You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
importsyssys.path+= ['path_to_project/package1/', 'path_to_project/package2/']
importparent.child.oneimportparent.child.twoprint(parent.child.__path__)
try:
print(parent.child.__file__)
exceptAttributeError:
print("parent.child have no __file__ attribute")
print(parent.child.one.__file__)
print(parent.child.two.__file__)
executing python root\app.py will show
_NamespacePath(['path_to_project/package1/parent/child', 'path_to_project/package2/parent/child'])
parent.child have no __file__ attribute
path_to_project/package1/parent/child/one.py
path_to_project/package2/parent/child/two.py
Do you know if anything you're updating will handle __all__? I've been going through the Django stuff, and found that they make use of * imports and __all__ modification quite a bit. See:
EDIT: Testing on Django packages does seem to find stuff alright, but I can come up with an example like:
whatever/__init__.py
fromsysimportversion__all__= []
app.py
fromwhateverimport*print(version)
Where we (currently) show version as being in scope, but running it fails saying version is not defined, which seems to hint that we might want to see how __all__ is going to play into this.
Forgive me if this isn't directly namespace package related, but I know you're updating the import resolution code, so I figured I'd ask. I'll make a new issue for this if needed.
This is actually the opposite task - support of the __init__.py, which can be only in ordinal packages. __all__ isn't the only option, you can simply define imports there. So yes, we need another epic for this.
Issues applicable to GA in this Epic are closed. So I am going to disconnect to remaining issues since they are not prioritized to GA and close the Epic.
Activity
AlexanderSher commentedon Oct 24, 2018
Namespace packages can be presented in several directories. Consider the following folder structure:
If
app.pycontains the following code:executing
python root\app.pywill showAlexanderSher commentedon Oct 24, 2018
from package import *doesn't import anything unless other imports have provided information for the namespace. Ifapp.pycontains the following code:executing
python root/app.pywill produce an error:Adding import to
app.pythat can provide information about the modulemakes
python root/app.pywork normally:However, this won't add other modules inside package. For
app.pylike this:executing
python root/app.pywill produce an error:AlexanderSher commentedon Oct 24, 2018
Conflict resolution: if both regular and namespace packages are presented in search paths, namespace packages will be ignored:
For
app.pyexecuting
python root/app.pywill produceAlexanderSher commentedon Oct 24, 2018
Functions can affect the import. A bit of edge case. Consider the following code in
app.py:Execution of
python root/app.pywill produce:If imports are moved into scope (i.e. function), there will be an error:
However,
from parent.child import *will now import modules that were found whileadd_importswas executed:AlexanderSher commentedon Oct 24, 2018
Namespace packages can resolve dependencies through relative imports. For example, in a project structure:
and file contents:
executing
python root/app.pyprintsF2jakebailey commentedon Oct 31, 2018
Do you know if anything you're updating will handle
__all__? I've been going through the Django stuff, and found that they make use of*imports and__all__modification quite a bit. See:EDIT: Testing on Django packages does seem to find stuff alright, but I can come up with an example like:
whatever/__init__.pyapp.pyWhere we (currently) show version as being in scope, but running it fails saying
versionis not defined, which seems to hint that we might want to see how__all__is going to play into this.Forgive me if this isn't directly namespace package related, but I know you're updating the import resolution code, so I figured I'd ask. I'll make a new issue for this if needed.
AlexanderSher commentedon Nov 1, 2018
This is actually the opposite task - support of the
__init__.py, which can be only in ordinal packages.__all__isn't the only option, you can simply define imports there. So yes, we need another epic for this.addisonElliott commentedon Dec 5, 2018
👍 Interested in this PR
In many Python projects, it's typical to alter the sys.path in unit tests to include the Python package.
This is one of the few things keeping me from fully switching to VS Code for Python dev...
wtigotw commentedon Jan 9, 2019
Same for me. This is the last major hurdle between me and VS Code as well.
MikhailArkhipov commentedon Feb 13, 2019
Issues applicable to GA in this Epic are closed. So I am going to disconnect to remaining issues since they are not prioritized to GA and close the Epic.