-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add py.typed file to package for PEP-561 compliance #299
Conversation
Per PEP-561, packages that include type information that can be consumed by other libraries should distribute a py.typed file. This tells mypy and other tools to use type information shipped with the library. This requires moving distro from a single module file to a package so that it can ship data files. For details on PEP-561, see: https://www.python.org/dev/peps/pep-0561/ For details on mypy using py.typed, see: https://mypy.readthedocs.io/en/stable/installed_packages.html#creating-pep-561-compatible-packages
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.
thank you. it seems to me there's a little more inside that doesn't relate to PEP-561 directly.
@@ -0,0 +1,4 @@ | |||
from . import main |
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.
from . import main | |
from distro import main |
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.
IMO the relative import is a better choice. It avoids conflicts with any other "distro" module/package in the Python path. I'd prefer to keep this as-is unless there is a strong reason against it.
@@ -1365,7 +1365,3 @@ def main(): | |||
logger.info("Version: %s", distribution_version) | |||
distribution_codename = dist.codename() | |||
logger.info("Codename: %s", distribution_codename) | |||
|
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.
why is this moved to a separate module? wouldn't it be better to define a "console script" entrypoint?
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.
There is a console script. That hasn't changed.
It was moved to a module within a package so that additional "data" files can be installed alongside the package. That data file is the PEP-561 py.typed file.
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.
Further, using __main__.py
allows the user to run python -m distro
once installed. This was supported with the module version, so I carried over this feature.
Thanks @jdufresne, though this means that I'd rather not break that. Thoughts? |
@nir0s I see your point and it is a good one. It is a bit unfortunate that the module isn't PEP-561 compliant but not such a big deal. AFAICT, it can't be done with a pure module. |
then what about
?! |
Thank you for this suggestion and sorry for taking so long to get back to it. I've implemented this in #315 along with the documentation. |
Per PEP-561, packages that include type information that can be consumed
by other libraries should distribute a py.typed file. This tells mypy
and other tools to use type information shipped with the library.
This requires moving distro from a single module file to a package so
that it can ship data files.
For details on PEP-561, see:
https://www.python.org/dev/peps/pep-0561/
For details on mypy using py.typed, see:
https://mypy.readthedocs.io/en/stable/installed_packages.html#creating-pep-561-compatible-packages