Skip to content

Doc: update term "namespace package" #129251

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

Merged
merged 6 commits into from
Feb 14, 2025
Merged

Conversation

methane
Copy link
Member

@methane methane commented Jan 24, 2025

Recommend using regular package officially to avoid people just think __init__.py is not necessary.

For example: https://stackoverflow.com/questions/448271/what-is-init-py-for


📚 Documentation preview 📚: https://cpython-previews--129251.org.readthedocs.build/

Recommend using regular package officially to avoid
people just think `__init__.py` is not necessary.
@methane methane added the docs Documentation in the Doc dir label Jan 24, 2025
@methane
Copy link
Member Author

methane commented Jan 24, 2025

Another example of namespace pacakge being misunderstood.
#81073 (comment)

@methane methane requested a review from ericvsmith January 24, 2025 06:02
Doc/glossary.rst Outdated
and specifically are not like a :term:`regular package` because they
have no ``__init__.py`` file.

Namespace packages allow you to split single package across multiple directories or distributions.
On the other hand, namespace packages have some drawbacks and pitfalls.
Use :term:`regular package` always when it fits your needs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Use :term:`regular package` always when it fits your needs.
It is recommended to use a :term:`regular package` when possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "When possible" and "fits your needs" have same nuance?

For example, user who are thinking splitting their packages to two distribution, but it is "possible" to keep releasing one distribution.

In this case, regular package is not fits their need, but it is possible to use regular package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested edit makes text less direct, which is the style wanted for our docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think the wording should be improved. «always» seems strong but is weakened by «when it fits your needs» – people may not now if they do need to split a project!

Also, «across multiple directories» is talking about source trees but «across multiple distributions» is a concern for packaging and installation, so they’re not on the same level.

I’ll think on this and suggest edits!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it is friendlier

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You misunderstand – I meant that the previous wording was more direct, which is what we want. «It is recommended» is not an improvement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, @StanFromIreland, Open telemetry is an example of a namespace package.

I recommend removing "On the other hand ... your needs." This is a glossary entry so the prose should be brief and direct. I think if you add @methane's suggestion Namespace packages allow several individually installable packages to have a common parent package., then there is no need for the two sentences and they can be removed.

Copy link
Member

@merwok merwok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops message didn’t post earlier

Doc/glossary.rst Outdated
and specifically are not like a :term:`regular package` because they
have no ``__init__.py`` file.

Namespace packages allow you to split single package across multiple directories or distributions.
On the other hand, namespace packages have some drawbacks and pitfalls.
Use :term:`regular package` always when it fits your needs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think the wording should be improved. «always» seems strong but is weakened by «when it fits your needs» – people may not now if they do need to split a project!

Also, «across multiple directories» is talking about source trees but «across multiple distributions» is a concern for packaging and installation, so they’re not on the same level.

I’ll think on this and suggest edits!

@merwok merwok requested review from ncoghlan and merwok January 24, 2025 17:53
@methane methane force-pushed the doc-namespace-package branch from 5002745 to 16d5407 Compare January 24, 2025 23:13
@methane
Copy link
Member Author

methane commented Jan 24, 2025

Also, «across multiple directories» is talking about source trees but «across multiple distributions» is a concern for packaging and installation, so they’re not on the same level.

How about this?

Namespace packages allow several individually installable packages to have a common parent package.

Both of pip install and "setting multiple import paths" are "install".

In case of pip install, namespace package would be a single directory. But that is certainly a situation where implicit namespace packages can be used.

Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @methane. I recommend removing the awkward sentences at the end.

Doc/glossary.rst Outdated
and specifically are not like a :term:`regular package` because they
have no ``__init__.py`` file.

Namespace packages allow you to split single package across multiple directories or distributions.
On the other hand, namespace packages have some drawbacks and pitfalls.
Use :term:`regular package` always when it fits your needs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, @StanFromIreland, Open telemetry is an example of a namespace package.

I recommend removing "On the other hand ... your needs." This is a glossary entry so the prose should be brief and direct. I think if you add @methane's suggestion Namespace packages allow several individually installable packages to have a common parent package., then there is no need for the two sentences and they can be removed.

@methane
Copy link
Member Author

methane commented Jan 25, 2025

@willingc I would like to add a sentence to the official documentation to debunk the misconception that __init__.py is no longer needed from Python 3.3.

#113209 added unless using a :term:`namespace package`, a relatively advanced feature in the tutorial. But "relatively advanced feature" is not enough to prevent omitting __init__.py without knowing its risk.

We have namespace packages section in the reference. But tutorial refers to glossary, not reference. That is why I added the awkward sentences at the end.

Copy link
Member

@ericvsmith ericvsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

@merwok merwok merged commit e65e9f9 into python:main Feb 14, 2025
24 checks passed
@merwok
Copy link
Member

merwok commented Feb 14, 2025

Thanks all!

I think we should backport

@merwok merwok added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Feb 14, 2025
@miss-islington-app
Copy link

Thanks @methane for the PR, and @merwok for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @methane for the PR, and @merwok for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 14, 2025
(cherry picked from commit e65e9f9)

Co-authored-by: Inada Naoki <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Feb 14, 2025

GH-130128 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Feb 14, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 14, 2025
(cherry picked from commit e65e9f9)

Co-authored-by: Inada Naoki <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Feb 14, 2025

GH-130129 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Feb 14, 2025
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 CentOS9 NoGIL Refleaks 3.x has failed when building commit e65e9f9.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1610/builds/858) and take a look at the build logs.
  4. Check if the failure is related to this commit (e65e9f9) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1610/builds/858

Failed tests:

  • test_free_threading

Summary of the results of the build (if available):

==

Click to see traceback logs
remote: Enumerating objects: 6, done.        
remote: Counting objects:  16% (1/6)        
remote: Counting objects:  33% (2/6)        
remote: Counting objects:  50% (3/6)        
remote: Counting objects:  66% (4/6)        
remote: Counting objects:  83% (5/6)        
remote: Counting objects: 100% (6/6)        
remote: Counting objects: 100% (6/6), done.        
remote: Compressing objects:  20% (1/5)        
remote: Compressing objects:  40% (2/5)        
remote: Compressing objects:  60% (3/5)        
remote: Compressing objects:  80% (4/5)        
remote: Compressing objects: 100% (5/5)        
remote: Compressing objects: 100% (5/5), done.        
remote: Total 6 (delta 1), reused 2 (delta 1), pack-reused 0 (from 0)        
From https://github.com/python/cpython
 * branch                    main       -> FETCH_HEAD
Note: switching to 'e65e9f90626a4c62da4d3500044f354b51e51dbb'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at e65e9f90626 Doc: update term "namespace package" (#129251)
Switched to and reset branch 'main'

configure: WARNING: no system libmpdecimal found; falling back to bundled libmpdecimal (deprecated and scheduled for removal in Python 3.15)

make: *** [Makefile:2325: buildbottest] Error 2

@methane methane deleted the doc-namespace-package branch February 15, 2025 05:07
methane pushed a commit that referenced this pull request Feb 15, 2025
methane added a commit that referenced this pull request Feb 15, 2025
(cherry picked from commit e65e9f9)
Co-authored-by: Inada Naoki <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants