Skip to content

Commit

Permalink
Do not crash on out of order tables (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat committed May 9, 2023
1 parent fb72ada commit c36e2db
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
hooks:
- id: ssort
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.2
rev: v3.4.0
hooks:
- id: pyupgrade
args: [ "--py37-plus" ]
Expand All @@ -43,6 +43,7 @@ repos:
rev: "0.11.1"
hooks:
- id: pyproject-fmt
additional_dependencies: [ tox>=4.5.1 ]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
build-backend = "hatchling.build"
requires = [
"hatch-vcs>=0.3",
"hatchling>=1.14",
"hatchling>=1.14.1",
]

[project]
Expand All @@ -26,19 +26,20 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dynamic = [
"version",
]
dependencies = [
"natsort>=8.3.1",
"packaging>=23.1",
"tomlkit>=0.11.7",
"tomlkit>=0.11.8",
'typing-extensions>=4.5; python_version < "3.8"',
]
optional-dependencies.docs = [
"furo>=2023.3.27",
"sphinx>=6.1.3",
"sphinx>=6.2.1",
"sphinx-argparse-cli>=1.11",
"sphinx-autodoc-typehints!=1.23.4,>=1.23",
"sphinx-copybutton>=0.5.2",
Expand Down
1 change: 1 addition & 0 deletions src/pyproject_fmt/formatter/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def fmt_tools(parsed: TOMLDocument, conf: Config) -> None: # noqa: U100
table = tools[tool]
ensure_newline_at_end(cast(Table, table))
order = [
"poetry",
"setuptools",
"setuptools_scm",
"hatch",
Expand Down
2 changes: 2 additions & 0 deletions src/pyproject_fmt/formatter/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def ensure_newline_at_end(body: Table) -> None:
# coverage has a bug on python < 3.10, seeing this line as uncovered
# https://github.com/nedbat/coveragepy/issues/1480
break
if isinstance(body, OutOfOrderTableProxy):
return
whitespace = Whitespace("\n")
insert_body = content.value.body
if insert_body and isinstance(insert_body[-1][1], Whitespace):
Expand Down
8 changes: 8 additions & 0 deletions tests/formatter/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

def test_tools_ordering(fmt: Fmt) -> None:
content = """
[tool.poetry]
name = "a"
[tool.coverage]
a = 0
[tool.poetry.scripts]
version = "1"
[tool.pytest]
a = 0
[tool.black]
Expand All @@ -24,6 +28,10 @@ def test_tools_ordering(fmt: Fmt) -> None:
"""
expected = """
[tool.poetry]
name = "a"
[tool.poetry.scripts]
version = "1"
[tool.setuptools]
a.b = 0
Expand Down

0 comments on commit c36e2db

Please sign in to comment.