pypa / pypa/packaging.python.org

Most likely namespace packages explained wrongly

Open
#814 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.7k
Forks
1.7k
Avg merge
3d 12h
Merged PRs (30d)
4

Description

E.g., compare examples at https://packaging.python.org/guides/packaging-namespace-packages/#packaging-namespace-packages and https://www.python.org/dev/peps/pep-0420/#examples. I.e., using examples from packaging.python.org, packages will be merged upon installation, whereas the very purpose of namespace packages is to avoid this.

This example:

mynamespace-subpackage-a/
    setup.py
    mynamespace/
        subpackage_a/
            __init__.py

mynamespace-subpackage-b/
    setup.py
    mynamespace/
        subpackage_b/
            __init__.py
        module_b.py

Must look like this:

mynamespace-subpackage-a/
    setup.py
    mynamespace_subpackage_a/
        mynamespace/
            subpackage_a/
                __init__.py

mynamespace-subpackage-b/
    setup.py
    mynamespace_subpackage_b/
        mynamespace/
            subpackage_b/
                __init__.py
            module_b.py

Also, for namespace to be found, its parent dir must be in sys.path, which is demonstrated at https://www.python.org/dev/peps/pep-0420/#examples. The effect of inclusion of mynamespace_subpackage_a dir in sys.path can be achieved by including file mynamespace_subpackage_a.pth with ./mynamespace_subpackage_a inside of it into mynamespace_subpackage_a. The same must be done for mynamespace_subpackage_b. Thus, final example should look like this:

mynamespace-subpackage-a/
    setup.py
    mynamespace_subpackage_a.pth # With ``./mynamespace_subpackage_a`` inside of it.
    mynamespace_subpackage_a/
        mynamespace/
            subpackage_a/
                __init__.py

mynamespace-subpackage-b/
    setup.py
    mynamespace_subpackage_b.pth # With ``./mynamespace_subpackage_b`` inside of it.
    mynamespace_subpackage_b/
        mynamespace/
            subpackage_b/
                __init__.py
            module_b.py

Obviously, setup.py must be updated as well.

BTW, this issue may be related to #689.

Edit:
It may be worth telling that too many paths in sys.path are likely to have negative impact on performance.


I'm not sure if I'm right about the actual implementation, but examples definitely look wrong.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare the namespace-package examples in the Packaging User Guide with the PEP 420 examples linked in the issue, and review related issue #689. Verify the claims about installation, sys.path, .pth files, and setup.py before updating the documentation examples and explaining the correct layout and behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.