Skip to content

Commit 6a89679

Browse files
authored
QA: mypy, reformatting, and linting (#69)
* reformat, lint, mypy hints * pyproject: strong mypy config * base: __future__ * cleanup docs, make consistent, use furo More misc cleanup. * workflows: add release workflow
1 parent ca8f80e commit 6a89679

File tree

10 files changed

+95
-44
lines changed

10 files changed

+95
-44
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ jobs:
2929
- name: test
3030
run: make test INSTALL_EXTRA=test
3131

32-
# lint:
33-
# runs-on: ubuntu-latest
34-
# steps:
35-
# - uses: actions/checkout@v3
36-
# - uses: actions/setup-python@v4
37-
# with:
38-
# python-version: "3.10"
39-
# - name: lint
40-
# run: make lint INSTALL_EXTRA=lint
32+
lint:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v3
36+
- uses: actions/setup-python@v4
37+
with:
38+
python-version: "3.x"
39+
- name: lint
40+
run: make lint INSTALL_EXTRA=lint

.github/workflows/release.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
on:
2+
release:
3+
types:
4+
- published
5+
6+
name: release
7+
8+
jobs:
9+
pypi:
10+
name: upload release to PyPI
11+
runs-on: ubuntu-latest
12+
environment: release
13+
permissions:
14+
# Used for OIDC publishing.
15+
# Used to sign the release's artifacts with sigstore-python.
16+
id-token: write
17+
18+
# Used to attach signing artifacts to the published release.
19+
contents: write
20+
21+
steps:
22+
- uses: actions/checkout@v3
23+
24+
- uses: actions/setup-python@v4
25+
with:
26+
python-version: "3.x"
27+
28+
- name: deps
29+
run: python -m pip install -U setuptools build wheel
30+
31+
- name: build
32+
run: python -m build
33+
34+
- name: publish
35+
uses: pypa/[email protected]
36+
37+
- name: sign
38+
uses: sigstore/[email protected]
39+
with:
40+
inputs: ./dist/*.tar.gz ./dist/*.whl
41+
release-signing-artifacts: true
42+
bundle-only: true

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# stdlib-list
22

3-
This package includes lists of all of the standard libraries for Python 2.6,
4-
2.7, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, and 3.9 along with the code for
5-
scraping the official Python docs to get said lists.
3+
This package includes lists of all of the standard libraries for Python 2.6
4+
through 3.11.
65

76
**IMPORTANT**: If you're on Python 3.10 or newer, you **probably don't need this library**.
87
See [`sys.stdlib_module_names`](https://docs.python.org/3/library/sys.html#sys.stdlib_module_names)

docs/conf.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030
extensions = [
3131
"sphinx.ext.autodoc",
3232
"sphinx.ext.viewcode",
33-
"sphinx_rtd_theme",
3433
]
3534

36-
html_theme = "sphinx_rtd_theme"
35+
html_theme = "furo"
3736

3837
# Add any paths that contain templates here, relative to this directory.
3938
templates_path = ["_templates"]
@@ -48,8 +47,8 @@
4847
master_doc = "index"
4948

5049
# General information about the project.
51-
project = "Python Standard Library List"
52-
copyright = "2015, Jack Maney"
50+
project = "stdlib-list"
51+
copyright = "2015, stdlib-list authors"
5352

5453
# The version info for the project you're documenting, acts as replacement for
5554
# |version| and |release|, also used in various other places throughout the

docs/index.rst

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
.. Python Standard Library List documentation master file, created by
2-
sphinx-quickstart on Tue Mar 10 02:16:08 2015.
3-
You can adapt this file completely to your liking, but it should at least
4-
contain the root `toctree` directive.
1+
stdlib-list
2+
===========
53

6-
Python Standard Library List
7-
========================================================
4+
This package includes lists of all of the standard libraries for Python 2.6
5+
through 3.11.
86

9-
This package includes lists of all of the standard libraries for Python 2.6, 2.7, 3.2, 3.3, and 3.4, along with the code for scraping the official Python docs to get said lists.
7+
.. note::
108

11-
Listing the modules in the standard library? Wait, why on Earth would you care about that?!
12-
===========================================================================================
13-
14-
Because knowing whether or not a module is part of the standard library will come in handy in `a project of mine <https://github.com/jackmaney/pypt>`_. `And I'm not the only one <http://stackoverflow.com/questions/6463918/how-can-i-get-a-list-of-all-the-python-standard-library-modules>`_ who would find this useful. Or, the TL;DR answer is that it's handy in situations when you're analyzing Python code and would like to find module dependencies.
15-
16-
After googling for a way to generate a list of Python standard libraries (and looking through the answers to the previously-linked Stack Overflow question), I decided that I didn't like the existing solutions. So, I started by writing a scraper for the TOC of the Python Module Index for each of the versions of Python above.
17-
18-
However, web scraping can be a fragile affair. Thanks to `a suggestion <https://github.com/jackmaney/python-stdlib-list/issues/1#issuecomment-86517208>`_ by `@ncoghlan <https://github.com/ncoghlan>`_, and some further help from `@birkenfeld <https://github.com/birkenfeld>`_ and `@epc <https://github.com/epc>`_, the population of the lists is now done by grabbing and parsing the Sphinx object inventory for the official Python docs of each relevant version.
9+
If you're on Python 3.10 or newer, you **probably don't need this library**.
10+
See `sys.stdlib_module_names <https://docs.python.org/3/library/sys.html#sys.stdlib_module_names>`_
11+
and `sys.builtin_module_names <https://docs.python.org/3/library/sys.html#sys.builtin_module_names>`_
12+
for similar functionality.
1913

2014
Contents
2115
========

pyproject.toml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,32 @@ Source = "https://github.com/pypi/stdlib-list"
3030
[project.optional-dependencies]
3131
test = ["pytest", "pytest-cov", "coverage[toml]"]
3232
lint = ["black", "mypy", "ruff"]
33-
doc = ["sphinx", "sphinx_rtd_theme"]
33+
doc = ["sphinx", "furo"]
3434
dev = ["build", "stdlib-list[test,lint,doc]"]
3535
# CI only: used for list generation for Python versions < 3.10.
3636
support = ["sphobjinv"]
3737

38+
[tool.mypy]
39+
allow_redefinition = true
40+
check_untyped_defs = true
41+
disallow_incomplete_defs = true
42+
disallow_untyped_defs = true
43+
ignore_missing_imports = true
44+
no_implicit_optional = true
45+
show_error_codes = true
46+
sqlite_cache = true
47+
strict_equality = true
48+
warn_no_return = true
49+
warn_redundant_casts = true
50+
warn_return_any = true
51+
warn_unreachable = true
52+
warn_unused_configs = true
53+
warn_unused_ignores = true
3854

3955
[tool.black]
4056
line-length = 100
4157

4258
[tool.ruff]
4359
select = ["E", "F", "I", "W", "UP"]
4460
target-version = "py37"
61+
line-length = 100

stdlib_list/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
# Import all the things that used to be in here for backwards-compatibility reasons
44
from .base import (
5-
stdlib_list,
6-
in_stdlib,
75
get_canonical_version,
8-
short_versions,
6+
in_stdlib,
97
long_versions,
8+
short_versions,
9+
stdlib_list,
1010
)
1111

1212
__all__ = [

stdlib_list/base.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from __future__ import print_function, absolute_import
1+
from __future__ import annotations
22

33
import os
44
import pkgutil
55
import sys
6-
76
from functools import lru_cache
87

98
long_versions = [
@@ -24,16 +23,16 @@
2423
short_versions = [".".join(x.split(".")[:2]) for x in long_versions]
2524

2625

27-
def get_canonical_version(version):
26+
def get_canonical_version(version: str) -> str:
2827
if version in long_versions:
2928
version = ".".join(version.split(".")[:2])
3029
elif version not in short_versions:
31-
raise ValueError("No such version: {}".format(version))
30+
raise ValueError(f"No such version: {version}")
3231

3332
return version
3433

3534

36-
def stdlib_list(version=None):
35+
def stdlib_list(version: str | None = None) -> list[str]:
3736
"""
3837
Given a ``version``, return a ``list`` of names of the Python Standard
3938
Libraries for that version.
@@ -53,23 +52,23 @@ def stdlib_list(version=None):
5352
else ".".join(str(x) for x in sys.version_info[:2])
5453
)
5554

56-
module_list_file = os.path.join("lists", "{}.txt".format(version))
55+
module_list_file = os.path.join("lists", f"{version}.txt")
5756

58-
data = pkgutil.get_data("stdlib_list", module_list_file).decode()
57+
data = pkgutil.get_data("stdlib_list", module_list_file).decode() # type: ignore[union-attr]
5958

6059
result = [y for y in [x.strip() for x in data.splitlines()] if y]
6160

6261
return result
6362

6463

6564
@lru_cache(maxsize=16)
66-
def _stdlib_list_with_cache(version=None):
65+
def _stdlib_list_with_cache(version: str | None = None) -> list[str]:
6766
"""Internal cached version of `stdlib_list`"""
6867
return stdlib_list(version=version)
6968

7069

7170
@lru_cache(maxsize=256)
72-
def in_stdlib(module_name, version=None):
71+
def in_stdlib(module_name: str, version: str | None = None) -> bool:
7372
"""
7473
Return a ``bool`` indicating if module ``module_name`` is in the list of stdlib
7574
symbols for python version ``version``. If ``version`` is ``None`` (default), the

stdlib_list/py.typed

Whitespace-only changes.

tests/test_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pkgutil
2+
23
import pytest
34

45
import stdlib_list

0 commit comments

Comments
 (0)