Skip to content

Commit

Permalink
Update formatting and linting
Browse files Browse the repository at this point in the history
Former-commit-id: d6aea62
  • Loading branch information
kavanase committed Apr 13, 2024
1 parent de0cee2 commit 540d295
Show file tree
Hide file tree
Showing 14 changed files with 922 additions and 1,554 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install setuptools setuptools_scm wheel
pip install pydocstyle black flake8 isort
pip install pydocstyle black flake8 ruff
pip install -e .[tests]
- name: sort imports
- name: ruff
run: |
isort . --atomic --profile black
ruff --version
ruff --fix shakenbreak
- name: check docstrings
run: |
pydocstyle --version
pydocstyle -e --count --convention=google --add-ignore=D400,D415,D212,D205,D417,D107 shakenbreak
- name: black
- name: black # max line length 107 specified in pyproject.toml
run: |
black --version
black --color shakenbreak
Expand Down
23 changes: 8 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
# See https://pre-commit.com/hooks.html for more hooks
exclude: ^(docs|tests|SnB_input_files|.github|shakenbreak/scripts|CITATION*|MANIFEST*)
repos:

# Lint and format, isort, docstrings...
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.3.7
hooks:
- id: ruff
args: [--fix]

# Remove trailing whitespace, leave empty line at end of file
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -12,18 +17,6 @@ repos:
- id: end-of-file-fixer
- id: check-yaml

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.971
# hooks:
# - id: mypy

# Sort/format imports
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: [--profile, black]

# Check docstrings
- repo: https://github.com/pycqa/pydocstyle
rev: 4.0.0 # pick a git hash / tag to point to
Expand All @@ -32,8 +25,8 @@ repos:
args: [-e, --count, "--convention=google", "--add-ignore=D107,D202,D400,D415,D212,D205,D417,D413"]

# Code formatting
- repo: https://github.com/psf/black
rev: 22.6.0
- repo: https://github.com/psf/black # max line length 107 specified in pyproject.toml
rev: 24.2.0
hooks:
- id: black
args: [--color]
Expand Down
4 changes: 2 additions & 2 deletions docs/Contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ workflow to do so and follow the `PEP8 <https://peps.python.org/pep-0008/>`_ sty
.. NOTE::
Alternatively, if you prefer not to use ``pre-commit hooks``, you can manually run the following in the **correct sequence**
on your local machine. From the ``shakenbreak`` top directory, run `isort <https://pycqa.github.io/isort/>`_ to sort and format your imports, followed by
on your local machine. From the ``shakenbreak`` top directory, run `ruff --fix <https://docs.astral.sh/ruff/>`_ to lint and format, followed by
`black <https://black.readthedocs.io/en/stable/index.html>`_, which will automatically reformat the code to ``PEP8`` conventions:

.. code:: bash
$ isort . --profile black
$ ruff --fix
$ black --diff --color shakenbreak
Then run `pycodestyle <https://pycodestyle.pycqa.org/en/latest/>`_ to check the docstrings,
Expand Down
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,53 @@ requires = [
"wheel"
]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 107

[tool.ruff]
line-length = 107
lint.pydocstyle.convention = "google"
lint.isort.split-on-trailing-comma = false
lint.select = [ # from pymatgen
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"D", # pydocstyle
"E", # pycodestyle error
"EXE", # flake8-executable
"F", # pyflakes
"FLY", # flynt
"I", # isort
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"PD", # pandas-vet
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PYI", # flakes8-pyi
"Q", # flake8-quotes
"RET", # flake8-return
"RSE", # flake8-raise
"RUF", # Ruff-specific rules
"SIM", # flake8-simplify
"TCH", # flake8-type-checking
"TID", # tidy imports
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"W", # pycodestyle warning
"YTT", # flake8-2020
]
lint.ignore = [
"B028", # No explicit stacklevel keyword argument found
"D101", # Missing docstring in public class (docstring in init instead)
"D200", # One-line docstring should fit on one line with quotes
"D205", # 1 blank line required between summary line and description
"D212", # Multi-line docstring summary should start at the first line
"PLR2004", # Magic number
"PLR", # pylint refactor
"W605", # Invalid escape sequence
"PT011", # too broad pytest.raises()
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["D102"]
14 changes: 6 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""This is a setup.py script to install ShakeNBreak"""
"""This is a setup.py script to install ShakeNBreak."""

import os
import warnings
Expand Down Expand Up @@ -32,9 +32,7 @@ def _install_custom_font():

# Copy the font file to matplotlib's True Type font directory
fonts_dir = f"{path_to_file}/shakenbreak/"
ttf_fonts = [
file_name for file_name in os.listdir(fonts_dir) if ".ttf" in file_name
]
ttf_fonts = [file_name for file_name in os.listdir(fonts_dir) if ".ttf" in file_name]
try:
for font in ttf_fonts: # must be in ttf format for matplotlib
old_path = os.path.join(fonts_dir, font)
Expand Down Expand Up @@ -104,7 +102,7 @@ def run(self):


class CustomEggInfoCommand(egg_info):
"""Post-installation"""
"""Post-installation."""

def run(self):
"""
Expand All @@ -120,14 +118,14 @@ def run(self):
def package_files(directory):
"""Include package data."""
paths = []
for path, directories, filenames in os.walk(directory):
for path, _dir, filenames in os.walk(directory):
paths.extend(os.path.join("..", path, filename) for filename in filenames)
return paths


input_files = package_files("SnB_input_files/")

with open("README.md", "r", encoding="utf-8") as file:
with open("README.md", encoding="utf-8") as file:
long_description = file.read()


Expand Down Expand Up @@ -194,7 +192,7 @@ def package_files(directory):
},
# Specify any non-python files to be distributed with the package
package_data={
"shakenbreak": ["shakenbreak/*"] + input_files,
"shakenbreak": ["shakenbreak/*", *input_files],
},
include_package_data=True,
# Specify the custom installation class
Expand Down
Loading

0 comments on commit 540d295

Please sign in to comment.