Skip to content

Commit

Permalink
Support tomlkit 0.11 (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored Aug 13, 2022
1 parent 9101096 commit 4e41ea1
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 63 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
19 changes: 11 additions & 8 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ concurrency:
jobs:
test:
name: test ${{ matrix.py }}
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
py:
- "3.11.0-rc.1"
- "3.10"
- "3.9"
- "3.8"
Expand All @@ -33,11 +34,13 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.py }}
- name: pick environment to run
- name: Pick environment to run
run: |
import os
with open(os.environ['GITHUB_ENV'], 'a') as file_handler:
file_handler.write('TOXENV=py${{matrix.py}}'.replace('.', ''))
import codecs; import os; import sys
env = "TOXENV=py{}{}\n".format(*sys.version_info[0:2])
print("Picked:\n{}for{}".format(env, sys.version))
with codecs.open(os.environ["GITHUB_ENV"], "a", "utf-8") as file_handler:
file_handler.write(env)
shell: python
- name: setup test suite
run: tox -vv --notest
Expand All @@ -46,7 +49,7 @@ jobs:

check:
name: tox env ${{ matrix.tox_env }}
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
Expand All @@ -70,7 +73,7 @@ jobs:
publish:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [check, test]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: setup python to build package
uses: actions/setup-python@v2
Expand All @@ -82,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@master
uses: pypa/gh-action-pypi-publish@v1.5.1
with:
skip_existing: true
user: __token__
Expand Down
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/bwhmather/ssort
rev: v0.11.5
rev: v0.11.6
hooks:
- id: ssort
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.2
rev: v2.37.3
hooks:
- id: pyupgrade
args: [ "--py37-plus" ]
Expand All @@ -33,21 +33,21 @@ repos:
rev: v1.12.1
hooks:
- id: blacken-docs
additional_dependencies: [ black==22.1.0 ]
additional_dependencies: [ black==22.6 ]
- repo: https://github.com/tox-dev/tox-ini-fmt
rev: "0.5.2"
hooks:
- id: tox-ini-fmt
args: [ "-p", "fix" ]
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==22.1.11
- flake8-comprehensions==3.8
- flake8-bugbear==22.7.1
- flake8-comprehensions==3.10
- flake8-pytest-style==1.6
- flake8-spellcheck==0.24
- flake8-unused-arguments==0.0.9
- flake8-noqa==1.2.1
- pep8-naming==0.12.1
- flake8-spellcheck==0.28
- flake8-unused-arguments==0.0.11
- flake8-noqa==1.2.8
- pep8-naming==0.13.1
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
changelog
=========

v0.3.3 (2022-08-12)
-------------------
* Support ``tomlkit>=0.11`` and CPython 3.11.

v0.3.2 (2022-03-01)
-------------------
* Fix invalid newline inside inline-table - by :user:`abravalheri`.
Expand Down
20 changes: 10 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
build-backend = "hatchling.build"
requires = ["hatchling>=0.14", "hatch-vcs>=0.1"]
requires = ["hatchling>=1.7", "hatch-vcs>=0.2"]

[project]
name = "pyproject_fmt"
Expand All @@ -15,20 +15,20 @@ authors = [{ name = "Bernat Gabor", email = "[email protected]" }]
requires-python = ">=3.7"
dependencies = [
"packaging>=21.3",
"tomlkit>=0.10",
'typing-extensions>=3.10;python_version<"3.8"',
"tomlkit>=0.11.3",
'typing-extensions>=4.3; python_version < "3.8"',
]
optional-dependencies.test = [
"covdefaults>=2",
"pytest>=7",
"covdefaults>=2.2",
"pytest>=7.1.2",
"pytest-cov>=3",
"pytest-mock>=3.7",
"pytest-mock>=3.8.2",
]
optional-dependencies.docs = [
"furo>=2022.1.2b11",
"sphinx>=4.4",
"sphinx-argparse-cli>=1.8",
"sphinx-autodoc-typehints>=1.17",
"furo>=2022.6.21",
"sphinx>=5.1.1",
"sphinx-argparse-cli>=1.10",
"sphinx-autodoc-typehints>=1.19.2",
"sphinx-copybutton>=0.5",
]
scripts.pyproject-fmt = "pyproject_fmt.__main__:run"
Expand Down
37 changes: 20 additions & 17 deletions src/pyproject_fmt/formatter/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Table,
Trivia,
Whitespace,
_ArrayItemGroup,
)

if sys.version_info >= (3, 8): # pragma: no cover (py38+)
Expand Down Expand Up @@ -70,26 +71,28 @@ def sorted_array(

entries: list[ArrayEntries] = []
start: list[Comment] = []
for entry in body:
if isinstance(entry, String):
entries.append(ArrayEntries(entry))
elif isinstance(entry, Comment):
(entries[-1].comments if len(entries) else start).append(entry)
for group in body:
for entry in group:
if isinstance(entry, String):
entries.append(ArrayEntries(entry))
elif isinstance(entry, Comment):
(entries[-1].comments if len(entries) else start).append(entry)

body.clear()
indent_text = " " * indent
for entry in start:
body.append(Whitespace(f"\n{indent_text}"))
entry.indent(0)
body.append(entry)
for entry in sorted(entries, key=key):
body.append(Whitespace(f"\n{indent_text}"))
body.append(entry.text)
body.append(Whitespace(","))
if entry.comments:
com = " ".join(i.trivia.comment[1:].strip() for i in entry.comments)
body.append(Comment(Trivia(comment=f" # {com}", trail="")))
body.append(Whitespace("\n"))
for start_entry in start:
body.append(_ArrayItemGroup(indent=Whitespace(f"\n{indent_text}"), comment=start_entry))
for element in sorted(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=""))
else:
comment = None
group = _ArrayItemGroup(
indent=Whitespace(f"\n{indent_text}"), value=element.text, comma=Whitespace(","), comment=comment
)
body.append(group)
body.append(_ArrayItemGroup(indent=Whitespace("\n")))


__all__ = [
Expand Down
16 changes: 14 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,20 @@ def no_color(diff: Any) -> Any:
return diff


@pytest.mark.parametrize("in_place", [True, False])
@pytest.mark.parametrize("cwd", [True, False])
@pytest.mark.parametrize(
"in_place",
[
True,
False,
],
)
@pytest.mark.parametrize(
"cwd",
[
True,
False,
],
)
@pytest.mark.parametrize(
("start", "outcome", "output"),
[
Expand Down
10 changes: 6 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ passenv =
PROGRAMDATA
skip_install = true
deps =
pre-commit>=2
pre-commit>=2.20
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")'
Expand All @@ -47,16 +47,16 @@ description = run type check on code base
setenv =
{tty:MYPY_FORCE_COLOR = 1}
deps =
mypy==0.931
mypy==0.971
commands =
mypy --strict --python-version 3.10 src tests

[testenv:readme]
description = check that the long description is valid
skip_install = true
deps =
build[virtualenv]>=0.7
twine>=3.7
build[virtualenv]>=0.8
twine>=4.0.1
commands =
python -m build --sdist --wheel -o {envtmpdir} .
twine check {envtmpdir}/*
Expand All @@ -80,5 +80,7 @@ commands =
python -c 'import sys; print(sys.executable)'

[flake8]
max-complexity = 22
max-line-length = 120
noqa-require-code = true
dictionaries = en_US,python,technical,django
12 changes: 0 additions & 12 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,22 @@ autoclass
autodoc
capsys
chdir
conf
dedent
deps
difflib
dunder
extlinks
fmt
formatter
fromfile
func
intersphinx
iread
iwrite
nitpicky
pathlib
pep508
py38
pygments
pyproject
raws
readouterr
req
sdist
skipif
textwrap
tmp
tofile
toml
tomlkit
typehints
util

0 comments on commit 4e41ea1

Please sign in to comment.