caterinaurban / Typpete

35 stars 6 forks source link

Entry points #36

Closed mostafa-abdullah closed 6 years ago

mostafa-abdullah commented 6 years ago

Packaging Typpete. Now we can run the type inference directly from the command line.

Changes include the following:

- Made a main function for running the type inference in `typpete/tests/inference_runner.py`.
- Added an entry point in `setup.py` for this main function
- Replaced relative paths for built in libraries stubs with absolute paths, in order to run the inference on a file anywhere.
- Supporting taking the inference configuration flags from the command line (See the syntax below).

Note that you see a lot of rename changes (111 files :D ) because I had to move all the project files into a typpete folder to have successful packaging.

Typpete Installation

In the root folder (the one which contains the package and setup.py), run pip install . or python3 setup.py install. Note that installation via pip is recommended since packages installed with setup.py are not uninstallable (They can only be uninstalled by manually deleting their files)

Running the inference

You can run the inference with the following command

$ typpete <file_name> [flags]

Where flags is a space separated list of options for configuring the type inference. Each flag must have the following syntax: --flag_name=flag_value. For example, the following is a valid configuration flag: --allow_attributes_outside_init=True

The currently supported flags are the following:

Flag Description Possible values
ignore_fully_annotated_function Whether to ignore the body of fully annotated functions and just take the provided types for args/return True, False
enforce_same_type_in_branches Whether to allow different branches to use different types of same variable. True, False
allow_attributes_outside_init Whether to allow to define instance attribute outside __init__ True, False
none_subtype_of_all Whether to make None a subtype of all types. True, False

Example:

$ typpete python_file.py --ignore_fully_annotated_function=True
caterinaurban commented 6 years ago

Installation goes fine but something is wrong when I try to run the inference. I get this stack trace (I installed everything in a virtualenv called qwerty):

Traceback (most recent call last):
  File "./qwerty/bin/typpete", line 11, in <module>
    load_entry_point('Typpete==0.1', 'console_scripts', 'typpete')()
  File "./qwerty/lib/python3.6/site-packages/pkg_resources/__init__.py", line 572, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "./qwerty/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2755, in load_entry_point
    return ep.load()
  File "./qwerty/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2408, in load
    return self.resolve()
  File "./qwerty/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2414, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'typpete'

Any idea of why this happens?

mostafa-abdullah commented 6 years ago

@caterinaurban Fixed now

caterinaurban commented 6 years ago

I ran out of ideas :(

Traceback (most recent call last):
  File "./qwerty/bin/typpete", line 11, in <module>
    load_entry_point('Typpete==0.1', 'console_scripts', 'typpete')()
  File "./qwerty/lib/python3.6/site-packages/typpete/tests/inference_runner.py", line 38, in run_inference
    solver = z3_types.TypesSolver(t, root_folder)
  File "./qwerty/lib/python3.6/site-packages/typpete/frontend/z3_types.py", line 47, in __init__
    self.z3_types = Z3Types(self.config)
  File "./qwerty/lib/python3.6/site-packages/typpete/frontend/z3_types.py", line 94, in __init__
    type_sort = declare_type_sort(max_tuple_length, max_function_args, classes_to_instance_attrs)
  File "./qwerty/lib/python3.6/site-packages/typpete/frontend/z3_types.py", line 294, in declare_type_sort
    return type_sort.create()
  File "./qwerty/lib/python3.6/site-packages/typpete/z3/z3.py", line 4365, in create
    return CreateDatatypes([self])[0]
  File "./qwerty/lib/python3.6/site-packages/typpete/z3/z3.py", line 4467, in CreateDatatypes
    cref = cref()
  File "./qwerty/lib/python3.6/site-packages/typpete/z3/z3.py", line 715, in __call__
    _z3_assert(num == self.arity(), "Incorrect number of arguments to %s" % self)
  File "./qwerty/lib/python3.6/site-packages/typpete/z3/z3.py", line 292, in __str__
    return obj_to_string(self)
  File "./qwerty/lib/python3.6/site-packages/typpete/z3/z3printer.py", line 1183, in obj_to_string
    _PP(out, _Formatter(a))
  File "./qwerty/lib/python3.6/site-packages/typpete/z3/z3printer.py", line 1079, in __call__
    return self.main(a)
  File "./qwerty/lib/python3.6/site-packages/typpete/z3/z3printer.py", line 1052, in main
    if z3.is_expr(a):
AttributeError: module 'z3' has no attribute 'is_expr'