From 6b69376a76ee5c72504ce8756685812d737d8a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Fri, 3 Mar 2023 08:34:51 -0800 Subject: [PATCH 01/14] Bump deps and tools and fix CI (#72) --- .pre-commit-config.yaml | 8 ++++++-- README.md | 2 +- pyproject.toml | 6 +++--- src/pyproject_fmt/formatter/util.py | 4 ++-- tests/formatter/test_tools.py | 2 -- tox.ini | 5 +++-- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8429cc3..e2ec35c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,14 +39,18 @@ repos: hooks: - id: tox-ini-fmt args: [ "-p", "fix" ] + - repo: https://github.com/tox-dev/pyproject-fmt + rev: "0.9.2" + hooks: + - id: pyproject-fmt - repo: https://github.com/PyCQA/flake8 rev: 6.0.0 hooks: - id: flake8 additional_dependencies: - - flake8-bugbear==23.1.20 + - flake8-bugbear==23.2.13 - flake8-comprehensions==3.10.1 - - flake8-pytest-style==1.7 + - flake8-pytest-style==1.7.2 - flake8-spellcheck==0.28 - flake8-unused-arguments==0.0.13 - flake8-noqa==1.3 diff --git a/README.md b/README.md index b2a3cf6..09a8812 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Apply a consistent format to `pyproject.toml` files. ```yaml - repo: https://github.com/tox-dev/pyproject-fmt - rev: "0.9.0" + rev: "0.9.2" hooks: - id: pyproject-fmt ``` diff --git a/pyproject.toml b/pyproject.toml index 8aa05be..00714f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ requires = [ ] [project] -name = "pyproject_fmt" +name = "pyproject-fmt" description = "Format your pyproject.toml file" readme = "README.md" keywords = [ @@ -33,7 +33,7 @@ dynamic = [ dependencies = [ "packaging>=23", "tomlkit>=0.11.6", - 'typing-extensions>=4.4; python_version < "3.8"', + 'typing-extensions>=4.5; python_version < "3.8"', ] optional-dependencies.docs = [ "furo>=2022.12.7", @@ -49,9 +49,9 @@ optional-dependencies.test = [ "pytest-mock>=3.10", ] urls."Bug Tracker" = "https://github.com/tox-dev/pyproject-fmt/issues" +urls."Changelog" = "https://github.com/tox-dev/pyproject-fmt/releases" urls.Documentation = "https://github.com/tox-dev/pyproject-fmt/" urls."Source Code" = "https://github.com/tox-dev/pyproject-fmt" -urls."Changelog" = "https://github.com/tox-dev/pyproject-fmt/releases" scripts.pyproject-fmt = "pyproject_fmt.__main__:run" [tool.hatch] diff --git a/src/pyproject_fmt/formatter/util.py b/src/pyproject_fmt/formatter/util.py index 32383f5..5d35284 100644 --- a/src/pyproject_fmt/formatter/util.py +++ b/src/pyproject_fmt/formatter/util.py @@ -108,12 +108,12 @@ def sorted_array( def ensure_newline_at_end(body: Table) -> None: - content = body + content: Table = body while True: if isinstance(content, AoT) and content.value and isinstance(content[-1], (AoT, Table)): content = content[-1] elif isinstance(content, Table) and content.value.body and isinstance(content.value.body[-1][1], (AoT, Table)): - content = content.value.body[-1][1] + content = content.value.body[-1][1] # type: ignore # can be AoT temporarily else: # pragma: no cover # coverage has a bug on python < 3.10, seeing this line as uncovered # https://github.com/nedbat/coveragepy/issues/1480 diff --git a/tests/formatter/test_tools.py b/tests/formatter/test_tools.py index 0497daf..0ef8ec4 100644 --- a/tests/formatter/test_tools.py +++ b/tests/formatter/test_tools.py @@ -54,7 +54,6 @@ def test_sub_table_newline(fmt: Fmt) -> None: content = """ [tool.mypy] a = 0 - [[tool.mypy.overrides]] a = 1 [tool.something-else] @@ -63,7 +62,6 @@ def test_sub_table_newline(fmt: Fmt) -> None: expected = """ [tool.mypy] a = 0 - [[tool.mypy.overrides]] a = 1 diff --git a/tox.ini b/tox.ini index 070de9e..e217a2e 100644 --- a/tox.ini +++ b/tox.ini @@ -34,7 +34,7 @@ wheel_build_env = .pkg description = run static analysis and style check using flake8 skip_install = true deps = - pre-commit>=3.0.4 + pre-commit>=3.1.1 commands = pre-commit run --all-files --show-diff-on-failure python -c 'print("hint: run {envdir}/bin/pre-commit install to add checks as pre-commit hook")' @@ -46,7 +46,8 @@ setenv = deps = mypy==1 commands = - mypy --strict --python-version 3.10 src tests + mypy src + mypy tests [testenv:readme] description = check that the long description is valid From 143f8bc532e54c010bf9cb3bbb39b33613b91ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Sun, 12 Mar 2023 10:36:28 -0700 Subject: [PATCH 02/14] Add pyproject-fmt (#74) --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e2ec35c..116692d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,3 +56,7 @@ repos: - flake8-noqa==1.3 - pep8-naming==0.13.3 - flake8-pyproject==1.2.2 + - repo: https://github.com/tox-dev/pyproject-fmt + rev: "0.9.2" + hooks: + - id: pyproject-fmt From e5002919f240be967fd492c6900de848fa2d9409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Sun, 12 Mar 2023 10:36:33 -0700 Subject: [PATCH 03/14] Bump deps and tools (#73) --- pyproject.toml | 4 ++-- tox.ini | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 00714f3..20f04cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,8 +43,8 @@ optional-dependencies.docs = [ "sphinx-copybutton>=0.5.1", ] optional-dependencies.test = [ - "covdefaults>=2.2.2", - "pytest>=7.2.1", + "covdefaults>=2.3", + "pytest>=7.2.2", "pytest-cov>=4", "pytest-mock>=3.10", ] diff --git a/tox.ini b/tox.ini index e217a2e..ac527d6 100644 --- a/tox.ini +++ b/tox.ini @@ -44,7 +44,7 @@ description = run type check on code base setenv = {tty:MYPY_FORCE_COLOR = 1} deps = - mypy==1 + mypy==1.1.1 commands = mypy src mypy tests From ffbe4b936b599a9af3e7d5f3ead9e53482a1f00d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Mar 2023 07:19:31 -0700 Subject: [PATCH 04/14] Bump pypa/gh-action-pypi-publish from 1.6.4 to 1.7.1 (#75) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1fbb688..ac0ecce 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -85,7 +85,7 @@ jobs: - name: build package run: python -m build --sdist --wheel . -o dist - name: publish to PyPI - uses: pypa/gh-action-pypi-publish@v1.6.4 + uses: pypa/gh-action-pypi-publish@v1.7.1 with: skip_existing: true user: __token__ From fb49eef4939a18f515523e885ea51f9fddf31442 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 17 Mar 2023 08:31:55 -0700 Subject: [PATCH 05/14] Bump pypa/gh-action-pypi-publish from 1.7.1 to 1.8.1 (#77) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ac0ecce..4e0f2fc 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -85,7 +85,7 @@ jobs: - name: build package run: python -m build --sdist --wheel . -o dist - name: publish to PyPI - uses: pypa/gh-action-pypi-publish@v1.7.1 + uses: pypa/gh-action-pypi-publish@v1.8.1 with: skip_existing: true user: __token__ From ee4855c7ed690a5a4fab183b57d1c51d97ac12c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Sat, 18 Mar 2023 21:17:42 -0700 Subject: [PATCH 06/14] Bump deps and tools (#78) --- .pre-commit-config.yaml | 6 +++--- tox.ini | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 116692d..fe92b7d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -48,12 +48,12 @@ repos: hooks: - id: flake8 additional_dependencies: - - flake8-bugbear==23.2.13 - - flake8-comprehensions==3.10.1 + - flake8-bugbear==23.3.12 + - flake8-comprehensions==3.11 - flake8-pytest-style==1.7.2 - flake8-spellcheck==0.28 - flake8-unused-arguments==0.0.13 - - flake8-noqa==1.3 + - flake8-noqa==1.3.1 - pep8-naming==0.13.3 - flake8-pyproject==1.2.2 - repo: https://github.com/tox-dev/pyproject-fmt diff --git a/tox.ini b/tox.ini index ac527d6..c7b2a88 100644 --- a/tox.ini +++ b/tox.ini @@ -34,7 +34,7 @@ wheel_build_env = .pkg description = run static analysis and style check using flake8 skip_install = true deps = - pre-commit>=3.1.1 + pre-commit>=3.2 commands = pre-commit run --all-files --show-diff-on-failure python -c 'print("hint: run {envdir}/bin/pre-commit install to add checks as pre-commit hook")' From e0a356e204bc39af04fdb9ecb9794bbb91c1882a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Tue, 21 Mar 2023 14:54:27 -0700 Subject: [PATCH 07/14] Bump deps and tools (#79) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fe92b7d..e0778fe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,13 +49,13 @@ repos: - id: flake8 additional_dependencies: - flake8-bugbear==23.3.12 - - flake8-comprehensions==3.11 + - flake8-comprehensions==3.11.1 - flake8-pytest-style==1.7.2 - flake8-spellcheck==0.28 - flake8-unused-arguments==0.0.13 - flake8-noqa==1.3.1 - pep8-naming==0.13.3 - - flake8-pyproject==1.2.2 + - flake8-pyproject==1.2.3 - repo: https://github.com/tox-dev/pyproject-fmt rev: "0.9.2" hooks: From 815cf2361ad54bf440c3ced7a94f3ab18a9aedef Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 Mar 2023 07:41:04 -0700 Subject: [PATCH 08/14] Bump pypa/gh-action-pypi-publish from 1.8.1 to 1.8.3 (#80) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 4e0f2fc..1f756b2 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -85,7 +85,7 @@ jobs: - name: build package run: python -m build --sdist --wheel . -o dist - name: publish to PyPI - uses: pypa/gh-action-pypi-publish@v1.8.1 + uses: pypa/gh-action-pypi-publish@v1.8.3 with: skip_existing: true user: __token__ From f78b38810718f5a9f5a19ea846d9d1aeafed6679 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Apr 2023 09:14:52 -0700 Subject: [PATCH 09/14] Bump pypa/gh-action-pypi-publish from 1.8.3 to 1.8.5 (#83) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1f756b2..4f2d813 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -85,7 +85,7 @@ jobs: - name: build package run: python -m build --sdist --wheel . -o dist - name: publish to PyPI - uses: pypa/gh-action-pypi-publish@v1.8.3 + uses: pypa/gh-action-pypi-publish@v1.8.5 with: skip_existing: true user: __token__ From 8601dc73faad80eb2a8cb6ae49d04ae3fff5132a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Apr 2023 09:15:24 -0700 Subject: [PATCH 10/14] [pre-commit.ci] pre-commit autoupdate (#82) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 ++-- tox.ini | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e0778fe..2772fbf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: hooks: - id: isort - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 23.3.0 hooks: - id: black args: [ --safe ] @@ -35,7 +35,7 @@ repos: - id: blacken-docs additional_dependencies: [ black==23.1 ] - repo: https://github.com/tox-dev/tox-ini-fmt - rev: "0.6.1" + rev: "1.0.0" hooks: - id: tox-ini-fmt args: [ "-p", "fix" ] diff --git a/tox.ini b/tox.ini index c7b2a88..f003d9c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,4 +1,6 @@ [tox] +requires = + tox>=4.2 envlist = fix py311 @@ -10,16 +12,17 @@ envlist = readme docs skip_missing_interpreters = true -requires = tox>=4.2 [testenv] description = run the unit tests with pytest under {basepython} +package = wheel +wheel_build_env = .pkg +extras = + test setenv = COVERAGE_FILE = {toxworkdir}/.coverage.{envname} COVERAGE_PROCESS_START = {toxinidir}/setup.cfg _COVERAGE_SRC = {envsitepackagesdir}/sphinx_argparse_cli -extras = - test commands = python -m pytest {tty:--color=yes} {posargs: \ --junitxml {toxworkdir}{/}junit.{envname}.xml --cov {envsitepackagesdir}{/}pyproject_fmt \ @@ -27,8 +30,6 @@ commands = --cov-config=pyproject.toml --no-cov-on-fail --cov-report term-missing:skip-covered --cov-context=test \ --cov-report html:{envtmpdir}{/}htmlcov --cov-report xml:{toxworkdir}{/}coverage.{envname}.xml \ tests} -package = wheel -wheel_build_env = .pkg [testenv:fix] description = run static analysis and style check using flake8 @@ -41,10 +42,10 @@ commands = [testenv:type] description = run type check on code base -setenv = - {tty:MYPY_FORCE_COLOR = 1} deps = mypy==1.1.1 +setenv = + {tty:MYPY_FORCE_COLOR = 1} commands = mypy src mypy tests @@ -69,10 +70,10 @@ commands = [testenv:dev] description = generate a DEV environment +package = editable extras = docs test commands = python -m pip list --format=columns python -c 'import sys; print(sys.executable)' -package = editable From 96abf90aefe1ac6edd16cd982fad4a0f993ac665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Wed, 5 Apr 2023 09:19:46 -0700 Subject: [PATCH 11/14] Bump deps and tools (#85) --- .pre-commit-config.yaml | 4 ++-- pyproject.toml | 4 ++-- tox.ini | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2772fbf..578bd9a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: rev: 1.13.0 hooks: - id: blacken-docs - additional_dependencies: [ black==23.1 ] + additional_dependencies: [ black==23.3 ] - repo: https://github.com/tox-dev/tox-ini-fmt rev: "1.0.0" hooks: @@ -48,7 +48,7 @@ repos: hooks: - id: flake8 additional_dependencies: - - flake8-bugbear==23.3.12 + - flake8-bugbear==23.3.23 - flake8-comprehensions==3.11.1 - flake8-pytest-style==1.7.2 - flake8-spellcheck==0.28 diff --git a/pyproject.toml b/pyproject.toml index 20f04cd..945e109 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,11 +32,11 @@ dynamic = [ ] dependencies = [ "packaging>=23", - "tomlkit>=0.11.6", + "tomlkit>=0.11.7", 'typing-extensions>=4.5; python_version < "3.8"', ] optional-dependencies.docs = [ - "furo>=2022.12.7", + "furo>=2023.3.27", "sphinx>=6.1.3", "sphinx-argparse-cli>=1.11", "sphinx-autodoc-typehints!=1.23.4,>=1.22", diff --git a/tox.ini b/tox.ini index f003d9c..56d23f9 100644 --- a/tox.ini +++ b/tox.ini @@ -35,7 +35,7 @@ commands = description = run static analysis and style check using flake8 skip_install = true deps = - pre-commit>=3.2 + pre-commit>=3.2.1 commands = pre-commit run --all-files --show-diff-on-failure python -c 'print("hint: run {envdir}/bin/pre-commit install to add checks as pre-commit hook")' From 44a50e752a86f50457f2ac388b364425643d5fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Fri, 7 Apr 2023 14:03:27 -0700 Subject: [PATCH 12/14] Bump deps and tools (#86) Committed via https://github.com/asottile/all-repos --- .pre-commit-config.yaml | 2 +- pyproject.toml | 2 +- tox.ini | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 578bd9a..f4504d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,7 +35,7 @@ repos: - id: blacken-docs additional_dependencies: [ black==23.3 ] - repo: https://github.com/tox-dev/tox-ini-fmt - rev: "1.0.0" + rev: "1.3.0" hooks: - id: tox-ini-fmt args: [ "-p", "fix" ] diff --git a/pyproject.toml b/pyproject.toml index 945e109..a297916 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "hatch-vcs>=0.3", - "hatchling>=1.13", + "hatchling>=1.14", ] [project] diff --git a/tox.ini b/tox.ini index 56d23f9..d6b4c78 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] requires = tox>=4.2 -envlist = +env_list = fix py311 py310 @@ -19,7 +19,7 @@ package = wheel wheel_build_env = .pkg extras = test -setenv = +set_env = COVERAGE_FILE = {toxworkdir}/.coverage.{envname} COVERAGE_PROCESS_START = {toxinidir}/setup.cfg _COVERAGE_SRC = {envsitepackagesdir}/sphinx_argparse_cli @@ -35,7 +35,7 @@ commands = description = run static analysis and style check using flake8 skip_install = true deps = - pre-commit>=3.2.1 + pre-commit>=3.2.2 commands = pre-commit run --all-files --show-diff-on-failure python -c 'print("hint: run {envdir}/bin/pre-commit install to add checks as pre-commit hook")' @@ -43,8 +43,8 @@ commands = [testenv:type] description = run type check on code base deps = - mypy==1.1.1 -setenv = + mypy==1.2 +set_env = {tty:MYPY_FORCE_COLOR = 1} commands = mypy src From e984384c10f0defd472e7b28f8219135743b8d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Wed, 19 Apr 2023 10:56:52 -0700 Subject: [PATCH 13/14] Bump deps and tools (#87) --- .pre-commit-config.yaml | 2 +- pyproject.toml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f4504d5..15f96f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,7 +49,7 @@ repos: - id: flake8 additional_dependencies: - flake8-bugbear==23.3.23 - - flake8-comprehensions==3.11.1 + - flake8-comprehensions==3.12 - flake8-pytest-style==1.7.2 - flake8-spellcheck==0.28 - flake8-unused-arguments==0.0.13 diff --git a/pyproject.toml b/pyproject.toml index a297916..da73aba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ dynamic = [ "version", ] dependencies = [ - "packaging>=23", + "packaging>=23.1", "tomlkit>=0.11.7", 'typing-extensions>=4.5; python_version < "3.8"', ] @@ -39,12 +39,12 @@ optional-dependencies.docs = [ "furo>=2023.3.27", "sphinx>=6.1.3", "sphinx-argparse-cli>=1.11", - "sphinx-autodoc-typehints!=1.23.4,>=1.22", - "sphinx-copybutton>=0.5.1", + "sphinx-autodoc-typehints!=1.23.4,>=1.23", + "sphinx-copybutton>=0.5.2", ] optional-dependencies.test = [ "covdefaults>=2.3", - "pytest>=7.2.2", + "pytest>=7.3.1", "pytest-cov>=4", "pytest-mock>=3.10", ] From 115c1e02f0797d08b123382a26a3ef59738ca656 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 21 Apr 2023 23:14:46 -0600 Subject: [PATCH 14/14] Sort classifiers and respect `--indent` (#84) * Sort classifiers and respect --indent * Set lower bound as the latest version * Fix typing * Add test * Fix typing for Python 3.7 --- pyproject.toml | 1 + src/pyproject_fmt/formatter/project.py | 1 + src/pyproject_fmt/formatter/util.py | 23 ++++++++++++++--- tests/formatter/test_project.py | 34 ++++++++++++++++++++++++++ whitelist.txt | 2 ++ 5 files changed, 58 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index da73aba..bdbfb6a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ dynamic = [ "version", ] dependencies = [ + "natsort>=8.3.1", "packaging>=23.1", "tomlkit>=0.11.7", 'typing-extensions>=4.5; python_version < "3.8"', diff --git a/src/pyproject_fmt/formatter/project.py b/src/pyproject_fmt/formatter/project.py index bcefd5d..5d3dfa0 100644 --- a/src/pyproject_fmt/formatter/project.py +++ b/src/pyproject_fmt/formatter/project.py @@ -25,6 +25,7 @@ def fmt_project(parsed: TOMLDocument, conf: Config) -> None: sorted_array(cast(Optional[Array], project.get("keywords")), indent=conf.indent) sorted_array(cast(Optional[Array], project.get("dynamic")), indent=conf.indent) + sorted_array(cast(Optional[Array], project.get("classifiers")), indent=conf.indent, custom_sort="natsort") normalize_pep508_array(cast(Optional[Array], project.get("dependencies")), conf.indent) if "optional-dependencies" in project: diff --git a/src/pyproject_fmt/formatter/util.py b/src/pyproject_fmt/formatter/util.py index 5d35284..1216b77 100644 --- a/src/pyproject_fmt/formatter/util.py +++ b/src/pyproject_fmt/formatter/util.py @@ -3,8 +3,9 @@ import sys from collections import defaultdict from dataclasses import dataclass, field -from typing import Any, Callable, Sequence +from typing import Any, Callable, Iterable, Sequence, TypeVar +from natsort import natsorted from tomlkit.container import OutOfOrderTableProxy from tomlkit.items import ( AbstractTable, @@ -36,6 +37,14 @@ def __gt__(self, __other: Any) -> bool: # noqa: U101 ... +T = TypeVar("T") + + +class SortingFunction(Protocol[T]): + def __call__(self, __seq: Iterable[T], key: Callable[[T], SupportsDunderLT]) -> list[T]: # noqa: U100, U101 + ... + + def sort_inline_table(item: tuple[str, Any | Table]) -> str: key, value = item return f"{key}{'-'.join(value) if isinstance(value, Table) else ''}" @@ -75,7 +84,10 @@ class ArrayEntries: def sorted_array( - array: Array | None, indent: int, key: Callable[[ArrayEntries], str] = lambda e: str(e.text).lower() + array: Array | None, + indent: int, + key: Callable[[ArrayEntries], str] = lambda e: str(e.text).lower(), + custom_sort: str | None = None, ) -> None: if array is None: return @@ -94,7 +106,12 @@ def sorted_array( indent_text = " " * indent for start_entry in start: body.append(_ArrayItemGroup(indent=Whitespace(f"\n{indent_text}"), comment=start_entry)) - for element in sorted(entries, key=key): + sort_method: SortingFunction[ArrayEntries] + if custom_sort == "natsort": + sort_method = natsorted + else: + sort_method = sorted # type: ignore[assignment] + for element in sort_method(entries, key=key): if element.comments: com = " ".join(i.trivia.comment[1:].strip() for i in element.comments) comment = Comment(Trivia(comment=f" # {com}", trail="")) diff --git a/tests/formatter/test_project.py b/tests/formatter/test_project.py index 5e3e97c..9a36d8f 100644 --- a/tests/formatter/test_project.py +++ b/tests/formatter/test_project.py @@ -18,6 +18,40 @@ def test_project_name(fmt: Fmt, value: str) -> None: fmt(fmt_project, value, '[project]\nname="a-b"\n') +def test_project_classifiers(fmt: Fmt) -> None: + start = """ + [project] + classifiers = [ + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3 :: Only", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.11", + ] + """ + expected = """ + [project] + classifiers = [ + "License :: OSI Approved :: MIT License", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + ] + """ + fmt(fmt_project, start, expected) + + def test_project_dependencies(fmt: Fmt) -> None: start = '[project]\ndependencies=["pytest","pytest-cov",]' expected = '[project]\ndependencies=[\n "pytest",\n "pytest-cov",\n]\n' diff --git a/whitelist.txt b/whitelist.txt index e1097a0..8eff61c 100644 --- a/whitelist.txt +++ b/whitelist.txt @@ -11,6 +11,8 @@ intersphinx iread iwrite mkfifo +natsort +natsorted nitpicky pep508 py38