From ee562e06c8d71e29681335f2484b63209a1f2dad Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 16 Oct 2021 07:15:00 -0700 Subject: [PATCH] Add py.typed file to package for PEP-561 compliance 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. The original distro.py was not altered. Only the __init__.py and __main__.py were added to facilitate being used as a packages. By keeping distro.py unaltered, this allows projects to continue to vendor the file into their project without as before without any modifications. 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 --- README.md | 14 ++++++++ docs/conf.py | 4 +-- setup.cfg | 9 ++++-- src/distro/__init__.py | 54 +++++++++++++++++++++++++++++++ src/distro/__main__.py | 4 +++ distro.py => src/distro/distro.py | 0 src/distro/py.typed | 0 tests/test_distro.py | 2 +- 8 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 src/distro/__init__.py create mode 100644 src/distro/__main__.py rename distro.py => src/distro/distro.py (100%) create mode 100644 src/distro/py.typed diff --git a/README.md b/README.md index 8e689cd..e22ed1e 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,20 @@ Installation of the latest development version: pip install https://github.com/python-distro/distro/archive/master.tar.gz ``` +To use as a standalone script, download `distro.py` directly: + +```shell +curl -O https://github.com/raw/python-distro/distro/master/src/distro/distro.py +python distro.py +``` + +``distro`` is safe to vendor within projects that do not wish to add +dependencies. + +```shell +cd myproject +curl -O https://github.com/raw/python-distro/distro/master/src/distro/distro.py +``` ## Usage diff --git a/docs/conf.py b/docs/conf.py index 4b6dcd0..90e14fe 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,10 +25,10 @@ # The short X.Y version. # Note: We use the full version in both cases. -version = distro.__version__ +version = distro.distro.__version__ # The full version, including alpha/beta/rc tags -release = distro.__version__ +release = distro.distro.__version__ # -- General configuration --------------------------------------------------- diff --git a/setup.cfg b/setup.cfg index 0510c4b..c163a94 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,12 +30,17 @@ classifiers = Topic :: System :: Operating System [options] -py_modules = distro +package_dir = + = src +packages = distro python_requires = >=3.6 +[options.package_data] +* = py.typed + [options.entry_points] console_scripts = - distro = distro:main + distro = distro.distro:main [flake8] max-line-length = 88 diff --git a/src/distro/__init__.py b/src/distro/__init__.py new file mode 100644 index 0000000..7686fe8 --- /dev/null +++ b/src/distro/__init__.py @@ -0,0 +1,54 @@ +from .distro import ( + NORMALIZED_DISTRO_ID, + NORMALIZED_LSB_ID, + NORMALIZED_OS_ID, + LinuxDistribution, + __version__, + build_number, + codename, + distro_release_attr, + distro_release_info, + id, + info, + like, + linux_distribution, + lsb_release_attr, + lsb_release_info, + major_version, + minor_version, + name, + os_release_attr, + os_release_info, + uname_attr, + uname_info, + version, + version_parts, +) + +__all__ = [ + "NORMALIZED_DISTRO_ID", + "NORMALIZED_LSB_ID", + "NORMALIZED_OS_ID", + "LinuxDistribution", + "build_number", + "codename", + "distro_release_attr", + "distro_release_info", + "id", + "info", + "like", + "linux_distribution", + "lsb_release_attr", + "lsb_release_info", + "major_version", + "minor_version", + "name", + "os_release_attr", + "os_release_info", + "uname_attr", + "uname_info", + "version", + "version_parts", +] + +__version__ = __version__ diff --git a/src/distro/__main__.py b/src/distro/__main__.py new file mode 100644 index 0000000..0c01d5b --- /dev/null +++ b/src/distro/__main__.py @@ -0,0 +1,4 @@ +from .distro import main + +if __name__ == "__main__": + main() diff --git a/distro.py b/src/distro/distro.py similarity index 100% rename from distro.py rename to src/distro/distro.py diff --git a/src/distro/py.typed b/src/distro/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_distro.py b/tests/test_distro.py index 340fdef..6ffe654 100644 --- a/tests/test_distro.py +++ b/tests/test_distro.py @@ -33,7 +33,7 @@ IS_LINUX = sys.platform.startswith("linux") if IS_LINUX: - import distro + from distro import distro RELATIVE_UNIXCONFDIR = distro._UNIXCONFDIR[1:] RELATIVE_UNIXUSRLIBDIR = distro._UNIXUSRLIBDIR[1:]