Skip to content

Commit fc50668

Browse files
committed
Add Ruff to project
1 parent 3436a05 commit fc50668

File tree

8 files changed

+65
-11
lines changed

8 files changed

+65
-11
lines changed

Jenkinsfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ pipeline {
7171
),
7272
flake8(pattern: 'build/flake8.txt'),
7373
pyLint(pattern: 'build/pylint.txt'),
74-
myPy(pattern: 'build/mypy.txt')
74+
myPy(pattern: 'build/mypy.txt'),
75+
pyLint(pattern: 'build/ruff.txt', id: 'ruff', name: 'Ruff')
7576
]
7677
)
7778
}

Jenkinsfile.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ node {
5656
),
5757
flake8(pattern: 'build/flake8.txt'),
5858
pyLint(pattern: 'build/pylint.txt'),
59-
myPy(pattern: 'build/mypy.txt')
59+
myPy(pattern: 'build/mypy.txt'),
60+
pyLint(pattern: 'build/ruff.txt', id: 'ruff', name: 'Ruff')
6061
]
6162
)
6263
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The Python package is based on the following toolchain:
2525
* [Flake8](https://flake8.pycqa.org/en/latest/) for style guide enforcement
2626
* [mypy](https://mypy-lang.org/) for static type checking
2727
* [Pylint](https://www.pylint.org/) for static code analysis
28+
* [Ruff](https://docs.astral.sh/ruff/) for linting and code formatting
2829
* [pytest](https://docs.pytest.org/en/stable/) for test creation and execution
2930

3031

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ dev-dependencies = [
4242
"pytest",
4343
"pytest-cov",
4444
"pytest-mock",
45+
"ruff",
4546
"sphinx",
4647
"sphinx-rtd-theme",
4748
]
@@ -69,3 +70,11 @@ omit = [
6970
output = "build/test-coverage.xml"
7071

7172
source_pkgs = ["python_training_project"]
73+
74+
[tool.ruff]
75+
include = [
76+
"pyproject.toml",
77+
"src/**/*.py",
78+
"tests/**/*.py"
79+
]
80+
output-format = "pylint"

src/python_training_project/__main__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
The main entry point contains the command line interface.
33
"""
4+
45
import logging
56
import sys
67

@@ -18,16 +19,17 @@ def cli():
1819
logging.basicConfig(
1920
stream=sys.stdout,
2021
level=logging.INFO,
21-
format='%(asctime)s %(name)-16s %(levelname)-8s %(message)s')
22+
format="%(asctime)s %(name)-16s %(levelname)-8s %(message)s",
23+
)
2224

2325

24-
@cli.command(name='sum')
25-
@click.argument('a', type=float)
26-
@click.argument('b', type=float)
26+
@cli.command(name="sum")
27+
@click.argument("a", type=float)
28+
@click.argument("b", type=float)
2729
def cli_sum(a: float, b: float):
2830
"""Show the sum of two numbers on the console."""
29-
log.info('Sum of %f and %f is %f', a, b, sum(a, b))
31+
log.info("Sum of %f and %f is %f", a, b, sum(a, b))
3032

3133

32-
if __name__ == '__main__':
34+
if __name__ == "__main__":
3335
cli()

src/python_training_project/calculate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ def sum(a: float, b: float) -> float:
77
"""Calculate the sum of two numbers."""
88
return a + b
99

10+
1011
# TODO: add more functions here

tools/lint-package.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,26 @@ if [ $? -ne 0 ]; then
1616
STATUS=1
1717
fi
1818

19+
echo "Running mypy..."
20+
uv run --all-extras mypy src/python_training_project > build/mypy.txt
21+
if [ $? -ne 0 ]; then
22+
STATUS=1
23+
fi
24+
1925
echo "Running pylint..."
2026
uv run --all-extras pylint src/python_training_project --msg-template="{path}:{line}: [{msg_id}, {obj}] {msg} ({symbol})" > build/pylint.txt
2127
if [ $? -ne 0 ]; then
2228
STATUS=1
2329
fi
2430

25-
echo "Running mypy..."
26-
uv run --all-extras mypy src/python_training_project > build/mypy.txt
31+
echo "Running ruff check..."
32+
uv run --all-extras ruff check > build/ruff.txt
33+
if [ $? -ne 0 ]; then
34+
STATUS=1
35+
fi
36+
37+
echo "Running ruff format..."
38+
uv run --all-extras ruff format --check
2739
if [ $? -ne 0 ]; then
2840
STATUS=1
2941
fi

uv.lock

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)