Skip to content

Commit ea7ced7

Browse files
committed
Introduce Ruff github CI with some basic linter rules
And also to help catching syntax errors on older Python versions.
1 parent 7cde962 commit ea7ced7

5 files changed

Lines changed: 79 additions & 4 deletions

File tree

.github/workflows/ci-black-formatting.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
run: |
2424
python3 -m pip install --upgrade pip
2525
python3 -m pip install 'black>=24.10.0'
26+
curl -LsSf https://astral.sh/uv/install.sh | sh
27+
uv tool install ruff
2628
2729
# black doesn't catch all syntax errors, so we check them explicitly.
2830
- name: Check syntax errors
@@ -35,18 +37,27 @@ jobs:
3537
continue-on-error: true
3638

3739
- name: Black formatter
38-
id: linting
40+
id: black
3941
run: |
4042
python3 -m black --diff --check .
4143
continue-on-error: true
4244

45+
- name: Ruff check
46+
id: ruff
47+
run: |
48+
uvx ruff check
49+
continue-on-error: true
50+
4351
- name: Final check
4452
run: |
4553
ERROR=0
4654
if [ "${{ steps.syntax-errors.outcome }}" != "success" ]; then
4755
echo "::error::Syntax errors check failed, see 'syntax-errors' step for the details." && ERROR=1
4856
fi
49-
if [ "${{ steps.linting.outcome }}" != "success" ]; then
50-
echo "::error::Black formatting check failed, see 'linting' step for the details." && ERROR=1
57+
if [ "${{ steps.black.outcome }}" != "success" ]; then
58+
echo "::error::Black formatting check failed, see 'black' step for the details." && ERROR=1
59+
fi
60+
if [ "${{ steps.ruff.outcome }}" != "success" ]; then
61+
echo "::error::Ruff check failed, see 'ruff' step for the details." && ERROR=1
5162
fi
5263
exit $ERROR

pyproject.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,46 @@ disableBytesTypePromotions = true
3838
reportUnnecessaryTypeIgnoreComment = true
3939
# Just to add a quick insert of `# pyright: ignore[xxx]` comments in Pylance.
4040
enableTypeIgnoreComments = false
41+
42+
# Define here general ruff settings,
43+
# then they will be inherited projects .toml files.
44+
# This allows using assuming different Python version for different projects.
45+
[tool.ruff]
46+
exclude = [
47+
# Submodules.
48+
"src/ifcopenshell-python/ifcopenshell/express",
49+
"src/ifcopenshell-python/ifcopenshell/mvd",
50+
"src/ifcopenshell-python/ifcopenshell/simple_spf",
51+
"src/svgfill",
52+
#
53+
# Unformatted.
54+
"src/exterior-shell-extractor",
55+
# Incompatible with linter.
56+
"src/ifc2ca/templates",
57+
]
58+
[tool.ruff.lint]
59+
select = [
60+
# Default Ruff rules.
61+
# "E4", # imports
62+
# "E7", # statements
63+
"E9", # io errors
64+
# "F", # pyflakes
65+
#
66+
"FA", # future annotations
67+
"UP", # pyupgrade
68+
]
69+
ignore = [
70+
"FA100", # Conflicts with Blender using annotations for props definitions.
71+
# Maybe will enable later:
72+
"UP006", # deprecated symbols
73+
"UP007", # Optional to X | Y
74+
"UP015", # Unnecessary mode argument
75+
"UP028", # yield for -> yield from
76+
"UP030", # implicit references for positional format fields
77+
"UP031", # Replace % with .format
78+
"UP032", # Replace .format with f-string
79+
"UP035", # List -> list
80+
81+
# Deprecated Ruff rules.
82+
"UP038", # Use X | Y in isinstance
83+
]

src/bonsai/docs/guides/development/code_style.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Code style
22
============
33

44

5-
Black code formatter
5+
Code formatters
66
-------------------------------
77
For Python code formatting, we use `Black code formatter <https://pypi.org/project/black/>`__,
88
black settings are stored in the repository's pyproject.toml.
@@ -19,3 +19,17 @@ We have GitHub workflow `ci-black-formatting` to maintain black formatting acros
1919
# Format only some specific file.
2020
black src/bonsai/bonsai/bim/module/qto/operator.py
2121
22+
23+
There is also `ruff` with some basic linter rules (checked automatically by the same Github workflow).
24+
Which also helps maintaining consistency across the code base
25+
and ensure new Python syntax doesn't break code on older Python versions.
26+
27+
``ruff`` can be installed using ``pip install ruff`` and files can be formatted with the following example commands:
28+
29+
.. code-block:: bash
30+
# Check issues for the entire repository.
31+
ruff check
32+
# Apply some automatic fixes, if available.
33+
ruff check --fix
34+
# Check only some specific file.
35+
ruff src/bonsai/bonsai/bim/module/qto/operator.py

src/bonsai/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ keywords = ["IFC", "Blender", "BIM"]
1313
classifiers = [
1414
"Programming Language :: Python :: 3",
1515
]
16+
requires-python = ">=3.11"
1617
dependencies = [
1718
"ifcopenshell",
1819
]
@@ -28,3 +29,6 @@ exclude = ["test*"]
2829

2930
[tool.setuptools.package-data]
3031
"*" = ["*.*", "libs/desktop/bonsai", "libs/bin/ifcmerge"]
32+
33+
[tool.ruff]
34+
extend = "../../pyproject.toml"

src/ifcopenshell-python/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ include = ["ifcopenshell*"]
3636

3737
[tool.setuptools.package-data]
3838
"*" = ["*.*"]
39+
40+
[tool.ruff]
41+
extend = "../../pyproject.toml"

0 commit comments

Comments
 (0)