diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 28052a5..0000000 --- a/.flake8 +++ /dev/null @@ -1,16 +0,0 @@ -[flake8] -exclude = .tox, .git, __pycache__, .cache, build, dist, *.pyc, *.egg-info, .eggs -# Error codes: -# - https://flake8.pycqa.org/en/latest/user/error-codes.html -# - https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes -# - https://github.com/PyCQA/flake8-bugbear#list-of-warnings -# -# E203: whitespace before `,`, `;` or `:` -# E402: module level import not at top of file -# E501: line too long -# W503: line break before binary operator -ignore = - E203, - E402, - E501, - W503 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ad50ca7..9f8d1c1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,26 +1,10 @@ repos: -- repo: https://github.com/asottile/pyupgrade - rev: v3.16.0 +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.9 hooks: - - id: pyupgrade - args: [--py38-plus] -- repo: https://github.com/asottile/reorder_python_imports - rev: v3.13.0 - hooks: - - id: reorder-python-imports - args: [--py38-plus] -- repo: https://github.com/psf/black - rev: "23.12.1" - hooks: - - id: black - args: [--safe, --quiet] -- repo: https://github.com/pycqa/flake8 - rev: "7.1.0" - hooks: - - id: flake8 - additional_dependencies: - - flake8-bugbear==24.4.26 - - flake8-comprehensions==3.14.0 + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format - repo: https://github.com/igorshubovych/markdownlint-cli rev: v0.41.0 hooks: diff --git a/agentarchives/archivesspace/__init__.py b/agentarchives/archivesspace/__init__.py index 64d7a2e..421945b 100644 --- a/agentarchives/archivesspace/__init__.py +++ b/agentarchives/archivesspace/__init__.py @@ -1 +1 @@ -from .client import * # noqa +from .client import * diff --git a/agentarchives/archivesspace/client.py b/agentarchives/archivesspace/client.py index d830bf5..c9d1748 100644 --- a/agentarchives/archivesspace/client.py +++ b/agentarchives/archivesspace/client.py @@ -127,9 +127,7 @@ def _login(self): output = response.json() except Exception: raise ArchivesSpaceError( - "ArchivesSpace server responded with status {}, but returned a non-JSON document".format( - response.status_code - ) + f"ArchivesSpace server responded with status {response.status_code}, but returned a non-JSON document" ) if "error" in output: @@ -174,9 +172,7 @@ def _request(self, method, url, params, expected_response, data=None): output = response.json() except Exception: raise ArchivesSpaceError( - "ArchivesSpace server responded with status {}, but returned a non-JSON document".format( - response.status_code - ) + f"ArchivesSpace server responded with status {response.status_code}, but returned a non-JSON document" ) if "error" in output: diff --git a/agentarchives/archivists_toolkit/__init__.py b/agentarchives/archivists_toolkit/__init__.py index 64d7a2e..421945b 100644 --- a/agentarchives/archivists_toolkit/__init__.py +++ b/agentarchives/archivists_toolkit/__init__.py @@ -1 +1 @@ -from .client import * # noqa +from .client import * diff --git a/agentarchives/archivists_toolkit/client.py b/agentarchives/archivists_toolkit/client.py index cfa598a..86c25db 100644 --- a/agentarchives/archivists_toolkit/client.py +++ b/agentarchives/archivists_toolkit/client.py @@ -66,9 +66,7 @@ def edit_record(self, new_record): record_type = self.resource_type(record_id) if record_type is None: raise ArchivistsToolkitError( - "Could not determine type for record with ID {}; not in database?".format( - record_id - ) + f"Could not determine type for record with ID {record_id}; not in database?" ) clause = [] @@ -413,9 +411,7 @@ def find_collection_ids( params = tuple(params) - sql = "SELECT resourceId FROM Resources WHERE ({}) AND resourceLevel in ('recordgrp', 'collection') ORDER BY title".format( - clause - ) + sql = f"SELECT resourceId FROM Resources WHERE ({clause}) AND resourceLevel in ('recordgrp', 'collection') ORDER BY title" if page is not None: start = (page - 1) * page_size diff --git a/agentarchives/atom/__init__.py b/agentarchives/atom/__init__.py index 64d7a2e..421945b 100644 --- a/agentarchives/atom/__init__.py +++ b/agentarchives/atom/__init__.py @@ -1 +1 @@ -from .client import * # noqa +from .client import * diff --git a/agentarchives/atom/client.py b/agentarchives/atom/client.py index 4d52f7d..ea38446 100644 --- a/agentarchives/atom/client.py +++ b/agentarchives/atom/client.py @@ -26,9 +26,7 @@ class AuthenticationError(AtomError): class CommunicationError(AtomError): def __init__(self, status_code, response): - message = "AtoM server responded with status code {} (URL: {})".format( - status_code, response.url - ) + message = f"AtoM server responded with status code {status_code} (URL: {response.url})" self.response = response super().__init__(message) @@ -70,9 +68,7 @@ def _request(self, method, url, params, expected_response, data=None): output = response.json() except Exception: raise AtomError( - "Atom server responded with status {}, but returned a non-JSON document".format( - response.status_code - ) + f"Atom server responded with status {response.status_code}, but returned a non-JSON document" ) if "error" in output: @@ -239,7 +235,7 @@ def edit_record(self, new_record): updated_date = {} # Only single dates are currently supported - if "dates" in new_record and type(new_record["dates"]) is list: + if "dates" in new_record and isinstance(new_record["dates"], list): new_record["dates"] = new_record["dates"][0] # Map agentarchives date specification to AtoM specification diff --git a/pyproject.toml b/pyproject.toml index bb95493..8996687 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,6 +60,7 @@ dev = [ "pytest-cov", "pytest-mock", "pytest", + "ruff", "vcrpy", ] @@ -67,6 +68,28 @@ dev = [ version = {attr = "agentarchives.__version__"} readme = {file = ["README.md"], content-type = "text/markdown"} +[tool.ruff.lint] +# Rule reference: https://docs.astral.sh/ruff/rules/ +select = [ + "B", + "C4", + "E", + "F", + "I", + "UP", + "W", +] +ignore = [ + "B904", + "E501", +] + +[tool.ruff.lint.per-file-ignores] +"agentarchives/{archivesspace,archivists_toolkit,atom}/__init__.py" = ["F403"] + +[tool.ruff.lint.isort] +force-single-line = true + [tool.pytest.ini_options] python_files = [ "test_*.py", diff --git a/requirements-dev.txt b/requirements-dev.txt index b40c971..f1d0398 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -55,6 +55,8 @@ pyyaml==6.0.1 # via vcrpy requests==2.32.3 # via agentarchives (pyproject.toml) +ruff==0.4.9 + # via agentarchives (pyproject.toml) tomli==2.0.1 # via # build diff --git a/tests/test_archivesspace_client.py b/tests/test_archivesspace_client.py index 9d5b3ef..30fc127 100644 --- a/tests/test_archivesspace_client.py +++ b/tests/test_archivesspace_client.py @@ -9,7 +9,6 @@ from agentarchives.archivesspace.client import ArchivesSpaceError from agentarchives.archivesspace.client import CommunicationError - THIS_DIR = os.path.dirname(os.path.abspath(__file__)) AUTH = {"host": "http://localhost:8089", "user": "admin", "passwd": "admin"}