Skip to content

Commit 4d76bd1

Browse files
authored
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
1 parent b8590ec commit 4d76bd1

File tree

8 files changed

+82
-5
lines changed

8 files changed

+82
-5
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ Installation of the latest development version:
3636
pip install https://github.com/python-distro/distro/archive/master.tar.gz
3737
```
3838

39+
To use as a standalone script, download `distro.py` directly:
40+
41+
```shell
42+
curl -O https://raw.githubusercontent.com/python-distro/distro/master/src/distro/distro.py
43+
python distro.py
44+
```
45+
46+
``distro`` is safe to vendor within projects that do not wish to add
47+
dependencies.
48+
49+
```shell
50+
cd myproject
51+
curl -O https://raw.githubusercontent.com/python-distro/distro/master/src/distro/distro.py
52+
```
3953

4054
## Usage
4155

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
# The short X.Y version.
2727
# Note: We use the full version in both cases.
28-
version = distro.__version__
28+
version = distro.__version__ # type: ignore
2929

3030
# The full version, including alpha/beta/rc tags
31-
release = distro.__version__
31+
release = version
3232

3333

3434
# -- General configuration ---------------------------------------------------

setup.cfg

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ classifiers =
3030
Topic :: System :: Operating System
3131

3232
[options]
33-
py_modules = distro
33+
package_dir =
34+
= src
35+
packages = distro
3436
python_requires = >=3.6
3537

38+
[options.package_data]
39+
* = py.typed
40+
3641
[options.entry_points]
3742
console_scripts =
38-
distro = distro:main
43+
distro = distro.distro:main
3944

4045
[flake8]
4146
max-line-length = 88

src/distro/__init__.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from .distro import (
2+
NORMALIZED_DISTRO_ID,
3+
NORMALIZED_LSB_ID,
4+
NORMALIZED_OS_ID,
5+
LinuxDistribution,
6+
__version__,
7+
build_number,
8+
codename,
9+
distro_release_attr,
10+
distro_release_info,
11+
id,
12+
info,
13+
like,
14+
linux_distribution,
15+
lsb_release_attr,
16+
lsb_release_info,
17+
major_version,
18+
minor_version,
19+
name,
20+
os_release_attr,
21+
os_release_info,
22+
uname_attr,
23+
uname_info,
24+
version,
25+
version_parts,
26+
)
27+
28+
__all__ = [
29+
"NORMALIZED_DISTRO_ID",
30+
"NORMALIZED_LSB_ID",
31+
"NORMALIZED_OS_ID",
32+
"LinuxDistribution",
33+
"build_number",
34+
"codename",
35+
"distro_release_attr",
36+
"distro_release_info",
37+
"id",
38+
"info",
39+
"like",
40+
"linux_distribution",
41+
"lsb_release_attr",
42+
"lsb_release_info",
43+
"major_version",
44+
"minor_version",
45+
"name",
46+
"os_release_attr",
47+
"os_release_info",
48+
"uname_attr",
49+
"uname_info",
50+
"version",
51+
"version_parts",
52+
]
53+
54+
__version__ = __version__

src/distro/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .distro import main
2+
3+
if __name__ == "__main__":
4+
main()
File renamed without changes.

src/distro/py.typed

Whitespace-only changes.

tests/test_distro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
IS_LINUX = sys.platform.startswith("linux")
3535
if IS_LINUX:
36-
import distro
36+
from distro import distro
3737

3838
RELATIVE_UNIXCONFDIR = distro._UNIXCONFDIR[1:]
3939
RELATIVE_UNIXUSRLIBDIR = distro._UNIXUSRLIBDIR[1:]

0 commit comments

Comments
 (0)