Skip to content

Commit

Permalink
Migrate formatting to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
kieran-ryan committed Jan 2, 2024
1 parent 9622b60 commit c7ceef2
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
python -m pip install --upgrade pip
pip install --requirement requirements-dev.txt
- name: Lint Python code
run: ruff .
run: ruff check
- name: Check Python formatting
run: black . --check
run: ruff format --check
- name: Check pyproject.toml formatting
run: pyprojectsort --check
- name: Check cyclomatic complexity
Expand Down
21 changes: 3 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,17 @@ repos:
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: local
hooks:
- id: removestar
name: removestar
entry: removestar
language: system
types: [python]
args: [-i, pysamplelib]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.275"
rev: v0.1.9
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
hooks:
- id: blacken-docs
- id: ruff-format
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
hooks:
- id: pyupgrade
args: [ --py310-plus ]
args: [--py37-plus]
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"recommendations": [
"charliermarsh.ruff",
"editorconfig.editorconfig",
"ms-python.black-formatter",
"ms-python.python"
]
}
12 changes: 9 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"files.trimTrailingWhitespace": true,
"files.autoSave": "onFocusChange",
"files.exclude": {
".pytest_cache": true,
".ruff_cache": true
},
"files.trimTrailingWhitespace": true,
"git.autofetch": true,
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features",
Expand All @@ -11,7 +15,9 @@
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"search.exclude": {
"dist": true
}
}
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ A template repository for creating Python packages.
- `README.md` overview documentation
- Tool configuration:
- [editorconfig](https://editorconfig.org) - universal editor configuration
- [ruff](https://github.com/charliermarsh/ruff) - linting
- [ruff](https://github.com/charliermarsh/ruff) - linting and formatting
- [perflint](https://github.com/tonybaloney/perflint) - linting performance anti-patterns
- [mypy](https://mypy.readthedocs.io) - type checking
- [bandit](https://bandit.readthedocs.io/en/latest/) - vulnerability detection
- [black](https://black.readthedocs.io/en/stable/) - code style formatting
- [blacken-docs](https://pypi.org/project/blacken-docs/) - code style formatting in docs
- [pyupgrade](https://github.com/asottile/pyupgrade) - latest syntax upgrades
- [radon](https://pypi.org/project/radon/) - code quality
- [removestar](https://github.com/asmeurer/removestar) - automated removal of wildcard imports (*)
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ exclude_dirs = [
"venv",
]

[tool.black]
preview = true

[tool.coverage.html]
directory = "docs/coverage"

Expand Down Expand Up @@ -95,11 +92,13 @@ total_average = true
ignore = [
"ANN",
"ARG",
"COM812",
"D203",
"D213",
"DTZ005",
"G004",
"INP001",
"ISC001",
"S101",
"T201",
]
Expand Down
2 changes: 1 addition & 1 deletion pysamplelib/fizzbuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)


def fizzbuzz(number: int | float, keyword_mapping: dict[int, str] | None = None) -> str:
def fizzbuzz(number: float, keyword_mapping: dict[int, str] | None = None) -> str:
"""Run FizzBuzz against a number.
Returns the number itself, unless it is divisible by any of the keys
Expand Down
4 changes: 1 addition & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
--requirement requirements-docs.txt
--requirement requirements-test.txt
bandit==1.7.5
black==23.3.0
blacken-docs==1.14.0
mypy==0.971
perflint==0.7.3
pre-commit==3.3.3
pyprojectsort==0.3.0
pyupgrade==3.7.0
radon[toml]==6.0.1
removestar==1.3.1
ruff==0.0.275
ruff==0.1.9

0 comments on commit c7ceef2

Please sign in to comment.