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

pytest fails as importlib from 3.8 fails #90

Closed
jaraco opened this issue Oct 22, 2020 · 8 comments
Closed

pytest fails as importlib from 3.8 fails #90

jaraco opened this issue Oct 22, 2020 · 8 comments

Comments

@jaraco
Copy link
Member

jaraco commented Oct 22, 2020

In GitLab by @jokerjokerer on Sep 11, 2019, 20:39

with master 3.8 branch:

python3.8                                                                                                                                                                                         Wed 11 Sep 21:49:20 2019
Python 3.8.0b4+ (heads/3.8:8af4e0c, Sep 11 2019, 21:25:40)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
  File "/Users/bgabor8/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/192.6262.63/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2060, in <module>
    main()
  File "/Users/bgabor8/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/192.6262.63/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2054, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Users/bgabor8/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/192.6262.63/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1405, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "/Users/bgabor8/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/192.6262.63/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1412, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Users/bgabor8/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/192.6262.63/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/bgabor8/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/192.6262.63/PyCharm.app/Contents/helpers/pycharm/_jb_pytest_runner.py", line 37, in <module>
    config_result = real_prepare_config(args, plugins_to_load)
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/_pytest/config/__init__.py", line 208, in _prepareconfig
    return pluginmanager.hook.pytest_cmdline_parse(
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/pluggy/manager.py", line 92, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/pluggy/manager.py", line 83, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/_pytest/helpconfig.py", line 89, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/_pytest/config/__init__.py", line 720, in pytest_cmdline_parse
    self.parse(args)
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/_pytest/config/__init__.py", line 928, in parse
    self._preparse(args, addopts=addopts)
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/_pytest/config/__init__.py", line 869, in _preparse
    self._consider_importhook(args)
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/_pytest/config/__init__.py", line 817, in _consider_importhook
    self._mark_plugins_for_rewrite(hook)
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/_pytest/config/__init__.py", line 839, in _mark_plugins_for_rewrite
    for name in _iter_rewritable_modules(package_files):
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/_pytest/config/__init__.py", line 615, in _iter_rewritable_modules
    for fn in package_files:
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/site-packages/_pytest/config/__init__.py", line 832, in <genexpr>
    package_files = (
  File "/Users/bgabor8/git/github/sphinx-autodoc-typehints/.tox/py38/lib/python3.8/importlib/metadata/__init__.py", line 175, in <genexpr>
    resolver()
  File "<frozen importlib._bootstrap_external>", line 1383, in find_distributions
AttributeError: type object 'DistributionFinder' has no attribute 'Context'
@jaraco
Copy link
Member Author

jaraco commented Oct 22, 2020

In GitLab by @jokerjokerer on Sep 11, 2019, 20:49

changed the description

@jaraco
Copy link
Member Author

jaraco commented Oct 22, 2020

In GitLab by @jaraco on Sep 12, 2019, 18:43

This issue is related to #86, but may be slightly different. Clearly, find_distributions is looking for the new DistirbutionFinder.Context class, which was added in importlib_metadata 0.21 and in this commit for Python 3.8. So the question is, how is it possible that importlib.metadata ended up with a DistributionFinder with no Context?

I just don't see how that's possible.

That said, there was another update today; importlib_metadata 0.22, also ported to CPython 3.8 simplifies that interface even further, so it's possible that will correct the situation.

Are you still having issues? If so, could you try with the latest CPython? If it doesn't clear up with that, can you investigate a little bit more? In particular, inspect DistributionFinder to confirm it's importlib.metadata.DistributionFinder. Are you able to replicate this error in any other environment? Could the fact that DistributionFinder.Context is a class in a class be affected by the pytest context (monkeypatcher or assert rewriter maybe)?

@jaraco
Copy link
Member Author

jaraco commented Oct 22, 2020

In GitLab by @jokerjokerer on Sep 13, 2019, 11:32

On trying to replicate today I get a different:

 python3.8 'from importlib.metadata import MetadataPathFind'; python3.8                                                                    128ms  Fri 13 Sep 12:31:18 2019
python3.8: can't open file 'from importlib.metadata import MetadataPathFind': [Errno 2] No such file or directory
Python 3.8.0b4+ (heads/3.8:664d56a, Sep 13 2019, 08:58:37)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

@jaraco
Copy link
Member Author

jaraco commented Oct 22, 2020

In GitLab by @jaraco on Sep 13, 2019, 13:23

O_O

That error looks suspiciously erroneous. MetadataPathFind isn't a class (it should be MetadataPathFinder). Interesting that it detects it as a "No such file or directory" error. It sort-of makes sense, but I would have expected it to complain about the class missing from the module, not a submodule missing.

Regardless, I'll investigate.

@jaraco
Copy link
Member Author

jaraco commented Oct 22, 2020

In GitLab by @jaraco on Sep 13, 2019, 13:39

Searching for that code in the 3.8 branch of CPython, that text doesn't appear:

Searching 4212 files for "MetadataPathFind\b" (regex)

0 matches

Can you find the code that's attempting that import? By the way, if you're importing anything but the names in importlib.metadata.__all__, that's not supported, so we should seek out another solution.

@jaraco
Copy link
Member Author

jaraco commented Oct 22, 2020

In GitLab by @jokerjokerer on Sep 16, 2019, 09:49

Can replicate this locally for some reason, though not remotely for now 🤔

@jaraco
Copy link
Member Author

jaraco commented Oct 22, 2020

In GitLab by @jaraco on Sep 30, 2019, 02:53

Let me know if you find you can replicate it again.

@jaraco
Copy link
Member Author

jaraco commented Oct 22, 2020

In GitLab by @jaraco on Sep 30, 2019, 02:53

closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant