Skip to content

Commit

Permalink
Use ruff and use aiida-core ruff config
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Nov 27, 2024
1 parent a56887f commit c2e6298
Show file tree
Hide file tree
Showing 47 changed files with 376 additions and 483 deletions.
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
59 changes: 24 additions & 35 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.5.0
hooks:
- id: isort
- id: ruff-format
exclude: &exclude_ruff >
(?x)^(

- 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
1 change: 0 additions & 1 deletion examples/process_helloworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class HelloWorld(plumpy.Process):

@classmethod
def define(cls, spec):
super().define(spec)
Expand Down
1 change: 0 additions & 1 deletion examples/process_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import tempfile

import kiwipy

import plumpy


Expand Down
10 changes: 3 additions & 7 deletions examples/process_wait_and_resume.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
from kiwipy import rmq

import plumpy
from kiwipy import rmq


class WaitForResumeProc(plumpy.Process):

def run(self):
print(f'Now I am running: {self.state}')
return plumpy.Wait(self.after_resume_and_exec)
Expand All @@ -15,12 +13,10 @@ def after_resume_and_exec(self):


kwargs = {
'connection_params': {
'url': 'amqp://guest:[email protected]:5672/'
},
'connection_params': {'url': 'amqp://guest:[email protected]:5672/'},
'message_exchange': 'WaitForResume.uuid-0',
'task_exchange': 'WaitForResume.uuid-0',
'task_queue': 'WaitForResume.uuid-0'
'task_queue': 'WaitForResume.uuid-0',
}

if __name__ == '__main__':
Expand Down
1 change: 0 additions & 1 deletion examples/workchain_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class AddAndMulWF(plumpy.WorkChain):

@classmethod
def define(cls, spec):
super().define(spec)
Expand Down
35 changes: 30 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,36 @@ exclude = [
line-length = 120
fail-on-change = true

[tool.isort]
force_sort_within_sections = true
include_trailing_comma = true
line_length = 120
multi_line_output = 3
[tool.ruff]
line-length = 120

[tool.ruff.format]
quote-style = 'single'

[tool.ruff.lint]
ignore = [
'F403', # Star imports unable to detect undefined names
'F405', # Import may be undefined or defined from star imports
'PLR0911', # Too many return statements
'PLR0912', # Too many branches
'PLR0913', # Too many arguments in function definition
'PLR0915', # Too many statements
'PLR2004', # Magic value used in comparison
'RUF005', # Consider iterable unpacking instead of concatenation
'RUF012' # Mutable class attributes should be annotated with `typing.ClassVar`
]
select = [
'E', # pydocstyle
'W', # pydocstyle
'F', # pyflakes
'I', # isort
'N', # pep8-naming
'PLC', # pylint-convention
'PLE', # pylint-error
'PLR', # pylint-refactor
'PLW', # pylint-warning
'RUF' # ruff
]

[tool.mypy]
show_error_codes = true
Expand Down
18 changes: 14 additions & 4 deletions src/plumpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@
from .workchains import *

__all__ = (
events.__all__ + exceptions.__all__ + processes.__all__ + utils.__all__ + futures.__all__ + mixins.__all__ +
persistence.__all__ + communications.__all__ + process_comms.__all__ + process_listener.__all__ +
workchains.__all__ + loaders.__all__ + ports.__all__ + process_states.__all__
events.__all__
+ exceptions.__all__
+ processes.__all__
+ utils.__all__
+ futures.__all__
+ mixins.__all__
+ persistence.__all__
+ communications.__all__
+ process_comms.__all__
+ process_listener.__all__
+ workchains.__all__
+ loaders.__all__
+ ports.__all__
+ process_states.__all__
)


Expand All @@ -32,7 +43,6 @@
# https://docs.python.org/3.1/library/logging.html#library-config
# for more details
class NullHandler(logging.Handler):

def emit(self, record: logging.LogRecord) -> None:
pass

Expand Down
2 changes: 1 addition & 1 deletion src/plumpy/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from .state_machine import *
from .utils import *

__all__ = (state_machine.__all__ + utils.__all__)
__all__ = state_machine.__all__ + utils.__all__
Loading

0 comments on commit c2e6298

Please sign in to comment.