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

#1316 Update packaging-projects.rst with a tip on good module naming #1424

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
17e76be
Update packaging-projects.rst with a tip on good module naming
LLyaudet Nov 30, 2023
1815996
Update packaging-projects.rst add empty line after items
LLyaudet Dec 1, 2023
24d81e5
Update packaging-projects.rst ???
LLyaudet Dec 1, 2023
b8890ba
Update packaging-projects.rst use intersphinx
LLyaudet Dec 1, 2023
74af3e9
Merge branch 'pypa:main' into patch-1
LLyaudet Dec 2, 2023
2779b98
Update packaging-projects.rst use correctly intersphinx
LLyaudet Dec 2, 2023
c12f338
LL: create discussion choosing-a-module-name and link between it and …
LLyaudet Dec 2, 2023
cc8ffd5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 2, 2023
614bf97
LL: correction nox build.
LLyaudet Dec 2, 2023
5f7790e
Update source/discussions/choosing-a-module-name.rst
LLyaudet Dec 3, 2023
408d7aa
Update source/discussions/choosing-a-module-name.rst
LLyaudet Dec 3, 2023
2893273
LL: correction code-block python -> pycon.
LLyaudet Dec 3, 2023
81d8d52
LL : more markup in choosing-a-module-name.
LLyaudet Dec 3, 2023
43e64d9
LL: add warning and ref to PEP8 for unnatural module names.
LLyaudet Dec 3, 2023
76bb7bf
LL: add import package since import packages are a special case of mo…
LLyaudet Dec 3, 2023
4e5053e
LL: clarify terminology with links to the glossary.
LLyaudet Dec 3, 2023
fd7909e
Merge branch 'pypa:main' into patch-1
LLyaudet Dec 3, 2023
8f314ae
LL: typo cumbersone -> cumbersome.
LLyaudet Dec 3, 2023
8115dae
LL: correction Title underline too short.
LLyaudet Dec 3, 2023
63b5b46
Merge branch 'main' into patch-1
LLyaudet Dec 10, 2023
23e289e
Update source/discussions/choosing-a-package-module-name.rst
LLyaudet Dec 10, 2023
de7fbfa
LL: add recommendation to have only one importable package.
LLyaudet Dec 10, 2023
f962554
Update source/discussions/choosing-a-package-module-name.rst
LLyaudet Dec 10, 2023
b5fdb5c
LL: PyPI back after applying suggestion.
LLyaudet Dec 10, 2023
b93f306
LL: partial rewrite following in part suggestions by sinoroc.
LLyaudet Dec 10, 2023
a1745ef
LL: add section on the consequences of naming for consistency of the …
LLyaudet Dec 10, 2023
dfe196d
LL: refs for build backends.
LLyaudet Dec 10, 2023
7a52305
LL: missing new line before pycon.
LLyaudet Dec 10, 2023
8a20cac
LL: another missing new line.
LLyaudet Dec 10, 2023
eecfc2f
LL: correction `dist-info` -> ``dist-info``.
LLyaudet Dec 10, 2023
7d29053
LL: correct name normalization ref that fails in nox.
LLyaudet Dec 10, 2023
fcff555
LL: warning about 2 types of name normalization.
LLyaudet Dec 10, 2023
401d037
LL: naming gymnastic at the end with a little joke :).
LLyaudet Dec 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions source/discussions/choosing-a-package-module-name.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Choosing a Package/Module Name
==============================

This discussion is a complement to :doc:`/tutorials/packaging-projects`.

Make sure to have a valid :ref:`Python identifier <python:identifiers>` for your import package/module name.
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
Make sure to have a valid :ref:`Python identifier <python:identifiers>` for your import package/module name.
Make sure to choose a valid :ref:`Python identifier <python:identifiers>` for the names of all your :term:`import packages <import package>` and :term:`modules <module>`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the late answer. I validated your commit suggestion of the 4th. The 3rd december I modified like this:

Make sure to have a valid :ref:`Python identifier <python:identifiers>` for your import package/module name.
The (PyPI) :term:`project<Project>`/:term:`distribution package <Distribution Package>` name
and the Python :term:`import package <Import Package>`/module may differ slightly.

So the terms are already referenced.
I found it nice to have all 3 terms referenced in the same sentence when I modified.
But I understand the need to reference one of the 3 terms in the preceding sentence since it is asked here:

The first time you mention a tool or practice, link to the part of the

I have a question: Should I reference the glossary on each appearance of a term in the same document?
I know that when a document is long, it is nice when you can hover over any acronym and check again its meaning if it does not stuck the first time.
I think on Wikipedia, it is frequent that most occurrences are cross-links.
As of now, I kept the second reference in the following sentence.
Let me know if I should remove it.
Moreover, if there is a consensus on this question, I think it should be in contribute.rst :)

The (PyPI) :term:`project<Project>`/:term:`distribution package <Distribution Package>` name
and the Python :term:`import package <Import Package>`/module may differ slightly.
LLyaudet marked this conversation as resolved.
Show resolved Hide resolved
Moreover, one PyPI project/dist may ship more than one module or importable package — it is only possible that one matches the name, others can't.
LLyaudet marked this conversation as resolved.
Show resolved Hide resolved
For example, your package in :file:`pyproject.toml` and on PyPI may have the name ``abcd-1234``.
But a module named ``abcd-1234`` would be cumbersome to import in Python,
since it isn't a valid identifier.
(It would be cumbersome, completely unnatural and against the long-established conventions in the Python community;
see, for example, :pep:`8#package-and-module-names`.
LLyaudet marked this conversation as resolved.
Show resolved Hide resolved
There is a way to import it anyway, see :doc:`importlib <python:library/importlib>` and this question_.)

.. code-block:: pycon

>>> import abcd-1234
>>> from abcd-1234 import something

would not work.
LLyaudet marked this conversation as resolved.
Show resolved Hide resolved
But having a directory structure with ``src/abcd_1234/`` instead of ``src/abcd-1234/`` has 2 consequences:

- The following works:

.. code-block:: pycon

>>> import abcd_1234
>>> from abcd_1234 import something

- Hatch will recognize that the module corresponding to the package is ``abcd_1234`` instead of defaulting to ``src`` and building a not working wheel.

More information about :doc:`Python imports <python:reference/import>` and its :doc:`grammar <python:reference/grammar>`.

.. _question: https://stackoverflow.com/questions/8350853/how-to-import-module-when-module-name-has-a-dash-or-hyphen-in-it
1 change: 1 addition & 0 deletions source/discussions/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ specific topic. If you're just trying to get stuff done, see
wheel-vs-egg
src-layout-vs-flat-layout
setup-py-deprecated
choosing-a-package-module-name
4 changes: 2 additions & 2 deletions source/tutorials/packaging-projects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ Make sure you're still in your virtual environment, then run Python:

and import the package:

.. code-block:: python
.. code-block:: pycon

>>> from example_package_YOUR_USERNAME_HERE import example
>>> example.add_one(2)
Expand Down Expand Up @@ -537,7 +537,7 @@ some things you can do:
:ref:`pdm`, and :ref:`poetry`.
* Read :pep:`517` and :pep:`518` for background and details on build tool configuration.
* Read about :doc:`/guides/packaging-binary-extensions`.

* Read about :doc:`/discussions/choosing-a-package-module-name`.

----

Expand Down