diff --git a/README.md b/README.md index 7d126a3..d41d92c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Formatter for pyproject.toml files. -This package enforces consistent formatting of pyproject.toml files, reducing merge request conflicts and saving time otherwise spent to format manually. It also contributes to a cleaner git history and more readable code; enhancing overall project organisation and maintainability. Experience a streamlined workflow, reduced errors, and improved code readability with `pyprojectsort`. +This package enforces consistent formatting of pyproject.toml files, reducing merge request conflicts and saving time otherwise spent on manual formatting. It also contributes to a cleaner git history and more readable code; enhancing overall project organisation and maintainability. Experience a streamlined workflow, reduced errors, and improved code readability with `pyprojectsort`. ## Features diff --git a/pyprojectsort/main.py b/pyprojectsort/main.py index 89c6054..3c955cc 100644 --- a/pyprojectsort/main.py +++ b/pyprojectsort/main.py @@ -56,11 +56,20 @@ def reformat_pyproject(pyproject: dict | list) -> dict: """Reformat pyproject toml file.""" if isinstance(pyproject, dict): return { - key: reformat_pyproject(value) - for key, value in sorted(pyproject.items(), key=lambda item: item[0]) + key: reformat_pyproject(value) for key, value in sorted(pyproject.items()) } if isinstance(pyproject, list): - return sorted(reformat_pyproject(item) for item in pyproject) + numbers = [] + strings = [] + dictionaries = [] + for i in pyproject: + if isinstance(i, float | int): + numbers.append(i) + elif isinstance(i, str): + strings.append(i) + else: + dictionaries.append(reformat_pyproject(i)) + return sorted(numbers) + sorted(strings) + dictionaries return pyproject diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index 905f255..8fc2a8c 100644 --- a/tests/unit/test_main.py +++ b/tests/unit/test_main.py @@ -73,7 +73,7 @@ def test_reformat_pyproject(): pyproject = { "project": {"name": "pyprojectsort"}, "build-system": {"name": "flit"}, - "tool.pylint": {"ignore": ["docs", "tests", "venv"]}, + "tool.pylint": {"ignore": ["docs", "tests", "venv", 1, 1.1, {}]}, "tool.black": {"line_length": 88}, } @@ -82,7 +82,7 @@ def test_reformat_pyproject(): "build-system": {"name": "flit"}, "project": {"name": "pyprojectsort"}, "tool.black": {"line_length": 88}, - "tool.pylint": {"ignore": ["docs", "tests", "venv"]}, + "tool.pylint": {"ignore": [1, 1.1, "docs", "tests", "venv", {}]}, } assert reformat_pyproject(pyproject) == sorted_pyproject