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

Migrate formatter and linter to ruff #72

Merged
merged 3 commits into from
Nov 20, 2024
Merged
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
66 changes: 33 additions & 33 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
name: cd

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+*

jobs:

validate-release-tag:
validate-release-tag:

if: github.repository == 'aiidateam/aiida-restapi'
runs-on: ubuntu-latest
if: github.repository == 'aiidateam/aiida-restapi'
runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v2
steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Validate the tag version against the package version
run: python .github/workflows/validate_release_tag.py $GITHUB_REF
- name: Validate the tag version against the package version
run: python .github/workflows/validate_release_tag.py $GITHUB_REF

publish:
publish:

name: Publish to PyPI
needs: [validate-release-tag]
runs-on: ubuntu-latest
name: Publish to PyPI
needs: [validate-release-tag]
runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v2
steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Install flit
run: pip install flit~=3.4
- name: Install flit
run: pip install flit~=3.4

- name: Build and publish
run: flit publish
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.pypi_token }}
- name: Build and publish
run: flit publish
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.pypi_token }}
114 changes: 57 additions & 57 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,73 @@ on: [push, pull_request]

jobs:

pre-commit:
pre-commit:

runs-on: ubuntu-latest
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: '3.9'

- uses: pre-commit/[email protected]
- uses: pre-commit/[email protected]

tests:
tests:

runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']

services:
postgres:
image: postgres:latest
env:
POSTGRES_DB: test_db
POSTGRES_PASSWORD: ''
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
rabbitmq:
image: rabbitmq:latest
ports:
- 5672:5672
services:
postgres:
image: postgres:latest
env:
POSTGRES_DB: test_db
POSTGRES_PASSWORD: ''
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
rabbitmq:
image: rabbitmq:latest
ports:
- 5672:5672

steps:
- uses: actions/checkout@v2
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
pip install --upgrade pip
pip install -e .[testing,auth]
- name: Install Python dependencies
run: |
pip install --upgrade pip
pip install -e .[testing,auth]
- name: Run test suite
env:
- name: Run test suite
env:
# show timings of tests
PYTEST_ADDOPTS: "--durations=0"
AIIDA_WARN_v3: true
run: pytest --cov aiida_restapi --cov-report=xml
PYTEST_ADDOPTS: --durations=0
AIIDA_WARN_v3: true
run: pytest --cov aiida_restapi --cov-report=xml

- name: Upload to Codecov
if: matrix.python-version == 3.8
uses: codecov/codecov-action@v4
with:
name: pytests
flags: pytests
file: ./coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
- name: Upload to Codecov
if: matrix.python-version == 3.8
uses: codecov/codecov-action@v4
with:
name: pytests
flags: pytests
file: ./coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
26 changes: 10 additions & 16 deletions .github/workflows/validate_release_tag.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""Validate that the version in the tag label matches the version of the package."""

import argparse
import ast
from pathlib import Path
Expand All @@ -13,33 +13,27 @@ def get_version_from_module(content: str) -> str:
try:
module = ast.parse(content)
except SyntaxError as exception:
raise IOError("Unable to parse module.") from exception
raise IOError('Unable to parse module.') from exception

try:
return next(
ast.literal_eval(statement.value)
for statement in module.body
if isinstance(statement, ast.Assign)
for target in statement.targets
if isinstance(target, ast.Name) and target.id == "__version__"
if isinstance(target, ast.Name) and target.id == '__version__'
)
except StopIteration as exception:
raise IOError(
"Unable to find the `__version__` attribute in the module."
) from exception
raise IOError('Unable to find the `__version__` attribute in the module.') from exception


if __name__ == "__main__":
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("GITHUB_REF", help="The GITHUB_REF environmental variable")
parser.add_argument('GITHUB_REF', help='The GITHUB_REF environmental variable')
args = parser.parse_args()
tag_prefix = "refs/tags/v"
assert args.GITHUB_REF.startswith(
tag_prefix
), f'GITHUB_REF should start with "{tag_prefix}": {args.GITHUB_REF}'
tag_prefix = 'refs/tags/v'
assert args.GITHUB_REF.startswith(tag_prefix), f'GITHUB_REF should start with "{tag_prefix}": {args.GITHUB_REF}'
tag_version = args.GITHUB_REF.removeprefix(tag_prefix)
package_version = get_version_from_module(
Path("aiida_restapi/__init__.py").read_text(encoding="utf-8")
)
error_message = f"The tag version `{tag_version}` is different from the package version `{package_version}`"
package_version = get_version_from_module(Path('aiida_restapi/__init__.py').read_text(encoding='utf-8'))
error_message = f'The tag version `{tag_version}` is different from the package version `{package_version}`'
assert tag_version == package_version, error_message
121 changes: 68 additions & 53 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,58 +1,73 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: end-of-file-fixer
- id: fix-encoding-pragma
- id: mixed-line-ending
- id: trailing-whitespace
- id: check-json
- id: check-yaml
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-merge-conflict
- id: check-yaml
- id: double-quote-string-fixer
- id: end-of-file-fixer
exclude: &exclude_pre_commit_hooks >
(?x)^(
tests/.*(?<!\.py)$|
docs/source/.+\.aiida/repo/.+|
CHANGELOG.md|
)$
- id: fix-encoding-pragma
args: [--remove]
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
exclude: *exclude_pre_commit_hooks

- repo: https://github.com/pycqa/isort
rev: '5.12.0'
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: mypy
additional_dependencies:
- pydantic~=2.0
- types-python-dateutil
- types-docutils
exclude: >
(?x)^(
docs/.*|
examples/.*|
tests/.*|
conftest.py
)$

- repo: https://github.com/psf/black
rev: '22.10.0'
hooks:
- id: black
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.6
hooks:
- id: check-github-workflows

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: mypy
additional_dependencies:
- pydantic~=2.0
- types-python-dateutil
- types-docutils
exclude: >
(?x)^(
docs/.*|
examples/.*|
tests/.*|
conftest.py
)$
- repo: https://github.com/ikamensh/flynt/
rev: 1.0.1
hooks:
- id: flynt
args: [--line-length=120, --fail-on-change]

- repo: https://github.com/PyCQA/pylint
rev: v3.2.2
hooks:
- id: pylint
additional_dependencies:
- aiida-core~=2.0
- fastapi~=0.115.5
- uvicorn[standard]~=0.19.0
- pydantic~=2.0
- graphene~=3.0
- lark
- python-dateutil~=2.0
- python-jose
- python-multipart
- passlib
- pytest~=3.6,<5.0.0
- sphinx<4
exclude: >
(?x)^(
docs/.*|
)$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
hooks:
- id: ruff-format
exclude: &exclude_ruff >
(?x)^(
docs/source/topics/processes/include/snippets/functions/parse_docstring_expose_ipython.py|
docs/source/topics/processes/include/snippets/functions/signature_plain_python_call_illegal.py|
)$
- id: ruff
exclude: *exclude_ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.13.0
hooks:
- id: pretty-format-toml
args: [--autofix]
- id: pretty-format-yaml
args: [--autofix]
exclude: >-
(?x)^(
tests/.*|
environment.yml|
)$
5 changes: 2 additions & 3 deletions aiida_restapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
"""AiiDA REST API for data queries and workflow managment."""

__version__ = "0.1.0a1"
__version__ = '0.1.0a1'

from .main import app
from .main import app # noqa: F401
Loading
Loading