-
Notifications
You must be signed in to change notification settings - Fork 970
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
base: main
Are you sure you want to change the base?
Changes from 13 commits
17e76be
1815996
24d81e5
b8890ba
74af3e9
2779b98
c12f338
cc8ffd5
614bf97
5f7790e
408d7aa
2893273
81d8d52
43e64d9
76bb7bf
4e5053e
fd7909e
8f314ae
8115dae
63b5b46
23e289e
de7fbfa
f962554
b5fdb5c
b93f306
a1745ef
dfe196d
7a52305
8a20cac
eecfc2f
7d29053
fcff555
401d037
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Choosing a Module Name | ||
LLyaudet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
========================= | ||
|
||
This discussion is a complement to :doc:`/tutorials/packaging-projects`. | ||
LLyaudet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Make sure to have a valid :ref:`Python identifier <python:identifiers>` for your module name. | ||
The PyPI project/dist name and the Python module may differ slightly. | ||
LLyaudet marked this conversation as resolved.
Show resolved
Hide resolved
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. | ||
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, | ||
LLyaudet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
since it isn't a valid identifier. | ||
(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. | ||
But having a directory structure with ``src/abcd_1234/`` instead of ``src/abcd-1234/`` has 2 consequences: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The directory structure should be introduced in the document first. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was in part the goal of the first sentence :). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, of course, I see |
||
|
||
- 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why only mention hatch here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because I only had the bug with Hatch here. I tested Hatch and setuptools. |
||
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like it's best to have this absorbed in #1426, it's much more comprehensive and there's a section for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello :),
Thanks for the suggestions of corrections :).
I was seeing it coming regarding #1426 ;). Do as you want, you have writing rights on my PR.
I think my PR is ok as is as far as your other requests are concerned.
I have no experience of merging two PRs:
Let us know what you prefer :).
Best regards,
Laurent Lyaudet