diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4e256efb..11406afc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.1.6" + rev: "v0.1.8" hooks: - id: ruff args: [--exit-non-zero-on-fix] diff --git a/deptry/stdlibs.py b/deptry/stdlibs.py index d20d8209..72384eda 100644 --- a/deptry/stdlibs.py +++ b/deptry/stdlibs.py @@ -8,444 +8,440 @@ from __future__ import annotations STDLIBS_PYTHON = { - "38": 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", - "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", - } - ), - "39": frozenset( - { - "__future__", - "_ast", - "_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", - "email", - "encodings", - "ensurepip", - "enum", - "errno", - "faulthandler", - "fcntl", - "filecmp", - "fileinput", - "fnmatch", - "formatter", - "fractions", - "ftplib", - "functools", - "gc", - "getopt", - "getpass", - "gettext", - "glob", - "graphlib", - "grp", - "gzip", - "hashlib", - "heapq", - "hmac", - "html", - "http", - "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", - "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", - "zoneinfo", - } - ), + "38": 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", + "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", + }), + "39": frozenset({ + "__future__", + "_ast", + "_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", + "email", + "encodings", + "ensurepip", + "enum", + "errno", + "faulthandler", + "fcntl", + "filecmp", + "fileinput", + "fnmatch", + "formatter", + "fractions", + "ftplib", + "functools", + "gc", + "getopt", + "getpass", + "gettext", + "glob", + "graphlib", + "grp", + "gzip", + "hashlib", + "heapq", + "hmac", + "html", + "http", + "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", + "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", + "zoneinfo", + }), } diff --git a/deptry/violations/dep001_missing/finder.py b/deptry/violations/dep001_missing/finder.py index e2e41625..f4ed81df 100644 --- a/deptry/violations/dep001_missing/finder.py +++ b/deptry/violations/dep001_missing/finder.py @@ -34,14 +34,12 @@ def find(self) -> list[Violation]: return missing_dependencies def _is_missing(self, module: Module) -> bool: - if any( - [ - module.package is not None, - module.is_provided_by_dependency, - module.is_provided_by_dev_dependency, - module.local_module, - ] - ): + if any([ + module.package is not None, + module.is_provided_by_dependency, + module.is_provided_by_dev_dependency, + module.local_module, + ]): return False if module.name in self.ignored_modules: diff --git a/deptry/violations/dep003_transitive/finder.py b/deptry/violations/dep003_transitive/finder.py index c264034c..a23c7718 100644 --- a/deptry/violations/dep003_transitive/finder.py +++ b/deptry/violations/dep003_transitive/finder.py @@ -42,14 +42,12 @@ def find(self) -> list[Violation]: return transitive_dependencies def _is_transitive(self, module: Module) -> bool: - if any( - [ - module.package is None, - module.is_provided_by_dependency, - module.is_provided_by_dev_dependency, - module.local_module, - ] - ): + if any([ + module.package is None, + module.is_provided_by_dependency, + module.is_provided_by_dev_dependency, + module.local_module, + ]): return False if module.name in self.ignored_modules: diff --git a/tests/unit/reporters/test_text.py b/tests/unit/reporters/test_text.py index 06afc824..8fbc578d 100644 --- a/tests/unit/reporters/test_text.py +++ b/tests/unit/reporters/test_text.py @@ -70,9 +70,9 @@ def test_logging_number_multiple(caplog: LogCaptureFixture) -> None: def test_logging_number_single(caplog: LogCaptureFixture) -> None: with caplog.at_level(logging.INFO): - TextReporter( - [DEP001MissingDependencyViolation(Module("foo", package="foo_package"), Location(Path("foo.py"), 1, 2))] - ).report() + TextReporter([ + DEP001MissingDependencyViolation(Module("foo", package="foo_package"), Location(Path("foo.py"), 1, 2)) + ]).report() assert caplog.messages == [ "", diff --git a/tests/unit/test_core.py b/tests/unit/test_core.py index 139ec6ab..4a91aa27 100644 --- a/tests/unit/test_core.py +++ b/tests/unit/test_core.py @@ -66,16 +66,14 @@ def test__get_local_modules( tmp_path: Path, known_first_party: tuple[str, ...], root_suffix: str, expected: set[str] ) -> None: with run_within_dir(tmp_path): - create_files( - [ - Path("module_with_init/__init__.py"), - Path("module_with_init/foo.py"), - Path("module_with_init/subdirectory/__init__.py"), - Path("module_with_init/subdirectory/foo.py"), - Path("module_without_init/bar.py"), - Path("local_file.py"), - ] - ) + create_files([ + Path("module_with_init/__init__.py"), + Path("module_with_init/foo.py"), + Path("module_with_init/subdirectory/__init__.py"), + Path("module_with_init/subdirectory/foo.py"), + Path("module_without_init/bar.py"), + Path("local_file.py"), + ]) assert ( Core( diff --git a/tests/unit/test_python_file_finder.py b/tests/unit/test_python_file_finder.py index 77d5484b..bb8a0a5d 100644 --- a/tests/unit/test_python_file_finder.py +++ b/tests/unit/test_python_file_finder.py @@ -12,15 +12,13 @@ def test_simple(tmp_path: Path) -> None: with run_within_dir(tmp_path): - create_files( - [ - Path("dir/subdir/file1.py"), - Path("dir/subdir/file2.py"), - Path("dir/subdir/file3.py"), - Path("other_dir/subdir/file1.py"), - Path("other_dir/subdir/file2.py"), - ] - ) + create_files([ + Path("dir/subdir/file1.py"), + Path("dir/subdir/file2.py"), + Path("dir/subdir/file3.py"), + Path("other_dir/subdir/file1.py"), + Path("other_dir/subdir/file2.py"), + ]) files = PythonFileFinder( exclude=(".venv",), extend_exclude=("other_dir",), using_default_exclude=False @@ -38,15 +36,13 @@ def test_only_matches_start(tmp_path: Path) -> None: Test that adding 'subdir' as exclude argument does not also exclude dir/subdir. """ with run_within_dir(tmp_path): - create_files( - [ - Path("dir/subdir/file1.py"), - Path("dir/subdir/file2.py"), - Path("dir/subdir/file3.py"), - Path("subdir/file1.py"), - Path("subdir/file2.py"), - ] - ) + create_files([ + Path("dir/subdir/file1.py"), + Path("dir/subdir/file2.py"), + Path("dir/subdir/file3.py"), + Path("subdir/file1.py"), + Path("subdir/file2.py"), + ]) files = PythonFileFinder( exclude=("subdir",), extend_exclude=(), using_default_exclude=False @@ -114,17 +110,15 @@ def test_matches_ipynb(ignore_notebooks: bool, expected: list[Path], tmp_path: P ) def test_regex_argument(exclude: tuple[str], expected: list[Path], tmp_path: Path) -> None: with run_within_dir(tmp_path): - create_files( - [ - Path(".cache/file1.py"), - Path(".cache/file2.py"), - Path("dir/subdir/file1.py"), - Path("dir/subdir/file2.py"), - Path("dir/subdir/file3.py"), - Path("other_dir/subdir/file1.py"), - Path("other_dir/subdir/file2.py"), - ] - ) + create_files([ + Path(".cache/file1.py"), + Path(".cache/file2.py"), + Path("dir/subdir/file1.py"), + Path("dir/subdir/file2.py"), + Path("dir/subdir/file3.py"), + Path("other_dir/subdir/file1.py"), + Path("other_dir/subdir/file2.py"), + ]) files = PythonFileFinder( exclude=exclude, extend_exclude=(), using_default_exclude=False @@ -158,16 +152,14 @@ def test_regex_argument(exclude: tuple[str], expected: list[Path], tmp_path: Pat ) def test_multiple_source_directories(exclude: tuple[str], expected: list[Path], tmp_path: Path) -> None: with run_within_dir(tmp_path): - create_files( - [ - Path("dir/subdir/file1.py"), - Path("dir/subdir/file2.py"), - Path("dir/subdir/file3.py"), - Path("other_dir/subdir/file1.py"), - Path("other_dir/subdir/file2.py"), - Path("another_dir/subdir/file1.py"), - ] - ) + create_files([ + Path("dir/subdir/file1.py"), + Path("dir/subdir/file2.py"), + Path("dir/subdir/file3.py"), + Path("other_dir/subdir/file1.py"), + Path("other_dir/subdir/file2.py"), + Path("another_dir/subdir/file1.py"), + ]) files = PythonFileFinder( exclude=exclude, extend_exclude=(), using_default_exclude=False @@ -180,9 +172,10 @@ def test_duplicates_are_removed(tmp_path: Path) -> None: with run_within_dir(tmp_path): create_files([Path("dir/subdir/file1.py")]) - files = PythonFileFinder(exclude=(), extend_exclude=(), using_default_exclude=False).get_all_python_files_in( - (Path(), Path()) - ) + files = PythonFileFinder(exclude=(), extend_exclude=(), using_default_exclude=False).get_all_python_files_in(( + Path(), + Path(), + )) assert sorted(files) == [Path("dir/subdir/file1.py")]