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

NameError: name '__path__' is not defined with import-mode=importlib #10332

Open
jaraco opened this issue Oct 2, 2022 · 3 comments
Open

NameError: name '__path__' is not defined with import-mode=importlib #10332

jaraco opened this issue Oct 2, 2022 · 3 comments
Labels
topic: collection related to the collection phase type: enhancement new feature or API change, should be merged into features branch

Comments

@jaraco
Copy link
Contributor

jaraco commented Oct 2, 2022

Discovered in jaraco/backports.entry_points_selectable#7, when one uses import-mode=importlib on a pkgutil-style namespace package, the collection fails (or sometimes the tests fail).

 backports.entry_points_selectable main $ tox -- --import-mode importlib
python develop-inst-noop: /Users/jaraco/code/jaraco/backports.entry_points_selectable
python installed: attrs==22.1.0,-e git+gh://jaraco/backports.entry_points_selectable@59f716c15b8c1feb92f5ca7fd88d342d8ebf96c4#egg=backports.entry_points_selectable,black==22.8.0,build==0.8.0,click==8.1.3,coverage==6.5.0,docutils==0.19,filelock==3.8.0,flake8==4.0.1,importlib-metadata==4.13.0,iniconfig==1.1.1,jaraco.context==4.1.2,jaraco.functools==3.5.2,mccabe==0.6.1,more-itertools==8.14.0,mypy==0.981,mypy-extensions==0.4.3,packaging==21.3,pathspec==0.10.1,pep517==0.13.0,platformdirs==2.5.2,pluggy==1.0.0,py==1.11.0,pycodestyle==2.8.0,pyflakes==2.4.0,pyparsing==3.0.9,pytest==7.1.3,pytest-black==0.3.12,pytest-checkdocs==2.8.1,pytest-cov==4.0.0,pytest-enabler==1.3.0,pytest-flake8==1.1.1,pytest-mypy==0.10.0,toml==0.10.2,tomli==2.0.1,typing_extensions==4.3.0,zipp==3.8.1
python run-test-pre: PYTHONHASHSEED='1760814860'
python run-test: commands[0] | pytest --import-mode importlib
=================================================================== test session starts ====================================================================
platform darwin -- Python 3.10.6, pytest-7.1.3, pluggy-1.0.0
cachedir: .tox/python/.pytest_cache
rootdir: /Users/jaraco/code/jaraco/backports.entry_points_selectable, configfile: pytest.ini
plugins: black-0.3.12, checkdocs-2.8.1, flake8-1.1.1, mypy-0.10.0, cov-4.0.0, enabler-1.3.0
collected 16 items / 1 error                                                                                                                               

========================================================================== ERRORS ==========================================================================
__________________________________________________________ ERROR collecting backports/__init__.py __________________________________________________________
backports/__init__.py:1: in <module>
    __path__ = __import__('pkgutil').extend_path(__path__, __name__)  # type: ignore
E   NameError: name '__path__' is not defined

---------- coverage: platform darwin, python 3.10.6-final-0 ----------
Name                                   Stmts   Miss  Cover   Missing
--------------------------------------------------------------------
backports/__init__.py                      1      0   100%
backports/entry_points_selectable.py     116     64    45%   25-26, 34, 36-41, 51-62, 68, 114, 122-129, 133, 137-142, 156-161, 168, 175, 186, 190, 194, 198, 212-215, 222, 226, 235, 238-240, 261-268
docs/conf.py                              10      0   100%
--------------------------------------------------------------------
TOTAL                                    127     64    50%

================================================================= short test summary info ==================================================================
ERROR backports/__init__.py - NameError: name '__path__' is not defined
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
===================================================================== 1 error in 0.10s =====================================================================
ERROR: InvocationError for command /Users/jaraco/code/jaraco/backports.entry_points_selectable/.tox/python/bin/pytest --import-mode importlib (exited with code 2)
_________________________________________________________________________ summary __________________________________________________________________________
ERROR:   python: commands failed

These backports packages are by necessity not PEP 420 (because many of them must support Python 2.7).

Is there any intention to support pkgutil-style namespace packages with import-mode=importlib?

@RonnyPfannschmidt
Copy link
Member

Importlib mode currently does not support import from sibling modules at all

Pytest itself is not yet supporting pep420 to begin with

The idea is have for solutions is "import roots" but I haven't yet created a explicit write down that makes sense outside of my head

@kloczek
Copy link
Contributor

kloczek commented Oct 2, 2022

That is OK .. just humble question: jow high is this issue in ToDo list? 😋

@RonnyPfannschmidt
Copy link
Member

after sending out a first starting mail today, its hopefully going to happen within the next few months
im aiming for a timeframe betwen 6 and 12 months, but thats a initial naive hope

its mid range

@Zac-HD Zac-HD added type: enhancement new feature or API change, should be merged into features branch topic: collection related to the collection phase labels Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

4 participants