Skip to content

Commit 324105d

Browse files
authored
Go full ruff (black and bandit) and disable bandit on codeclimate (#24)
* Go full ruff (black and bandit) and disable bandit on codeclimate Signed-off-by: Federico Busetti <729029+febus982@users.noreply.github.com>
1 parent b227aea commit 324105d

File tree

10 files changed

+83
-479
lines changed

10 files changed

+83
-479
lines changed

.bandit.yml

Lines changed: 0 additions & 406 deletions
This file was deleted.

.codeclimate.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
version: "2"
22
plugins:
3-
bandit:
4-
enabled: true
53
sonar-python:
64
enabled: true

.github/workflows/python-code-style.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ jobs:
2424
- name: Install dependencies
2525
run: |
2626
python -m pip install --upgrade pip
27-
python -m pip install poetry
28-
poetry config virtualenvs.create false
29-
poetry install --no-root --with dev
27+
python -m pip install poetry tox
28+
make poetry-export
3029
- name: Check code style with black
3130
run: |
3231
make format

.github/workflows/python-lint.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ jobs:
2424
- name: Install dependencies
2525
run: |
2626
python -m pip install --upgrade pip
27-
python -m pip install poetry
28-
poetry config virtualenvs.create false
29-
poetry install --no-root --with dev
27+
python -m pip install poetry tox
28+
make poetry-export
3029
- name: Lint with ruff
3130
run: make lint

.github/workflows/python-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,3 @@ jobs:
3333
- name: Test with pytest
3434
run: |
3535
make ci-test
36-
- name: Check typing
37-
run: |
38-
make typing
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
33

4-
name: Bandit checks
4+
name: Python lint
55

66
on:
77
push:
@@ -12,21 +12,19 @@ on:
1212
workflow_dispatch:
1313

1414
jobs:
15-
bandit:
15+
typing:
1616
runs-on: ubuntu-latest
1717

1818
steps:
1919
- uses: actions/checkout@v4
20-
21-
- name: Security check - Bandit
22-
uses: ioggstream/bandit-report-artifacts@v1.7.4
23-
with:
24-
project_path: .
25-
config_file: .bandit.yml
26-
27-
# This is optional
28-
- name: Security check report artifacts
29-
uses: actions/upload-artifact@v4
20+
- name: Set up Python 3.12
21+
uses: actions/setup-python@v5
3022
with:
31-
name: Security report
32-
path: output/security_report.txt
23+
python-version: "3.12"
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
python -m pip install poetry tox
28+
make poetry-export
29+
- name: Check typing
30+
run: make typing

Makefile

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,49 @@
1-
.PHONY: docs
1+
.PHONY: dev-dependencies update-dependencies test docs fix check typing lint format ci-test ci-coverage poetry-export
2+
3+
#########################
4+
###### dev commands #####
5+
#########################
6+
dev-dependencies:
7+
poetry install --with dev --no-root
8+
9+
update-dependencies:
10+
poetry update --with dev
211

312
test:
413
poetry run pytest -n auto --cov
514

6-
ci-test:
7-
poetry run pytest
15+
docs:
16+
poetry run mkdocs serve
817

9-
ci-coverage:
10-
poetry run pytest --cov --cov-report lcov
18+
fix:
19+
poetry run ruff . --fix
20+
poetry run ruff format .
1121

12-
typing:
13-
tox -e typing
22+
check: poetry-export
23+
tox
1424

15-
format:
16-
tox -e format
25+
typing: poetry-export
26+
tox -e typing
1727

18-
lint:
28+
lint: poetry-export
1929
tox -e lint
2030

21-
bandit:
22-
tox -e bandit
23-
24-
format-fix:
25-
poetry run black .
31+
format: poetry-export
32+
tox -e format
2633

27-
lint-fix:
28-
poetry run ruff . --fix
2934

30-
dev-dependencies:
31-
poetry install --with dev --no-root
35+
#########################
36+
#### Helper commands ####
37+
#########################
38+
poetry-export:
39+
poetry export -f requirements.txt --output /tmp/requirements.txt --with dev
3240

33-
update-dependencies:
34-
poetry update --with dev
3541

36-
fix: format-fix lint-fix
37-
check:
38-
poetry export -f requirements.txt --output /tmp/requirements.txt --with dev
39-
tox
42+
#########################
43+
###### CI commands ######
44+
#########################
45+
ci-test:
46+
poetry run pytest
4047

41-
docs:
42-
poetry run mkdocs serve
48+
ci-coverage:
49+
poetry run pytest --cov --cov-report lcov

pyproject.toml

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ optional = true
4646

4747
[tool.poetry.group.dev.dependencies]
4848
coverage = ">=6.5.0"
49-
bandit = ">=1.7.6"
50-
black = ">=22.10.0"
5149
mkdocs = ">=1.4.3"
5250
mkdocstrings = { version = ">=0.24.0", extras = ["python"] }
5351
mkdocs-gen-files = ">=0.5.0"
@@ -67,15 +65,6 @@ tox = ">=4.12.1"
6765
### Tools configuration ###
6866
############################
6967

70-
[tool.black]
71-
target-version = ["py38", "py39", "py310", "py311", "py312"]
72-
extend-exclude = '''
73-
(
74-
/docs,
75-
.tox
76-
)
77-
'''
78-
7968
[tool.coverage.run]
8069
branch = true
8170
source = ["bootstrap_python_package"]
@@ -104,9 +93,37 @@ testpaths = [
10493

10594
[tool.ruff]
10695
extend-exclude = ["docs", ".tox"]
96+
target-version = "py38"
10797

10898
[tool.ruff.lint]
109-
select = ["E", "F", "I"]
99+
select = [
100+
"E", # pycodestyle
101+
"W", # pycodestyle
102+
"F", # pyflakes
103+
"I", # isort
104+
"N", # pep8-naming
105+
"S", # flake8-bandit
106+
"RUF", # ruff-specific-rules
107+
]
108+
# Ignoring rules problematic with formatter
109+
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
110+
ignore = [
111+
"W191",
112+
"E111",
113+
"E114",
114+
"E117",
115+
"D206",
116+
"D300",
117+
"Q000",
118+
"Q001",
119+
"Q002",
120+
"Q003",
121+
"COM812",
122+
"COM819",
123+
"ISC001",
124+
"ISC002",
125+
]
110126

111127
[tool.ruff.lint.per-file-ignores]
112-
"__init__.py" = ["F401"]
128+
"__init__.py" = ["F401"] # Ignore unused imports on init files
129+
"tests/**/*.py" = ["S101"] # Allow assert usage on tests

scripts/gen_pages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
full_doc_path = Path(nav_pages_path, doc_path)
3636

3737
# Handle edge cases
38-
parts = (src_dir,) + tuple(module_path.parts)
38+
parts = (src_dir, *tuple(module_path.parts))
3939
if parts[-1] == "__init__":
4040
parts = parts[:-1]
4141
doc_path = doc_path.with_name("index.md")

tox.ini

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ env_list =
77
py39
88
py38
99
typing
10-
format
1110
lint
12-
bandit
11+
format
1312

1413
[testenv]
1514
; The file /tmp/requirements.txt is created automatically if you run tox
@@ -34,12 +33,8 @@ commands =
3433

3534
[testenv:format]
3635
commands =
37-
black --check .
36+
ruff format --check .
3837

3938
[testenv:lint]
4039
commands =
4140
ruff .
42-
43-
[testenv:bandit]
44-
commands =
45-
bandit -c .bandit.yml -r .

0 commit comments

Comments
 (0)