Skip to content

Fix tests, run tests in CI #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
493d65b
tests: fix version calculation
woodruffw Jun 13, 2023
ee78d1d
workflows: ci
woodruffw Jun 13, 2023
125ec38
travis: remove old travis CI config
woodruffw Jun 13, 2023
3187ec7
tests: disable some broken tests
woodruffw Jun 13, 2023
e85109d
[WIP] experiment with CI
woodruffw Jun 14, 2023
e6430b0
[WIP] listgen: fix path
woodruffw Jun 14, 2023
235c31e
[WIP] more experimenting
woodruffw Jun 14, 2023
3aaac6d
[WIP] listgen: syntax
woodruffw Jun 14, 2023
63770a8
[WIP] listgen: disable 2.7 temporarily
woodruffw Jun 14, 2023
a429b80
[WIP] disable 3.2
woodruffw Jun 14, 2023
892e30e
[WIP]: 3.6+ only
woodruffw Jun 14, 2023
635b079
[WIP] listgen: tweak runner
woodruffw Jun 14, 2023
07e95a5
[WIP]: 3.7 and newer only
woodruffw Jun 14, 2023
7eabc10
[WIP] handle accelerator mods
woodruffw Jun 14, 2023
4b6a4ea
[WIP] do recursive step correctly
woodruffw Jun 14, 2023
206519a
[WIP] dedupe correctly
woodruffw Jun 14, 2023
84598f9
[WIP]: use pkgutil
woodruffw Jun 14, 2023
747b2fc
[WIP] hackety hack
woodruffw Jun 14, 2023
300689c
[WIP] hackety hack
woodruffw Jun 14, 2023
b421654
[WIP] builtin_module_names
woodruffw Jun 14, 2023
8ae1b6c
[WIP] newer python support
woodruffw Jun 15, 2023
c69a61e
[WIP] fix path
woodruffw Jun 15, 2023
eb82534
listgen: auto-PRs for 3.10+
woodruffw Jun 15, 2023
bd49ee1
listgen: fix base branch
woodruffw Jun 15, 2023
ab25cc8
walk-modules: be slightly smarter
woodruffw Jun 15, 2023
d80f0fc
Merge remote-tracking branch 'origin/main' into ww/fix-tests
woodruffw Jun 16, 2023
37f9ffb
listgen: temporarily disable PR creation
woodruffw Jun 16, 2023
04df9c7
rewrite tests
woodruffw Jun 16, 2023
fd48323
Makefile: enforce 100% coverage
woodruffw Jun 16, 2023
572af87
README: mention the new `sys` APIs
woodruffw Jun 16, 2023
b663cbf
listgen: run for old Pythons, drop pull_request trigger
woodruffw Jun 16, 2023
01402ca
ci: enable caching
woodruffw Jun 16, 2023
795886d
ci: test on 3.10 and 3.11
woodruffw Jun 16, 2023
8875a7b
base: update docstrings
woodruffw Jun 16, 2023
185e894
test_base: add another consistency test
woodruffw Jun 16, 2023
92e5670
tests: test long_versions as well for consistency
woodruffw Jun 20, 2023
d624d81
listgen: every tuesday
woodruffw Jun 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
test:
strategy:
matrix:
python:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: pip

- name: test
run: make test INSTALL_EXTRA=test

# lint:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-python@v4
# with:
# python-version: "3.10"
# - name: lint
# run: make lint INSTALL_EXTRA=lint
Comment on lines +32 to +40
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: Intentionally not enabled; will do in a separate PR.

115 changes: 115 additions & 0 deletions .github/workflows/listgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Generate stdlib lists

on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 2"

jobs:
pre-list-legacy:
strategy:
matrix:
python:
- "3.7"
- "3.8"
- "3.9"

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
# NOTE: matrix.python is intentionally not used here.
python-version: "3.x"
- name: support deps
run: make dev INSTALL_EXTRA=support
- name: build pre-list
env:
LISTGEN_PYTHON_VERSION: "${{ matrix.python }}"
run: |
./env/bin/python ./support/fetch-sphinx.py "${LISTGEN_PYTHON_VERSION}" > pre-list.txt
- name: upload pre-list
uses: actions/upload-artifact@v3
with:
name: pre-list-${{ matrix.python }}
path: pre-list.txt

expand-list-legacy:
needs: pre-list-legacy
strategy:
matrix:
python:
- "3.7"
- "3.8"
- "3.9"

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- uses: actions/download-artifact@v3
with:
name: pre-list-${{ matrix.python }}
- name: walk modules
run: |
python -V
python ./support/walk-modules.py "${LISTGEN_PYTHON_VERSION}.txt" < pre-list.txt
rm pre-list.txt
sort -o "${LISTGEN_PYTHON_VERSION}.txt" "${LISTGEN_PYTHON_VERSION}.txt"
mv "${LISTGEN_PYTHON_VERSION}.txt" ./stdlib_list/lists/
- name: create PR
uses: peter-evans/create-pull-request@v5
with:
commit-message: "[BOT] update list for ${{ matrix.python }}"
branch: update-stdlib-list-${{ matrix.python }}
base: main
branch-suffix: timestamp
title: "[BOT] update list for ${{ matrix.python }}"
body: |
This is an automated pull request, updating `${{ matrix.python }}.txt` after a detected change.

Please review manually before merging.
assignees: "woodruffw"
reviewers: "woodruffw"

expand-list:
strategy:
matrix:
python:
- "3.10"
- "3.11"

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: walk modules
env:
LISTGEN_PYTHON_VERSION: ${{ matrix.python }}
run: |
python -V
python ./support/walk-modules.py "${LISTGEN_PYTHON_VERSION}.txt"
sort -o "${LISTGEN_PYTHON_VERSION}.txt" "${LISTGEN_PYTHON_VERSION}.txt"
mv "${LISTGEN_PYTHON_VERSION}.txt" ./stdlib_list/lists/

- name: create PR
uses: peter-evans/create-pull-request@v5
with:
commit-message: "[BOT] update list for ${{ matrix.python }}"
branch: update-stdlib-list-${{ matrix.python }}
base: main
branch-suffix: timestamp
title: "[BOT] update list for ${{ matrix.python }}"
body: |
This is an automated pull request, updating `${{ matrix.python }}.txt` after a detected change.

Please review manually before merging.
assignees: "woodruffw"
reviewers: "woodruffw"
31 changes: 0 additions & 31 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ reformat:
test tests: $(VENV)/pyvenv.cfg
. $(VENV_BIN)/activate && \
pytest --cov=$(PY_MODULE) $(T) $(TEST_ARGS) && \
python -m coverage report -m $(COV_ARGS)
python -m coverage report -m $(COV_ARGS) --fail-under 100

.PHONY: doc
doc: $(VENV)/pyvenv.cfg
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This package includes lists of all of the standard libraries for Python 2.6,
2.7, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, and 3.9 along with the code for
scraping the official Python docs to get said lists.

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

## Installation

`stdlib-list` is available on PyPI:
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ test = ["pytest", "pytest-cov", "coverage[toml]"]
lint = ["black", "mypy", "ruff"]
doc = ["sphinx", "sphinx_rtd_theme"]
dev = ["build", "stdlib-list[test,lint,doc]"]
# CI only: used for list generation for Python versions < 3.10.
support = ["sphobjinv"]


[tool.black]
line-length = 100
Expand Down
8 changes: 8 additions & 0 deletions stdlib_list/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@
short_versions,
long_versions,
)

__all__ = [
"stdlib_list",
"in_stdlib",
"get_canonical_version",
"short_versions",
"long_versions",
]
22 changes: 17 additions & 5 deletions stdlib_list/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@

from functools import lru_cache

long_versions = ["2.6.9", "2.7.9", "3.2.6", "3.3.6", "3.4.3", "3.5", "3.6", "3.7", "3.8", "3.9"]
long_versions = [
"2.6.9",
"2.7.9",
"3.2.6",
"3.3.6",
"3.4.3",
"3.5",
"3.6",
"3.7",
"3.8",
"3.9",
"3.10",
"3.11",
]

short_versions = [".".join(x.split(".")[:2]) for x in long_versions]

Expand All @@ -23,11 +36,10 @@ def get_canonical_version(version):
def stdlib_list(version=None):
"""
Given a ``version``, return a ``list`` of names of the Python Standard
Libraries for that version. These names are obtained from the Sphinx inventory
file (used in :py:mod:`sphinx.ext.intersphinx`).
Libraries for that version.

:param str|None version: The version (as a string) whose list of libraries you want
(one of ``"2.6"``, ``"2.7"``, ``"3.2"``, ``"3.3"``, ``"3.4"``, or ``"3.5"``).
(formatted as ``X.Y``, e.g. ``"2.7"`` or ``"3.10"``).

If not specified, the current version of Python will be used.

Expand Down Expand Up @@ -72,7 +84,7 @@ def in_stdlib(module_name, version=None):

:param str|None module_name: The module name (as a string) to query for.
:param str|None version: The version (as a string) whose list of libraries you want
(one of ``"2.6"``, ``"2.7"``, ``"3.2"``, ``"3.3"``, ``"3.4"``, or ``"3.5"``).
(formatted as ``X.Y``, e.g. ``"2.7"`` or ``"3.10"``).

If not specified, the current version of Python will be used.

Expand Down
13 changes: 13 additions & 0 deletions support/fetch-sphinx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python

# fetch-sphinx.py: retrieve a particular Python version's stdlib list
# using its hosted Sphinx inventory.

import sys
import sphobjinv as soi

if __name__ == "__main__":
vers = sys.argv[1]
inv = soi.Inventory(url=f"https://docs.python.org/{vers}/objects.inv")
modules = list(sorted(obj.name for obj in inv.objects if obj.role == "module"))
print("\n".join(modules))
86 changes: 86 additions & 0 deletions support/walk-modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env python

import inspect
import pkgutil
import sys

SEEN_MODS = set()


def walk_pkgutil(mod_name, mod, io):
for pkg in pkgutil.walk_packages(mod.__path__, mod_name + "."):
if pkg.name in SEEN_MODS:
continue
else:
# We don't recurse here because `walk_packages` takes care of
# it for us.
SEEN_MODS.add(pkg.name)
print(pkg.name, file=io)


def walk_naive(mod_name, mod, io):
for attr in dir(mod):
attr_obj = getattr(mod, attr, None)
# Shouldn't happen, but who knows.
if attr_obj is None:
continue

# If this member isn't a module, skip it.
if not inspect.ismodule(attr_obj):
continue

# To filter "real" submodules from re-exports, we try
# and import the submodule by its qualified name.
# If the import fails, we know it's a re-exported module.
try:
submod_name = mod_name + "." + attr
__import__(submod_name)
walk(submod_name, io)
except ImportError:
# ...but sometimes we do want to include re-exports, since
# they might be things like "accelerator" modules that don't
# appear anywhere else.
# For example, `_bz2` might appear as a re-export.
try:
# Again, try and import to avoid module-looking object
# that don't actually appear on disk. Experimentally,
# there are a few of these (like "TK").
__import__(attr)
walk(attr, io)
except ImportError:
continue


def walk(mod_name, io):
if mod_name in SEEN_MODS:
return
else:
SEEN_MODS.add(mod_name)
print(mod_name, file=io)

# Try and import it.
try:
mod = __import__(mod_name)

if hasattr(mod, "__path__"):
walk_pkgutil(mod_name, mod, io)
else:
walk_naive(mod_name, mod, io)

except ImportError:
pass


if __name__ == "__main__":
output = sys.argv[1]

with open(output, mode="w") as io:
for mod_name in sys.builtin_module_names:
walk(mod_name, io)

if hasattr(sys, "stdlib_module_names"):
for mod_name in sys.stdlib_module_names:
walk(mod_name, io)
else:
for mod_name in sys.stdin:
walk(mod_name.rstrip("\n"), io)
7 changes: 0 additions & 7 deletions tests/__main__.py

This file was deleted.

Loading