From 2063cdae3e319e9c1f982ed99a49f6cc9000927b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 9 Jan 2025 23:48:42 +0100 Subject: [PATCH 1/5] Update typing for `setuptools` The inspiration for this change was the following warning from `poetry`: Warning: The locked version 0.1.3 for types-pkg-resources is a yanked version. Reason for being yanked: Use types-setuptools instead Following that, adding `types-setuptools` allowed the removal of some `type: ignore` comments, which then lead to a single issue needing to be fixed: tests/unit/test_setuptools_command.py:8: error: Argument 1 to "ISortCommand" has incompatible type "distutils.dist.Distribution"; expected "setuptools.dist.Distribution" [arg-type] Co-authored-by: Matthew Hughes --- isort/setuptools_commands.py | 4 ++-- poetry.lock | 24 ++++++++++++------------ pyproject.toml | 2 +- tests/unit/test_setuptools_command.py | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/isort/setuptools_commands.py b/isort/setuptools_commands.py index e0538ffe1..74f204ffb 100644 --- a/isort/setuptools_commands.py +++ b/isort/setuptools_commands.py @@ -4,13 +4,13 @@ from typing import Any, Dict, Iterator, List from warnings import warn -import setuptools # type: ignore +import setuptools from . import api from .settings import DEFAULT_CONFIG -class ISortCommand(setuptools.Command): # type: ignore +class ISortCommand(setuptools.Command): """The :class:`ISortCommand` class is used by setuptools to perform imports checks on registered modules. """ diff --git a/poetry.lock b/poetry.lock index 9d16de87d..b07488ffb 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2465,17 +2465,6 @@ files = [ {file = "types_colorama-0.4.15.12-py3-none-any.whl", hash = "sha256:23c9d4a00961227f7ef018d5a1c190c4bbc282119c3ee76a17677a793f13bb82"}, ] -[[package]] -name = "types-pkg-resources" -version = "0.1.3" -description = "Typing stubs for pkg_resources" -optional = false -python-versions = "*" -files = [ - {file = "types-pkg_resources-0.1.3.tar.gz", hash = "sha256:834a9b8d3dbea343562fd99d5d3359a726f6bf9d3733bccd2b4f3096fbab9dae"}, - {file = "types_pkg_resources-0.1.3-py2.py3-none-any.whl", hash = "sha256:0cb9972cee992249f93fff1a491bf2dc3ce674e5a1926e27d4f0866f7d9b6d9c"}, -] - [[package]] name = "types-python-dateutil" version = "2.8.19.14" @@ -2487,6 +2476,17 @@ files = [ {file = "types_python_dateutil-2.8.19.14-py3-none-any.whl", hash = "sha256:f977b8de27787639986b4e28963263fd0e5158942b3ecef91b9335c130cb1ce9"}, ] +[[package]] +name = "types-setuptools" +version = "75.6.0.20241126" +description = "Typing stubs for setuptools" +optional = false +python-versions = ">=3.8" +files = [ + {file = "types_setuptools-75.6.0.20241126-py3-none-any.whl", hash = "sha256:aaae310a0e27033c1da8457d4d26ac673b0c8a0de7272d6d4708e263f2ea3b9b"}, + {file = "types_setuptools-75.6.0.20241126.tar.gz", hash = "sha256:7bf25ad4be39740e469f9268b6beddda6e088891fa5a27e985c6ce68bf62ace0"}, +] + [[package]] name = "types-toml" version = "0.10.8.7" @@ -2672,4 +2672,4 @@ plugins = [] [metadata] lock-version = "2.0" python-versions = ">=3.8.0" -content-hash = "af40040169eed27512d6c410555090b114596c1cabc2db893ecbe36cc25a91cd" +content-hash = "18332649b028357816abdf722df1d35f3937fd766781dbe40af7e9219da4c46c" diff --git a/pyproject.toml b/pyproject.toml index b2e25ec49..cb86d689b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,7 +80,7 @@ mypy-extensions = ">=0.4.3" pre-commit = ">=2.13.0" pytest-benchmark = ">=3.4.1" toml = ">=0.10.2" -types-pkg-resources = ">=0.1.2" +types-setuptools = ">=70.0.0.20240523" types-colorama = ">=0.4.2" types-toml = ">=0.1.3" vulture = ">=1.0" diff --git a/tests/unit/test_setuptools_command.py b/tests/unit/test_setuptools_command.py index c8da0d23b..ba7157ff6 100644 --- a/tests/unit/test_setuptools_command.py +++ b/tests/unit/test_setuptools_command.py @@ -3,7 +3,7 @@ def test_isort_command_smoke(src_dir): """A basic smoke test for the setuptools_commands command""" - from distutils.dist import Distribution + from setuptools.dist import Distribution command = setuptools_commands.ISortCommand(Distribution()) command.distribution.packages = ["isort"] From de6403c2bd9c77da9bf6cdac74cb440dd11f2f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 9 Jan 2025 23:50:29 +0100 Subject: [PATCH 2/5] Remove support for Python 3.8 --- .github/workflows/test.yml | 2 +- README.md | 2 +- docs/configuration/black_compatibility.md | 1 - docs/configuration/github_action.md | 2 +- docs/contributing/1.-contributing-guide.md | 2 +- isort/api.py | 9 +++------ poetry.lock | 8 ++------ pyproject.toml | 5 ++--- scripts/docker.sh | 2 +- 9 files changed, 12 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b3dfbd5c1..4ffe0d537 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12"] os: [ubuntu-latest, macos-latest, windows-latest] steps: diff --git a/README.md b/README.md index 84b20244a..bd085730f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ isort is a Python utility / library to sort imports alphabetically and automatically separate into sections and by type. It provides a command line utility, Python library and [plugins for various editors](https://github.com/pycqa/isort/wiki/isort-Plugins) to -quickly sort all your imports. It requires Python 3.8+ to run but +quickly sort all your imports. It requires Python 3.9+ to run but supports formatting Python 2 code too. - [Try isort now from your browser!](https://pycqa.github.io/isort/docs/quick_start/0.-try.html) diff --git a/docs/configuration/black_compatibility.md b/docs/configuration/black_compatibility.md index 3cf437e88..5a91e026c 100644 --- a/docs/configuration/black_compatibility.md +++ b/docs/configuration/black_compatibility.md @@ -34,7 +34,6 @@ language: python python: - "3.10" - "3.9" - - "3.8" install: - pip install -r requirements-dev.txt diff --git a/docs/configuration/github_action.md b/docs/configuration/github_action.md index 343a27252..4a983f093 100644 --- a/docs/configuration/github_action.md +++ b/docs/configuration/github_action.md @@ -51,7 +51,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: 3.9 - uses: isort/isort-action@master with: requirementsFiles: "requirements.txt requirements-test.txt" diff --git a/docs/contributing/1.-contributing-guide.md b/docs/contributing/1.-contributing-guide.md index 3f65be85e..b10cf571b 100644 --- a/docs/contributing/1.-contributing-guide.md +++ b/docs/contributing/1.-contributing-guide.md @@ -14,7 +14,7 @@ Account Requirements: Base System Requirements: -- Python3.8+ +- Python3.9+ - poetry - bash or a bash compatible shell (should be auto-installed on Linux / Mac) - WSL users running Ubuntu may need to install Python's venv module even after installing Python. diff --git a/isort/api.py b/isort/api.py index 3a304c1c0..3d636c3ee 100644 --- a/isort/api.py +++ b/isort/api.py @@ -466,12 +466,9 @@ def sort_file( if not config.quiet: print(f"Fixing {source_file.path}") finally: - try: # Python 3.8+: use `missing_ok=True` instead of try except. - if not config.overwrite_in_place: # pragma: no branch - tmp_file = _tmp_file(source_file) - tmp_file.unlink() - except FileNotFoundError: - pass # pragma: no cover + if not config.overwrite_in_place: # pragma: no branch + tmp_file = _tmp_file(source_file) + tmp_file.unlink(missing_ok=True) else: changed = sort_stream( input_stream=source_file.stream, diff --git a/poetry.lock b/poetry.lock index b07488ffb..61afc5cef 100644 --- a/poetry.lock +++ b/poetry.lock @@ -11,9 +11,6 @@ files = [ {file = "annotated_types-0.6.0.tar.gz", hash = "sha256:563339e807e53ffd9c267e99fc6d9ea23eb8443c08f112651963e24e22f84a5d"}, ] -[package.dependencies] -typing-extensions = {version = ">=4.0.0", markers = "python_version < \"3.9\""} - [[package]] name = "anyio" version = "4.4.0" @@ -2132,7 +2129,6 @@ files = [ [package.dependencies] markdown-it-py = ">=2.2.0" pygments = ">=2.13.0,<3.0.0" -typing-extensions = {version = ">=4.0.0,<5.0", markers = "python_version < \"3.9\""} [package.extras] jupyter = ["ipywidgets (>=7.5.1,<9)"] @@ -2671,5 +2667,5 @@ plugins = [] [metadata] lock-version = "2.0" -python-versions = ">=3.8.0" -content-hash = "18332649b028357816abdf722df1d35f3937fd766781dbe40af7e9219da4c46c" +python-versions = ">=3.9.0" +content-hash = "6264c8bcf1e07ddbdf830bcb8b251a8cf738fab9bea4860ed819ab91cdfccc8b" diff --git a/pyproject.toml b/pyproject.toml index cb86d689b..f860a6d9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,6 @@ classifiers = [ "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -40,7 +39,7 @@ include = [ ] [tool.poetry.dependencies] -python = ">=3.8.0" +python = ">=3.9.0" colorama = {version = ">=0.4.6", optional = true} [tool.poetry.extras] @@ -138,7 +137,7 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.mypy] -python_version = 3.8 +python_version = 3.9 strict = true follow_imports = "silent" exclude = "isort/_vendored|tests/unit/example_projects|tests/unit/example_crlf_file.py" diff --git a/scripts/docker.sh b/scripts/docker.sh index 1ca23e0e2..51ebe4ccc 100755 --- a/scripts/docker.sh +++ b/scripts/docker.sh @@ -3,7 +3,7 @@ set -ux result=0 -for ver in {3.8,3.9,3.10}; do +for ver in {3.9,3.10}; do # latest tag will override after each build, leaving only the newest python version tagged docker build ./ --build-arg VERSION=$ver -t "isort:$ver" -t "isort:latest" && docker run "isort:$ver" result=$(( $? + $result )) From 9abe8d73c6262770b9c66b11efd06fde8d8868fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Fri, 10 Jan 2025 00:04:01 +0100 Subject: [PATCH 3/5] Add ignore for `PY-R1000` --- isort/api.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/isort/api.py b/isort/api.py index 3d636c3ee..61c9b5e5a 100644 --- a/isort/api.py +++ b/isort/api.py @@ -363,6 +363,9 @@ def _file_output_stream_context(filename: Union[str, Path], source_file: File) - yield output_stream +# Ignore DeepSource cyclomatic complexity check for this function. It is one +# the main entrypoints so sort of expected to be complex. +# skipcq: PY-R1000 def sort_file( filename: Union[str, Path], extension: Optional[str] = None, From 46f63c3631bc794dca2f53b658eae45e2b15c9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:26:35 +0100 Subject: [PATCH 4/5] Change target version for `black` --- scripts/lint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lint.sh b/scripts/lint.sh index 3d938a9a9..e9118ff06 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -3,7 +3,7 @@ set -euxo pipefail poetry run cruft check poetry run mypy -p isort -p tests -poetry run black --target-version py38 --check . +poetry run black --target-version py39 --check . poetry run isort --profile hug --check --diff isort/ tests/ poetry run isort --profile hug --check --diff example_*/ poetry run flake8 isort/ tests/ From 064cfd730981574b702199e6a142ff42b5e5f40a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:26:46 +0100 Subject: [PATCH 5/5] Update automatic `py_version` discovery --- isort/settings.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/isort/settings.py b/isort/settings.py index 7f66dc47e..80eccae2b 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -252,14 +252,7 @@ class _Config: def __post_init__(self) -> None: py_version = self.py_version if py_version == "auto": # pragma: no cover - if sys.version_info.major == 2 and sys.version_info.minor <= 6: - py_version = "2" - elif sys.version_info.major == 3 and ( - sys.version_info.minor <= 5 or sys.version_info.minor >= 12 - ): - py_version = "3" - else: - py_version = f"{sys.version_info.major}{sys.version_info.minor}" + py_version = f"{sys.version_info.major}{sys.version_info.minor}" if py_version not in VALID_PY_TARGETS: raise ValueError(