Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to sort particular keys first in output #53

Merged
merged 6 commits into from
Mar 16, 2023

Conversation

jonathangreen
Copy link
Contributor

This PR builds on #52, so that one should go in first.

This should resolve #42 by allowing a new configuration option sort_first, and adds this option to the new overrides configuration defined in #52.

For the case mentioned in #42, a configuration like this can be used:

[tool.tomlsort]
overrides."tool.poetry.dependencies".first = ["python"]

Copy link
Owner

@pappasam pappasam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@pappasam pappasam merged commit 91bfb56 into pappasam:main Mar 16, 2023
@pappasam
Copy link
Owner

@jonathangreen out of curiosity, how is the command line option supposed to work? I've tried testing the latest main on this repository's pyproject.toml:

toml-sort --all --sort-first tool.poetry.dev-dependencies.tox pyproject.toml

I'd expect this:

[tool.poetry.dev-dependencies]
tox = "^3.25.1"
black = ">=22.6.0"
docformatter = ">=1.5.1"
isort = "^5.11.4"
m2r2 = ">=0.3.2"
mypy = ">=0.961"
pre-commit = ">=2.19.0"
pylint = ">=2.13.9"
pytest = ">=7.1.2"
pytest-cov = ">=3.0.0"
sphinx = "^4.4.0"
sphinx-argparse = ">=0.3.1"
sphinx-rtd-theme = "^1.0.0"
tox-asdf = "^0.1.0"

But I get this:

[tool.poetry.dev-dependencies]
black = ">=22.6.0"
docformatter = ">=1.5.1"
isort = "^5.11.4"
m2r2 = ">=0.3.2"
mypy = ">=0.961"
pre-commit = ">=2.19.0"
pylint = ">=2.13.9"
pytest = ">=7.1.2"
pytest-cov = ">=3.0.0"
sphinx = "^4.4.0"
sphinx-argparse = ">=0.3.1"
sphinx-rtd-theme = "^1.0.0"
tox = "^3.25.1"
tox-asdf = "^0.1.0"

@jonathangreen
Copy link
Contributor Author

jonathangreen commented Mar 16, 2023

I decided to add the cli switch for the sort_first option right before submitting this PR. I had originally intended it to be configuration only, like the overrides are.

Maybe I should have added some more detail to the description of that flag for cli, or refactor it's behavior to be more flexible.

You can configure the behavior you are expecting from the pyproject.toml, but the cli switch only applies at the top level of keys for sorting.

So you can reorder the tool section but not the tool.poetry.dev-dependencies.tox from the cli switches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python as first item in "tool.poetry.dependencies"
2 participants