Skip to content

Commit

Permalink
feat!: drop support for Python 3.7 (#352)
Browse files Browse the repository at this point in the history
* feat!: require Python >= 3.8

* chore: set tooling Python target version to >= 3.8

* chore: run `pre-commit run -a`

* refactor: remove obsolete `compat`

* chore: remove obsolete Python 3.7 only dependencies

* chore: remove `3.7` from `stdlibs` generation script

* chore: run `poetry run scripts/generated_stdlibs.py`

* ci: remove Python 3.7

* chore(tox): remove Python 3.7

* chore(mypy): remove unused ignores
  • Loading branch information
mkniewallner authored May 6, 2023
1 parent f1f9419 commit d7ee7b2
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 310 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
strategy:
matrix:
os: [macOS, Ubuntu, Windows]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
include:
- os: macOS
image: macos-12
Expand Down
4 changes: 2 additions & 2 deletions deptry/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import logging
from collections import defaultdict
from importlib.metadata import version
from pathlib import Path
from typing import TYPE_CHECKING

import click

from deptry.compat import metadata
from deptry.config import read_configuration_from_pyproject_toml
from deptry.core import Core

Expand Down Expand Up @@ -93,7 +93,7 @@ def display_deptry_version(ctx: click.Context, _param: click.Parameter, value: b
if not value or ctx.resilient_parsing:
return None

click.echo(f'deptry {metadata.version("deptry")}') # type: ignore[no-untyped-call]
click.echo(f'deptry {version("deptry")}')
ctx.exit()


Expand Down
12 changes: 0 additions & 12 deletions deptry/compat.py

This file was deleted.

16 changes: 8 additions & 8 deletions deptry/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import logging
import re
from contextlib import suppress
from importlib import metadata
from typing import TYPE_CHECKING

from deptry.compat import metadata

if TYPE_CHECKING:
from collections.abc import Sequence
from importlib.metadata import Distribution


class Dependency:
Expand Down Expand Up @@ -36,7 +36,7 @@ def __init__(
self.top_levels = self._get_top_levels(name, distribution, module_names)

def _get_top_levels(
self, name: str, distribution: metadata.Distribution | None, module_names: Sequence[str] | None
self, name: str, distribution: Distribution | None, module_names: Sequence[str] | None
) -> set[str]:
if module_names is not None:
return set(module_names)
Expand Down Expand Up @@ -64,7 +64,7 @@ def __str__(self) -> str:
return f"Dependency '{self.name}'{self._string_for_printing()}with top-levels: {self.top_levels}."

@staticmethod
def find_distribution(name: str) -> metadata.Distribution | None:
def find_distribution(name: str) -> Distribution | None:
try:
return metadata.distribution(name)
except metadata.PackageNotFoundError:
Expand All @@ -86,7 +86,7 @@ def _string_for_printing(self) -> str:
return " "

@staticmethod
def _get_top_level_module_names_from_top_level_txt(distribution: metadata.Distribution) -> set[str]:
def _get_top_level_module_names_from_top_level_txt(distribution: Distribution) -> set[str]:
"""
top-level.txt is a metadata file added by setuptools that looks as follows:
Expand All @@ -98,14 +98,14 @@ def _get_top_level_module_names_from_top_level_txt(distribution: metadata.Distri
This function extracts these names, if a top-level.txt file exists.
"""
metadata_top_levels = distribution.read_text("top_level.txt") # type: ignore[no-untyped-call]
metadata_top_levels = distribution.read_text("top_level.txt")
if metadata_top_levels is None:
raise FileNotFoundError("top_level.txt")

return {x for x in metadata_top_levels.splitlines() if x}

@staticmethod
def _get_top_level_module_names_from_record_file(distribution: metadata.Distribution) -> set[str]:
def _get_top_level_module_names_from_record_file(distribution: Distribution) -> set[str]:
"""
Get the top-level module names from the RECORD file, whose contents usually look as follows:
Expand All @@ -122,7 +122,7 @@ def _get_top_level_module_names_from_record_file(distribution: metadata.Distribu
So if no file top-level.txt is provided, we can try and extract top-levels from this file, in
this case _black_version, black, and blackd.
"""
metadata_records = distribution.read_text("RECORD") # type: ignore[no-untyped-call]
metadata_records = distribution.read_text("RECORD")

if metadata_records is None:
raise FileNotFoundError("RECORD")
Expand Down
2 changes: 1 addition & 1 deletion deptry/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ def __init__(self, directory: str) -> None:
class UnsupportedPythonVersionError(ValueError):
def __init__(self, version: tuple[int, int]) -> None:
super().__init__(
f"Python version {version[0]}.{version[1]} is not supported. Only versions >= 3.7 are supported."
f"Python version {version[0]}.{version[1]} is not supported. Only versions >= 3.8 are supported."
)
5 changes: 2 additions & 3 deletions deptry/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import logging
from dataclasses import dataclass
from importlib.metadata import PackageNotFoundError, metadata
from typing import TYPE_CHECKING

from deptry.compat import PackageNotFoundError, metadata

if TYPE_CHECKING:
from deptry.dependency import Dependency

Expand Down Expand Up @@ -93,7 +92,7 @@ def _get_package_name_from_metadata(self) -> str | None:
Most packages simply have a field called "Name" in their metadata. This method extracts that field.
"""
try:
name: str = metadata.metadata(self.name)["Name"] # type: ignore[no-untyped-call]
name: str = metadata(self.name)["Name"]
except PackageNotFoundError:
return None
else:
Expand Down
221 changes: 0 additions & 221 deletions deptry/stdlibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,227 +7,6 @@
from __future__ import annotations

STDLIBS_PYTHON = {
"37": frozenset(
{
"__future__",
"_ast",
"_dummy_thread",
"_thread",
"abc",
"aifc",
"argparse",
"array",
"ast",
"asynchat",
"asyncio",
"asyncore",
"atexit",
"audioop",
"base64",
"bdb",
"binascii",
"binhex",
"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",
"dummy_threading",
"email",
"encodings",
"ensurepip",
"enum",
"errno",
"faulthandler",
"fcntl",
"filecmp",
"fileinput",
"fnmatch",
"formatter",
"fractions",
"ftplib",
"functools",
"gc",
"getopt",
"getpass",
"gettext",
"glob",
"grp",
"gzip",
"hashlib",
"heapq",
"hmac",
"html",
"http",
"imaplib",
"imghdr",
"imp",
"importlib",
"inspect",
"io",
"ipaddress",
"itertools",
"json",
"keyword",
"lib2to3",
"linecache",
"locale",
"logging",
"lzma",
"macpath",
"mailbox",
"mailcap",
"marshal",
"math",
"mimetypes",
"mmap",
"modulefinder",
"msilib",
"msvcrt",
"multiprocessing",
"netrc",
"nis",
"nntplib",
"ntpath",
"numbers",
"operator",
"optparse",
"os",
"ossaudiodev",
"parser",
"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",
"symbol",
"symtable",
"sys",
"sysconfig",
"syslog",
"tabnanny",
"tarfile",
"telnetlib",
"tempfile",
"termios",
"test",
"textwrap",
"threading",
"time",
"timeit",
"tkinter",
"token",
"tokenize",
"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",
}
),
"38": frozenset(
{
"__future__",
Expand Down
Loading

0 comments on commit d7ee7b2

Please sign in to comment.