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 to lint codes #1852

Merged
merged 2 commits into from
Feb 25, 2023
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ repos:
rev: 23.1.0
hooks:
- id: black-jupyter
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.252
hooks:
- id: isort
files: \.py$
- id: ruff
args: ["--fix"]
# numpydoc
- repo: https://github.com/Carreau/velin
rev: 0.0.12
Expand Down
32 changes: 32 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,35 @@ omit = ["*test*"]

[tool.isort]
profile = "black"

[tool.ruff]
target-version = "py37"

select = [
"E", # errors
"F", # pyflakes
"D", # pydocstyle
"I", # isort
"UP", # pyupgrade
]
ignore = [
"E501", # line too long
"F401", # unused import
"F841", # local variable is assigned to but never used
"E741", # ambiguous variable name
"E402", # module level import not at top of file
"D413", # missing blank line after last section
"D416", # section name should end with a colon
"D203", # 1 blank line required before class docstring
"D107", # missing docstring in __init__
"D213", # multi-line docstring summary should start at the second line
"D100", # TODO: missing docstring in public module
"D101", # TODO: missing docstring in public class
"D102", # TODO: missing docstring in public method
"D103", # TODO: missing docstring in public function
"D104", # TODO: missing docstring in public package
"D105", # TODO: missing docstring in magic method
"D205", # 1 blank line required between summary line and description
"D401", # TODO: first line should be in imperative mood
"D404", # TODO: first word of the docstring should not be This
]
2 changes: 1 addition & 1 deletion reacnetgenerator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2018-2022, East China Normal University
"""ReacNetGenerator is an automatic reaction network generator for
reactive molecular dynamics simulation.[1]_
reactive molecular dynamics simulation.[1]_.

References
----------
Expand Down
2 changes: 1 addition & 1 deletion reacnetgenerator/_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def _readstepfunc(self, item):
s = line.split()
if index > 1:
step_atoms.append(
(index - 1, Atom(s[0], tuple((float(x) for x in s[1:4]))))
(index - 1, Atom(s[0], tuple(float(x) for x in s[1:4])))
)
_, step_atoms = zip(*sorted(step_atoms, key=operator.itemgetter(0)))
step_atoms = Atoms(step_atoms)
Expand Down
2 changes: 1 addition & 1 deletion reacnetgenerator/_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,5 @@ def _handlespecies(self, name):
if species:
logger.info("Species are:")
for specname, n in showname.items():
logger.info("{} {}".format(n, specname))
logger.info(f"{n} {specname}")
return species, showname
2 changes: 1 addition & 1 deletion reacnetgenerator/_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _searchspecies(self, originspec, sortedreactions, species):
for reaction, n_reaction in sortedreactions:
ii = 1
if originspec == reaction[1 - ii]:
if not reaction[ii] in species:
if reaction[ii] not in species:
searchedspecies.append((reaction[ii], (reaction, n_reaction)))
if len(searchedspecies) >= self.n_searchspecies:
break
Expand Down
2 changes: 1 addition & 1 deletion reacnetgenerator/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _getatomroute(self, item):
return moleculeroute, routestr

def _printatomroute(self, atomeach, timeaxis=None):
"""For analysis without HMM, we may not need to use np.unique"""
"""For analysis without HMM, we may not need to use np.unique."""
with WriteBuffer(
open(
self.atomroutefilename
Expand Down
4 changes: 2 additions & 2 deletions reacnetgenerator/_reachtml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# cython: linetrace=True
# cython: language_level=3
"""Generate a web page to show the analysis report.
Expand Down Expand Up @@ -72,7 +71,8 @@ def _re(self, smi):
like [H]C([H])[H]. However, OpenBabel will consider it as a methane molecule. So,
you have to use [H][C]([H])[H], if you need to process some radicals.

Examples:
Examples
--------
>>> self._re('C')
[C]
>>> self._re('[C]')
Expand Down
11 changes: 3 additions & 8 deletions reacnetgenerator/_reaction.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# cython: language_level=3
# cython: linetrace=True
"""Reactions finder.


"""
"""Reactions finder."""
from collections import Counter, defaultdict

import numpy as np
Expand Down Expand Up @@ -84,9 +81,7 @@ def _filterspec(self, reaction):
new_rightname = rightname - leftname
if new_leftname and new_rightname:
return "->".join(
(
"+".join(sorted(side.elements()))
for side in (new_leftname, new_rightname)
)
"+".join(sorted(side.elements()))
for side in (new_leftname, new_rightname)
)
return None
2 changes: 1 addition & 1 deletion reacnetgenerator/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,5 @@ def parm2cmd(pp: dict) -> List[str]:
)
for ii in ["nproc", "selectatoms", "stepinterval", "split", "maxspecies"]:
if pp.get(ii, None):
commands.extend(("--{}".format(ii), str(pp[ii])))
commands.extend((f"--{ii}", str(pp[ii])))
return commands
3 changes: 1 addition & 2 deletions reacnetgenerator/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# -*- coding: UTF-8 -*-
# cython: language_level=3
# cython: linetrace=True
"""GUI version of ReacNetGenerator.
"""
"""GUI version of ReacNetGenerator."""
import base64
import os
import tkinter as tk
Expand Down
4 changes: 2 additions & 2 deletions reacnetgenerator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def download_multifiles(urls: List[dict]) -> None:
asyncio.run(gather_download_files(urls))


def run_mp(nproc: int, **arg: Any) -> Iterable[Any]:
def run_mp(nproc: int, **kwargs: Any) -> Iterable[Any]:
"""Process a file with multiple processors.

Parameters
Expand All @@ -552,7 +552,7 @@ def run_mp(nproc: int, **arg: Any) -> Iterable[Any]:
pool = Pool(nproc, maxtasksperchild=1000)
semaphore = Semaphore(nproc * 150)
try:
results = multiopen(pool=pool, semaphore=semaphore, **arg)
results = multiopen(pool=pool, semaphore=semaphore, **kwargs)
for item in results:
yield item
semaphore.release()
Expand Down