Skip to content

Commit

Permalink
Add py.typed file to package for PEP-561 compliance
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jdufresne committed Nov 25, 2021
1 parent 8032f16 commit ee562e0
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 5 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------
Expand Down
9 changes: 7 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions src/distro/__init__.py
Original file line number Diff line number Diff line change
@@ -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__
4 changes: 4 additions & 0 deletions src/distro/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .distro import main

if __name__ == "__main__":
main()
File renamed without changes.
Empty file added src/distro/py.typed
Empty file.
2 changes: 1 addition & 1 deletion tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down

0 comments on commit ee562e0

Please sign in to comment.