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

Use Ruff for linting #289

Merged
merged 10 commits into from
Dec 2, 2024
Merged
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
run: pip install -e .[tests]

- name: Run pytest
run: pytest -sv --cov=plumpy test
run: pytest -s --cov=plumpy tests

- name: Create xml coverage
run: coverage xml
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: continuous-integration
name: ci

on: [push, pull_request]

Expand All @@ -9,10 +9,10 @@ jobs:
steps:
- uses: actions/checkout@v2

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

- name: Install Python dependencies
run: pip install -e .[pre-commit]
Expand All @@ -26,6 +26,7 @@ jobs:
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
fail-fast: false

services:
rabbitmq:
Expand All @@ -42,10 +43,10 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install python dependencies
run: pip install -e .[tests]
run: pip install .[tests]

- name: Run pytest
run: pytest -sv --cov=plumpy test
run: pytest -s --cov=plumpy tests/

- name: Create xml coverage
run: coverage xml
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/validate_release_tag.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- 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 @@ -17,8 +18,11 @@ def get_version_from_module(content: str) -> str:

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__'
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__'
)
except StopIteration as exception:
raise IOError('Unable to find the `__version__` attribute in the module.') from exception
Expand Down
61 changes: 25 additions & 36 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,46 +1,35 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: fix-encoding-pragma
- id: mixed-line-ending
- id: trailing-whitespace
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: fix-encoding-pragma
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/ikamensh/flynt/
rev: '0.77'
- repo: https://github.com/ikamensh/flynt/
rev: 1.0.1
hooks:
- id: flynt
- id: flynt
args: [--line-length=120, --fail-on-change]

- repo: https://github.com/pycqa/isort
rev: '5.12.0'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
hooks:
- id: isort
- id: ruff-format
exclude: &exclude_ruff >
(?x)^(
tests/.*|
)$

- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.32.0
hooks:
- id: yapf
name: yapf
types: [python]
args: ['-i']
additional_dependencies: ['toml']

- repo: https://github.com/PyCQA/pylint
rev: v2.15.8
hooks:
- id: pylint
language: system
exclude: >
(?x)^(
docs/source/conf.py|
test/.*|
)$
- id: ruff
exclude: *exclude_ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

- repo: local
- repo: local
hooks:
- id: mypy
- id: mypy
name: mypy
entry: mypy
args: [--config-file=pyproject.toml]
Expand All @@ -49,6 +38,6 @@ repos:
require_serial: true
pass_filenames: true
files: >-
(?x)^(
src/.*py|
)$
(?x)^(
src/.*py|
)$
32 changes: 21 additions & 11 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

import filecmp
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path

import plumpy

Expand All @@ -32,8 +30,12 @@
master_doc = 'index'
language = None
extensions = [
'myst_nb', 'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.viewcode', 'sphinx.ext.intersphinx',
'IPython.sphinxext.ipython_console_highlighting'
'myst_nb',
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.viewcode',
'sphinx.ext.intersphinx',
'IPython.sphinxext.ipython_console_highlighting',
]

# List of patterns, relative to source directory, that match files and
Expand All @@ -46,14 +48,14 @@

intersphinx_mapping = {
'python': ('https://docs.python.org/3.8', None),
'kiwipy': ('https://kiwipy.readthedocs.io/en/latest/', None)
'kiwipy': ('https://kiwipy.readthedocs.io/en/latest/', None),
}

myst_enable_extensions = ['colon_fence', 'deflist', 'html_image', 'smartquotes', 'substitution']
myst_url_schemes = ('http', 'https', 'mailto')
myst_substitutions = {
'rabbitmq': '[RabbitMQ](https://www.rabbitmq.com/)',
'kiwipy': '[kiwipy](https://kiwipy.readthedocs.io)'
'kiwipy': '[kiwipy](https://kiwipy.readthedocs.io)',
}
jupyter_execute_notebooks = 'cache'
execution_show_tb = 'READTHEDOCS' in os.environ
Expand Down Expand Up @@ -84,7 +86,7 @@
'use_issues_button': True,
'path_to_docs': 'docs',
'use_edit_page_button': True,
'extra_navbar': ''
'extra_navbar': '',
}

# API Documentation
Expand Down Expand Up @@ -112,9 +114,17 @@ def run_apidoc(app):
# this ensures that document rebuilds are not triggered every time (due to change in file mtime)
with tempfile.TemporaryDirectory() as tmpdirname:
options = [
'-o', tmpdirname,
str(package_dir), '--private', '--force', '--module-first', '--separate', '--no-toc', '--maxdepth', '4',
'-q'
'-o',
tmpdirname,
str(package_dir),
'--private',
'--force',
'--module-first',
'--separate',
'--no-toc',
'--maxdepth',
'4',
'-q',
]

os.environ['SPHINX_APIDOC_OPTIONS'] = 'members,special-members,private-members,undoc-members,show-inheritance'
Expand Down
Loading