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

pre-commit: Modernize ruff, enable safe fixes and formatting, drop black and sort #102

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
# see https://github.com/pre-commit/action/#using-this-action
- name: pre-commit checks
uses: pre-commit/[email protected]
env:
# it's okay for github to commit to main/master
SKIP: no-commit-to-branch
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
16 changes: 5 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.254
hooks:
- id: ruff
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- id: ruff-format
29 changes: 28 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[project]
requires-python = ">= 3.8"

[tool.poetry]
name = "quiffen"
version = "2.0.13"
Expand Down Expand Up @@ -45,8 +48,32 @@ include_trailing_comma = true

[tool.ruff]
line-length = 88
target-version = "py38"

[tool.ruff.lint]
# see https://docs.astral.sh/ruff/configuration/#using-pyprojecttoml
select = [
# default Ruff checkers: E4, E7, E9, F
"E4",
"E7",
"E9",
# "F" contains autoflake, see https://github.com/astral-sh/ruff/issues/1647
"F", # pyflakes

"I", # isort

# TODO: add more rules. For example:
# "B", # flake8-bugbear
# "C4", # flake8-comprehensions
# "EXE", # flake8-executable
# "ICN", # flake8-import-conventions
# "ISC", # flake8-implicit-str-concat
# "PL", # pylint
# "RUF",
# "UP", # pyupgrade
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"] # Ignore unused imports in __init__.py

[tool.pyright]
Expand Down
1 change: 1 addition & 0 deletions quiffen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
and also to create a QIF structure and then output to either a QIF file, a CSV
of transaction data or a pandas DataFrame.
"""

from quiffen.core.account import Account, AccountType
from quiffen.core.base import Field
from quiffen.core.category import (
Expand Down
2 changes: 1 addition & 1 deletion tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_create_field():
field = Field(line_code="T", attr="test", type=str)
assert field.line_code == "T"
assert field.attr == "test"
assert field.type == str
assert field.type is str


def test_sorting_fields():
Expand Down
38 changes: 22 additions & 16 deletions tests/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,11 @@ def test_to_qif():
root = Category(name="Root")
child = Category(name="Child")
root.add_child(child)
assert root.to_qif() == ( # Should show both root and child
"!Type:Cat\nNRoot\nE\n^\n" "!Type:Cat\nNRoot:Child\nE\n"
assert (
root.to_qif()
== ( # Should show both root and child
"!Type:Cat\nNRoot\nE\n^\n" "!Type:Cat\nNRoot:Child\nE\n"
)
)
assert child.to_qif() == "!Type:Cat\nNRoot:Child\nE\n"

Expand Down Expand Up @@ -541,20 +544,23 @@ def test_to_qif_with_custom_fields():
child.custom_field_2 = Decimal("9238479")
child.custom_field_3 = datetime(2022, 1, 1, 0, 0, 0, 1)

assert root.to_qif() == ( # Should show both root and child
"!Type:Cat\n"
"NRoot\n"
"E\n"
"DT2022-01-01 00:00:00.000001\n"
"Y9238479\n"
"XCustom field 1\n"
"^\n"
"!Type:Cat\n"
"NRoot:Child\n"
"E\n"
"DT2022-01-01 00:00:00.000001\n"
"Y9238479\n"
"XCustom field 1\n"
assert (
root.to_qif()
== ( # Should show both root and child
"!Type:Cat\n"
"NRoot\n"
"E\n"
"DT2022-01-01 00:00:00.000001\n"
"Y9238479\n"
"XCustom field 1\n"
"^\n"
"!Type:Cat\n"
"NRoot:Child\n"
"E\n"
"DT2022-01-01 00:00:00.000001\n"
"Y9238479\n"
"XCustom field 1\n"
)
)
assert child.to_qif() == (
"!Type:Cat\n"
Expand Down
Loading