Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve UX when users forget to install the package they are analyzing #5

Open
obi1kenobi opened this issue Jan 19, 2021 · 0 comments
Labels
better-error-ux Improving the UX around error conditions good first issue Good for newcomers

Comments

@obi1kenobi
Copy link
Owner

typing_copilot requires that the package being analyzed is installed in the virtualenv from where its command is invoked. However, this requirement is easy to miss, and if missed, will result in a fairly opaque error message (this was generated when analyzing the arviz package, https://github.com/arviz-devs/arviz ):

Traceback (most recent call last):
  File ".../arviz/venv/bin/typing_copilot", line 8, in <module>
    sys.exit(cli())
  File ".../arviz/venv/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File ".../arviz/venv/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File ".../arviz/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File ".../arviz/venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File ".../arviz/venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File ".../arviz/venv/lib/python3.8/site-packages/typing_copilot/cli.py", line 245, in init
    final_config_components = _make_strictest_mypy_config_components_from_errors(strict_errors)
  File ".../arviz/venv/lib/python3.8/site-packages/typing_copilot/cli.py", line 57, in _make_strictest_mypy_config_components_from_errors
    first_party_suppressions = get_1st_party_modules_and_suppressions(strict_errors)
  File ".../arviz/venv/lib/python3.8/site-packages/typing_copilot/error_tracker.py", line 251, in get_1st_party_modules_and_suppressions
    needed_setting_to_minimum_covering_modules: Dict[MypyErrorSetting, FrozenSet[str]] = {
  File ".../arviz/venv/lib/python3.8/site-packages/typing_copilot/error_tracker.py", line 252, in <dictcomp>
    error_setting: _consider_replacing_child_modules_with_parent(
  File ".../arviz/venv/lib/python3.8/site-packages/typing_copilot/error_tracker.py", line 167, in _consider_replacing_child_modules_with_parent
    unseen_child_modules_for_parent = {
  File ".../arviz/venv/lib/python3.8/site-packages/typing_copilot/error_tracker.py", line 168, in <dictcomp>
    parent_name: _get_child_module_names_for_module(parent_name)
  File ".../arviz/venv/lib/python3.8/site-packages/typing_copilot/error_tracker.py", line 135, in _get_child_module_names_for_module
    module = importlib.import_module(module_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'arviz'

Catch the ModuleNotFoundError error in get_1st_party_modules_and_suppressions and reraise it with a clearer error message that explains the appropriate action to take to resolve it -- simply install into your venv the package you are analyzing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
better-error-ux Improving the UX around error conditions good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant