Skip to content

Commit

Permalink
Add support for Python 3.11 (#152)
Browse files Browse the repository at this point in the history
* feat(stdlibs): generate modules for 3.11

* feat(module): add Python 3.11

* refactor(module): simplify a bit some methods

* test(module): add tests for `_get_stdlib_packages`

* ci: add Python 3.11

* ci: provide faster feedback

* chore: explicitly add `3.11` classifier
  • Loading branch information
mkniewallner authored Oct 2, 2022
1 parent e71dc6a commit 9c886fe
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 52 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:

tox:
runs-on: ubuntu-latest
needs: quality
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11-dev']
fail-fast: false
steps:
- name: Check out
uses: actions/checkout@v3
Expand All @@ -45,7 +45,6 @@ jobs:
check-docs:
runs-on: ubuntu-latest
needs: quality
steps:
- name: Check out
uses: actions/checkout@v3
Expand Down
48 changes: 24 additions & 24 deletions .github/workflows/on-release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:
uses: ./.github/actions/run-checks

tox:
needs: quality
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11-dev']
fail-fast: false
steps:
- name: Check out
uses: actions/checkout@v3
Expand All @@ -39,10 +39,8 @@ jobs:
poetry add tox-gh-actions
tox
check-docs:
runs-on: ubuntu-latest
needs: quality
steps:
- name: Check out
uses: actions/checkout@v3
Expand All @@ -51,32 +49,34 @@ jobs:
uses: ./.github/actions/check-docs

publish:
runs-on: ubuntu-latest
needs: tox
steps:
- name: Check out
uses: actions/checkout@v3

- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
runs-on: ubuntu-latest
needs:
- quality
- tox
- check-docs
steps:
- name: Check out
uses: actions/checkout@v3

- name: Set output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Set up the environment
uses: ./.github/actions/setup-poetry-env

- name: Build and publish
run: |
source .venv/bin/activate
poetry version $RELEASE_VERSION
make build-and-publish
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
- name: Set output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

- name: Build and publish
run: |
source .venv/bin/activate
poetry version $RELEASE_VERSION
make build-and-publish
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}

deploy-docs:
runs-on: ubuntu-latest
needs: quality
needs: publish
steps:
- name: Check out
uses: actions/checkout@v3
Expand Down
42 changes: 20 additions & 22 deletions deptry/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,27 @@ def _get_corresponding_top_levels_from(self, dependencies: List[Dependency]) ->
]

def _in_standard_library(self) -> bool:
if self.name in self._get_stdlib_packages():
return True
return False

def _get_stdlib_packages(self) -> Set[str]:
incorrect_version_error = ValueError(
f"Incorrect Python version {'.'.join([str(x) for x in sys.version_info[0:3]])}. Only 3.7, 3.8, 3.9, and"
" 3.10 are currently supported."
)
if sys.version_info[0] == 3:
if sys.version_info[1] == 7:
from deptry.stdlibs.py37 import stdlib
elif sys.version_info[1] == 8:
from deptry.stdlibs.py38 import stdlib
elif sys.version_info[1] == 9:
from deptry.stdlibs.py39 import stdlib
elif sys.version_info[1] == 10:
from deptry.stdlibs.py310 import stdlib
else:
raise incorrect_version_error
return stdlib
return self.name in self._get_stdlib_packages()

@staticmethod
def _get_stdlib_packages() -> Set[str]:
if sys.version_info[:2] == (3, 7):
from deptry.stdlibs.py37 import stdlib
elif sys.version_info[:2] == (3, 8):
from deptry.stdlibs.py38 import stdlib
elif sys.version_info[:2] == (3, 9):
from deptry.stdlibs.py39 import stdlib
elif sys.version_info[:2] == (3, 10):
from deptry.stdlibs.py310 import stdlib
elif sys.version_info[:2] == (3, 11):
from deptry.stdlibs.py311 import stdlib
else:
raise incorrect_version_error
raise ValueError(
f"Python version {'.'.join([str(x) for x in sys.version_info[0:3]])} is not supported. Only 3.7, 3.8,"
" 3.9, 3.10 and 3.11 are currently supported."
)

return stdlib

def _is_local_directory(self) -> bool:
"""
Expand Down
222 changes: 222 additions & 0 deletions deptry/stdlibs/py311.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
"""
DO NOT EDIT THIS FILE MANUALLY.
It is generated from `scripts/generate_stdlibs.py` script and contains the stdlib modules for Python 3.11.
You can generate it again using `poetry run scripts/generate_stdlibs.py`.
"""

stdlib = {
"__future__",
"_ast",
"_thread",
"abc",
"aifc",
"argparse",
"array",
"ast",
"asynchat",
"asyncio",
"asyncore",
"atexit",
"audioop",
"base64",
"bdb",
"binascii",
"bisect",
"builtins",
"bz2",
"cProfile",
"calendar",
"cgi",
"cgitb",
"chunk",
"cmath",
"cmd",
"code",
"codecs",
"codeop",
"collections",
"colorsys",
"compileall",
"concurrent",
"configparser",
"contextlib",
"contextvars",
"copy",
"copyreg",
"crypt",
"csv",
"ctypes",
"curses",
"dataclasses",
"datetime",
"dbm",
"decimal",
"difflib",
"dis",
"distutils",
"doctest",
"email",
"encodings",
"ensurepip",
"enum",
"errno",
"faulthandler",
"fcntl",
"filecmp",
"fileinput",
"fnmatch",
"fractions",
"ftplib",
"functools",
"gc",
"getopt",
"getpass",
"gettext",
"glob",
"graphlib",
"grp",
"gzip",
"hashlib",
"heapq",
"hmac",
"html",
"http",
"idlelib",
"imaplib",
"imghdr",
"imp",
"importlib",
"inspect",
"io",
"ipaddress",
"itertools",
"json",
"keyword",
"lib2to3",
"linecache",
"locale",
"logging",
"lzma",
"mailbox",
"mailcap",
"marshal",
"math",
"mimetypes",
"mmap",
"modulefinder",
"msilib",
"msvcrt",
"multiprocessing",
"netrc",
"nis",
"nntplib",
"ntpath",
"numbers",
"operator",
"optparse",
"os",
"ossaudiodev",
"pathlib",
"pdb",
"pickle",
"pickletools",
"pipes",
"pkgutil",
"platform",
"plistlib",
"poplib",
"posix",
"posixpath",
"pprint",
"profile",
"pstats",
"pty",
"pwd",
"py_compile",
"pyclbr",
"pydoc",
"queue",
"quopri",
"random",
"re",
"readline",
"reprlib",
"resource",
"rlcompleter",
"runpy",
"sched",
"secrets",
"select",
"selectors",
"shelve",
"shlex",
"shutil",
"signal",
"site",
"smtpd",
"smtplib",
"sndhdr",
"socket",
"socketserver",
"spwd",
"sqlite3",
"sre",
"sre_compile",
"sre_constants",
"sre_parse",
"ssl",
"stat",
"statistics",
"string",
"stringprep",
"struct",
"subprocess",
"sunau",
"symtable",
"sys",
"sysconfig",
"syslog",
"tabnanny",
"tarfile",
"telnetlib",
"tempfile",
"termios",
"test",
"textwrap",
"threading",
"time",
"timeit",
"tkinter",
"token",
"tokenize",
"tomllib",
"trace",
"traceback",
"tracemalloc",
"tty",
"turtle",
"turtledemo",
"types",
"typing",
"unicodedata",
"unittest",
"urllib",
"uu",
"uuid",
"venv",
"warnings",
"wave",
"weakref",
"webbrowser",
"winreg",
"winsound",
"wsgiref",
"xdrlib",
"xml",
"xmlrpc",
"zipapp",
"zipfile",
"zipimport",
"zlib",
"zoneinfo",
}
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Developers",
# Remove 3.11 classifier once https://github.com/python-poetry/poetry-core/pull/477 is merged and released.
"Programming Language :: Python :: 3.11",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: Quality Assurance",
]
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_stdlibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

OUTPUT_PATH = "deptry/stdlibs/py{}.py"
STDLIB_MODULES_URL = "https://docs.python.org/{}/py-modindex.html"
PYTHON_VERSIONS = (("3", "7"), ("3", "8"), ("3", "9"), ("3", "10"))
PYTHON_VERSIONS = (("3", "7"), ("3", "8"), ("3", "9"), ("3", "10"), ("3", "11"))

# Modules that are in stdlib, but undocumented.
EXTRA_STDLIBS_MODULES = ("_ast", "ntpath", "posixpath", "sre", "sre_constants", "sre_compile", "sre_parse")
Expand Down
Loading

0 comments on commit 9c886fe

Please sign in to comment.