Skip to content

Commit

Permalink
Update linters, switch black to ruff format (#225)
Browse files Browse the repository at this point in the history
* Bump ruff to v0.1.1
* Enable ruff autofixes through pre-commit
* Use ruff format instead of black
* Add new hooks from pre-commit-hooks
* Add badges to README
* Add check for large files
  • Loading branch information
danielhollas authored Oct 22, 2023
1 parent 54081f8 commit 8de5700
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 78 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,14 @@ on:
tags:
- "v*"
pull_request:
branches:
- "*"

jobs:

pre-commit:
runs-on: ubuntu-latest
steps:
- name: Check out app
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
cache-dependency-path: |
**/setup.cfg
**/pyproject.toml
uses: actions/checkout@v4
- name: Run pre-commit
uses: pre-commit/[email protected]

Expand Down Expand Up @@ -60,7 +50,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Check out app
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
Expand Down
24 changes: 18 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
default_language_version:
# all hooks should run with python 3.6+
python: python3
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+
- id: no-commit-to-branch
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-added-large-files
args: ['--maxkb=500', '--enforce-all']
- id: end-of-file-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: check-yaml
- id: check-toml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.270
rev: v0.1.1
hooks:
- id: ruff
args: [--show-source]
args: [--show-source, --fix]
- id: ruff-format

- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![CI](https://github.com/ispg-group/aiidalab-ispg/workflows/CI/badge.svg?branch=main&event=push)](https://github.com/ispg-group/aiidalab-ispg/actions?query=workflow%3ACI)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

# AiiDAlab ISPG applications

ATMOSPEC - ab initio workflow for UV/VIS spectroscopy of organic molecules.
Expand Down
2 changes: 1 addition & 1 deletion aiidalab_ispg/app/experimental_spectra/acrolein.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
- "G.K. Moortgat"
- "K. Wirtz"
title: "A study of the photolysis and OH-initiated oxidation of acrolein and trans-crotonaldehyde"
journal: "J. Phys. Chem. A"
journal: "J. Phys. Chem. A"
issue: "106"
pages: "2526-2537"
year: "2002"
Expand Down
4 changes: 2 additions & 2 deletions aiidalab_ispg/app/experimental_spectra/glycolaldehyde.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
molecule: glycolaldehyde
molecule: glycolaldehyde
smiles: "O=CCO"
source_file: glycolaldehyde.txt
metadata:
Expand All @@ -11,7 +11,7 @@ metadata:
- "Tyndall, G.S."
- "Orlando, J.J."
title: "The Atmospheric Chemistry of Glycolaldehyde"
journal: "J. Atmos. Chem."
journal: "J. Atmos. Chem."
issue: "39"
pages: "171-189"
year: "2001"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ smiles: "COO"
source_file: methylhydroperoxide.txt
y_axis_scaling: 1e-20
metadata:
description: 'H3OOH absorption spectrum from IUPAC97, originally from Vaghjiani and Ravishankara (1989)'
description: 'H3OOH absorption spectrum from IUPAC97, originally from Vaghjiani and Ravishankara (1989)'
license: '?'
source:
db_name: 'Andrew`s data'
14 changes: 7 additions & 7 deletions aiidalab_ispg/app/qeapp/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class WorkChainSelector(ipw.HBox):

BASE_FMT_WORKCHAIN = "{wc.pk:6}{wc.ctime:>10}\t{wc.state:<16}"

BASE_FIELDS = [("pk", int), ("ctime", str), ("state", str)]
extra_fields: Optional[list] = None
_BASE_FIELDS = (("pk", int), ("ctime", str), ("state", str))
extra_fields: Optional[tuple] = None

def __init__(self, process_label, **kwargs):
self.process_label = process_label
Expand All @@ -48,7 +48,7 @@ def __init__(self, process_label, **kwargs):
)

if self.extra_fields is not None:
fmt_extra = "".join([f"{{wc.{field[0]}}}\t" for field in self.extra_fields])
fmt_extra = "\t".join(f"{{wc.{field[0]}}}" for field in self.extra_fields)
self.fmt_workchain = self.BASE_FMT_WORKCHAIN + "\t" + fmt_extra
else:
self.fmt_workchain = self.BASE_FMT_WORKCHAIN
Expand Down Expand Up @@ -95,11 +95,11 @@ def find_work_chains(self):
pk = process_info["pk"]
extra_info = self.parse_extra_info(pk)

yield make_dataclass("WorkChain", self.BASE_FIELDS + self.extra_fields)(
**process_info, **extra_info
)
yield make_dataclass(
"WorkChain", self._BASE_FIELDS + self.extra_fields
)(**process_info, **extra_info)
else:
yield make_dataclass("WorkChain", self.BASE_FIELDS)(**process_info)
yield make_dataclass("WorkChain", self._BASE_FIELDS)(**process_info)

@tl.default("busy")
def _default_busy(self):
Expand Down
2 changes: 1 addition & 1 deletion aiidalab_ispg/app/qeapp/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, manager, description=None, **kwargs):
self.message_area,
self.confirm_button,
],
**kwargs
**kwargs,
)

@traitlets.default("state")
Expand Down
4 changes: 2 additions & 2 deletions aiidalab_ispg/app/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class SpectrumWidget(ipw.VBox):
# https://docs.bokeh.org/en/latest/docs/user_guide/tools.html?highlight=tools#specifying-tools
_TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
# https://docs.bokeh.org/en/latest/docs/user_guide/tools.html?highlight#hovertool
_TOOLTIPS = [("(energy, cross_section)", "($x,$y)")]
_TOOLTIPS = (("(energy, cross_section)", "($x,$y)"),)

def __init__(self, **kwargs):
self.width_slider = ipw.FloatSlider(
Expand Down Expand Up @@ -279,7 +279,7 @@ def __init__(self, **kwargs):
"width": 500,
}
self.figure = self._init_figure(
tools=self._TOOLS, tooltips=self._TOOLTIPS, **figure_size
tools=self._TOOLS, tooltips=list(self._TOOLTIPS), **figure_size
)
self.figure.layout = ipw.Layout(overflow="initial")

Expand Down
2 changes: 1 addition & 1 deletion aiidalab_ispg/app/static/StandardActinicFluxes2.csv
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,4 @@ WL,WU,wc,L90_500,M60_350,H0_200
746,747,746.5,1.754E+14,5.176E+14,5.836E+14
747,748,747.5,1.774E+14,5.213E+14,5.876E+14
748,749,748.5,1.787E+14,5.222E+14,5.885E+14
749,750,749.5,1.762E+14,5.116E+14,5.764E+14
749,750,749.5,1.762E+14,5.116E+14,5.764E+14
17 changes: 7 additions & 10 deletions aiidalab_ispg/app/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@


class ISPGWorkChainSelector(WorkChainSelector):
extra_fields = [
extra_fields = (
("formula", str),
("method", str),
("label", str),
("description", str),
]
)

def __init__(self, process_label: str, **kwargs):
super().__init__(process_label=process_label, **kwargs)
Expand Down Expand Up @@ -170,7 +170,8 @@ class TrajectoryDataViewer(StructureDataViewer):
trajectory = traitlets.Instance(Node, allow_none=True)
selected_structure_id = traitlets.Int(allow_none=True)

_structures: list[StructureData] = []
# TODO: Should probably be tuple instead
_structures: list[StructureData] = [] # noqa: RUF012
_energies: Optional[np.ndarray] = None
_boltzmann_weights: Optional[np.ndarray] = None

Expand Down Expand Up @@ -285,9 +286,7 @@ def _update_trajectory(self, change):
def _update_structure_viewer(self, change):
"""Update the view if displayed_structure trait was modified."""
with self.hold_trait_notifications():
for (
comp_id
) in self._viewer._ngl_component_ids: # pylint: disable=protected-access
for comp_id in self._viewer._ngl_component_ids: # pylint: disable=protected-access
self._viewer.remove_component(comp_id)
self.selection = []
if change["new"] is not None:
Expand Down Expand Up @@ -316,7 +315,7 @@ def _prepare_payload(self, file_format=None):
# NOTE: TrajectoryManagerWidget will hopefully note be necessary once
# the trajectory viewer is merged to AWB
class TrajectoryManagerWidget(StructureManagerWidget):
SUPPORTED_DATA_FORMATS = {
SUPPORTED_DATA_FORMATS = { # noqa: RUF012
"CifData": "core.cif",
"StructureData": "core.structure",
"TrajectoryData": "core.array.trajectory",
Expand Down Expand Up @@ -398,9 +397,7 @@ def _convert_to_structure_node(self, structure):
"""Convert structure of any type to the StructureNode object."""
if structure is None:
return None
structure_node_type = DataFactory(
self.SUPPORTED_DATA_FORMATS[self.node_class]
) # pylint: disable=invalid-name
structure_node_type = DataFactory(self.SUPPORTED_DATA_FORMATS[self.node_class]) # pylint: disable=invalid-name

# If the input_structure trait is set to Atoms object, structure node must be created from it.
if isinstance(structure, Atoms):
Expand Down
2 changes: 1 addition & 1 deletion aiidalab_ispg/workflows/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def extract_trajectory_arrays(**orca_output_parameters) -> ArrayData:
en0 = min(gibbs_energies)
relative_gibbs_energies_kj = AUtoKJ * (gibbs_energies - en0)

temperature = list(orca_output_parameters.values())[0]["temperature"]
temperature = next(iter(orca_output_parameters.values()))["temperature"]

boltzmann_weights = calc_boltzmann_weights(relative_gibbs_energies_kj, temperature)

Expand Down
46 changes: 25 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,35 @@ requires = [
build-backend = "setuptools.build_meta"

[tool.ruff]
# Enable pyflakes and pyf-builtins, pyflakes, f=bugbear
line-length = 88
# TODO: Enable ruff for notebooks
src = ["aiidalab_ispg", "tests"]
target-version = "py39"

# Enable pyflakes and pyf-builtins, pyflakes, f=bugbear
select = [
"A", # flake8-builtins
"B", # flake8-bugbear
"E", # pycodestyle
"F", # pyflakes
"C90", # McCabe code complexity
"UP", # pyupgrade
"S", # bandit
"C4", # comprehensiosn
"EM", # errormsg
"ISC", # implicit concatenation
"ICN", # import convention
"INP", # no implicite namespace package
"PIE", #
"PT", # pytest style
"A", # flake8-builtins
"B", # flake8-bugbear
"E", # pycodestyle
"F", # pyflakes
"C90", # McCabe code complexity
"UP", # pyupgrade
"S", # bandit
"C4", # comprehensions
"EM", # errormsg
"ISC", # implicit concatenation
"ICN", # import convention
"INP", # no implicite namespace package
"PIE", #
"PT", # pytest style
"PTH",
# "PL", # pylint, for now disabled
"PLC",
"PLE",
"PLW",
"RUF",
# "PL", # pylint, disabled for now
# "PLR", # pylint refactor
"PLC", "PLE", "PLW",
"RUF", # ruff
]
line-length = 120
src = ["aiidalab_ispg", "tests"]
target-version = "py39"

# Never enforce `E501` (line length violations).
# TODO: Remove all asserts from the codebase and enable this rule
Expand Down
Empty file modified tests/app/test_app.py
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion tests/wigner/wigner_test/freq_g09.molden
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ scf-first 1 THROUGH 12
-108.933430
[GEOMETRIES] XYZ
7

C -1.115872 -0.220612 0.023971
O 0.021884 0.600791 -0.024280
O 1.147735 -0.274299 -0.097254
Expand Down
Loading

0 comments on commit 8de5700

Please sign in to comment.