Skip to content

Commit 2896c50

Browse files
HugoOnghaitsmathis
andauthored
Linting workflow and pre-commit (#26)
* Added linting workflow, hopefully it works * Testing linting workflow again * New Branch for Linting Workflow * Testing Linting workflow * Allowing Lint.YML to run on push to linting_workflow * Testing pre-commit and updated lint.yml to disregard legacy files * disable fail-fast to see if other python versions will fail * Using uv to install ruff dependency, using uv-cache and removing pip installation * added new action to install virtual environment before attempting to install dependency * Fixed missing run for uv venv * attempting ruff check again now that is seems to work... * Trying uvx * Removed assume python 3.9 from ruff config in pyproject.toml * New Branch for Linting Workflow * Testing Linting workflow * (after rebase) Allowing Lint.YML to run on push to linting_workflow * Testing pre-commit and updated lint.yml to disregard legacy files * disable fail-fast to see if other python versions will fail * Using uv to install ruff dependency, using uv-cache and removing pip installation * added new action to install virtual environment before attempting to install dependency * Fixed missing run for uv venv * attempting ruff check again now that is seems to work... * (after rebase) Trying uvx * Removed assume python 3.9 from ruff config in pyproject.toml * fixing typos after rebase * Installing Ruff before calling check; added precommit to uvlock * Added verbose keyword to make clear that files are being checked * Attempting to revert src/ tests/ and .gitignore to master current ver * Readded release and testing default workflows to match master * Readd changelog to match master * restored old version of gitignore * Fixing PR comments * fix * added mypy and ruff to a dependency group called lint --------- Co-authored-by: Tyler Mathis <[email protected]>
1 parent 860c854 commit 2896c50

File tree

5 files changed

+301
-1
lines changed

5 files changed

+301
-1
lines changed

.github/workflows/lint.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,20 @@ on:
55
branches: [master]
66
pull_request:
77
branches: [master]
8+
workflow_dispatch:
9+
810
# TODO: setup linting with uv/ruff
11+
# informed by testing.yml and https://medium.com/@sidharthvijayakumar7/automating-pylint-in-github-workflow-80c84b2ff243 and ruff documentation
12+
jobs:
13+
linting:
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Install uv and set up the python version
18+
uses: astral-sh/setup-uv@v6
19+
with:
20+
python-version: '3.12'
21+
version: "latest"
22+
23+
- name: Analyzing the code with ruff
24+
run: uvx ruff check --output-format=github

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.12.4
5+
hooks:
6+
# Run the linter.
7+
- id: ruff-check
8+
types_or: [ python, pyi ]
9+
args: [ --fix ]
10+
# Run the formatter.
11+
- id: ruff-format
12+
types_or: [python, pyi ]
13+
exclude: 'legacy'

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

pyproject.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ dependencies = [
2222
[dependency-groups]
2323
dev = [
2424
"pytest>=8.4.1",
25+
"pre-commit>=4.2.0",
26+
]
27+
lint = [
28+
"mypy>=1.17.1",
29+
"ruff>=0.12.7",
2530
]
2631

2732
[build-system]
@@ -38,3 +43,56 @@ packages = ["src/mp_cite"]
3843
[project.urls]
3944
Homepage = "https://github.com/materialsproject/MPCite"
4045
Issues = "https://github.com/materialsproject/MPCite/issues"
46+
47+
[tool.ruff]
48+
# Exclude a variety of commonly ignored directories.
49+
exclude = [
50+
"legacy",
51+
"notebooks",
52+
"uv.lock"
53+
]
54+
55+
# Same as Black.
56+
line-length = 88
57+
indent-width = 4
58+
59+
[tool.ruff.lint]
60+
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
61+
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
62+
# McCabe complexity (`C901`) by default.
63+
select = ["E4", "E7", "E9", "F"]
64+
ignore = []
65+
66+
# Allow fix for all enabled rules (when `--fix`) is provided.
67+
fixable = ["ALL"]
68+
unfixable = []
69+
70+
# Allow NO unused variables to exist in the codebase. If underscore-prefixed unused variables are permissible, use this regex $^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
71+
dummy-variable-rgx = "^$"
72+
73+
[tool.ruff.format]
74+
# Like Black, use double quotes for strings.
75+
quote-style = "double"
76+
77+
# Like Black, indent with spaces, rather than tabs.
78+
indent-style = "space"
79+
80+
# Like Black, respect magic trailing commas.
81+
skip-magic-trailing-comma = false
82+
83+
# Like Black, automatically detect the appropriate line ending.
84+
line-ending = "auto"
85+
86+
# Enable auto-formatting of code examples in docstrings. Markdown,
87+
# reStructuredText code/literal blocks and doctests are all supported.
88+
#
89+
# This is currently disabled by default, but it is planned for this
90+
# to be opt-out in the future.
91+
docstring-code-format = false
92+
93+
# Set the line length limit used when formatting code snippets in
94+
# docstrings.
95+
#
96+
# This only has an effect when the `docstring-code-format` setting is
97+
# enabled.
98+
docstring-code-line-length = "dynamic"

0 commit comments

Comments
 (0)