Skip to content

Commit f33db07

Browse files
authored
CI: uv+ruff (#109)
1 parent 490b2ac commit f33db07

27 files changed

+780
-654
lines changed

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# We include .git in the build context because excluding it would break the
2+
# "make release" target, which uses git to retrieve the build version and tag.
3+
#.git
4+
5+
crowdsec-blocklist-mirror
6+
crowdsec-blocklist-mirror-*
7+
crowdsec-blocklist-mirror.tgz
8+
docs/
9+
debian/
10+
rpm/
11+
test/

.github/workflows/tests.yml

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,21 @@ jobs:
3838
env:
3939
RICHGO_FORCE_COLOR: 1
4040

41+
- name: Install uv
42+
uses: astral-sh/setup-uv@v5
43+
with:
44+
version: 0.5.24
45+
enable-cache: true
46+
cache-dependency-glob: "test/uv.lock"
47+
4148
- name: "Setup Python"
4249
uses: actions/setup-python@v5
4350
with:
44-
python-version: "3.12"
45-
cache: 'pipenv'
51+
python-version-file: "test/.python-version"
4652

47-
- name: "Install python dependencies"
48-
env:
49-
PIP_BREAK_SYSTEM_PACKAGES: 1
50-
PIP_IGNORE_INSTALLED: 1
51-
run: |
52-
python -m pip install --upgrade pipenv
53-
pipenv install --deploy
54-
# some tests need root, so we have to install pytest twice
55-
sudo python3 -m pip install --upgrade pipenv
56-
sudo pipenv install --deploy
53+
- name: Install the project
54+
working-directory: ./test
55+
run: uv sync --all-extras --dev
5756

5857
- name: Install functional test dependencies
5958
run: |
@@ -66,18 +65,26 @@ jobs:
6665
CROWDSEC_TEST_NETWORK: net-test
6766
CROWDSEC_TEST_TIMEOUT: 60
6867
PYTEST_ADDOPTS: --durations=0 -vv --color=yes -m "not (deb or rpm)"
68+
working-directory: ./test
6969
run: |
7070
# everything except for
7171
# - install (requires root, ignored by default)
7272
# - deb/rpm (on their own workflows)
73-
pipenv run pytest
73+
uv run pytest
7474
# these need root
75-
sudo -E pipenv run pytest ./test/install/no_crowdsec
75+
sudo -E $(which uv) run pytest ./tests/install/no_crowdsec
7676
# these need a running crowdsec
77-
docker run -d --name crowdsec -e CI_TESTING=true -e DISABLE_ONLINE_API=true -ti crowdsecurity/crowdsec
77+
docker run -d --name crowdsec -e CI_TESTING=true -e DISABLE_ONLINE_API=true -p 8080:8080 -ti crowdsecurity/crowdsec
7878
install -m 0755 /dev/stdin /usr/local/bin/cscli <<'EOT'
7979
#!/bin/sh
8080
docker exec crowdsec cscli "$@"
8181
EOT
8282
sleep 5
83-
sudo -E pipenv run pytest ./test/install/with_crowdsec
83+
sudo -E $(which uv) run pytest ./tests/install/with_crowdsec
84+
85+
- name: Lint
86+
working-directory: ./test
87+
run: |
88+
uv run ruff check
89+
uv run basedpyright
90+

.github/workflows/tests_deb.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,21 @@ jobs:
2626
with:
2727
go-version-file: go.mod
2828

29-
- name: "Setup Python"
29+
- name: Install uv
30+
uses: astral-sh/setup-uv@v5
31+
with:
32+
version: 0.5.24
33+
enable-cache: true
34+
cache-dependency-glob: "test/uv.lock"
35+
36+
- name: "Set up Python"
3037
uses: actions/setup-python@v5
3138
with:
32-
python-version: "3.12"
33-
cache: 'pipenv'
39+
python-version-file: "test/.python-version"
3440

35-
- name: "Install python dependencies"
36-
env:
37-
PIP_BREAK_SYSTEM_PACKAGES: 1
38-
PIP_IGNORE_INSTALLED: 1
39-
run: |
40-
python -m pip install --upgrade pipenv
41-
pipenv install --deploy
42-
# some tests need root, so we have to install pytest twice
43-
sudo python3 -m pip install --upgrade pipenv
44-
sudo pipenv install --deploy
41+
- name: Install the project
42+
run: uv sync --all-extras --dev
43+
working-directory: ./test
4544

4645
- name: Install functional test dependencies
4746
run: |
@@ -56,6 +55,7 @@ jobs:
5655
CROWDSEC_TEST_NETWORK: net-test
5756
CROWDSEC_TEST_TIMEOUT: 60
5857
PYTEST_ADDOPTS: --durations=0 -vv --color=yes
58+
working-directory: ./test
5959
run: |
60-
pipenv run pytest test/pkg/test_build_deb.py
61-
sudo -E pipenv run pytest -m deb ./test/install/no_crowdsec
60+
uv run pytest ./tests/pkg/test_build_deb.py
61+
sudo -E $(which uv) run pytest -m deb ./tests/install/no_crowdsec

Pipfile

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

Pipfile.lock

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

test/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12
File renamed without changes.

test/pyproject.toml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[project]
2+
name = "cs-blocklist-mirror-tests"
3+
version = "0.1.0"
4+
description = "Tests for cs-blocklist-mirror"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = [
8+
"pexpect>=4.9.0",
9+
"pytest>=8.3.5",
10+
"pytest-cs>=0.7.21",
11+
"pytest-dependency>=0.6.0",
12+
"pytest-dotenv>=0.5.2",
13+
"zxcvbn>=4.5.0",
14+
]
15+
16+
[tool.uv.sources]
17+
pytest-cs = { git = "https://github.com/crowdsecurity/pytest-cs" }
18+
19+
[dependency-groups]
20+
dev = [
21+
"basedpyright>=1.28.4",
22+
"ipdb>=0.13.13",
23+
"ruff>=0.11.2",
24+
]
25+
26+
[tool.ruff]
27+
28+
line-length = 120
29+
30+
[tool.ruff.lint]
31+
select = [
32+
"ALL"
33+
]
34+
35+
ignore = [
36+
"ANN", # Missing type annotations
37+
"ARG001", # Unused function argument: `...`
38+
"COM812", # Trailing comma missing
39+
"D100", # Missing docstring in public module
40+
"D103", # Missing docstring in public function
41+
"D104", # Missing docstring in public package
42+
"D202",
43+
"D203", # incorrect-blank-line-before-class
44+
"D212", # Multi-line docstring summary should start at the first line
45+
"D400", # First line should end with a period
46+
"D415", # First line should end with a period, question mark, or exclamation point
47+
"ERA",
48+
"FIX002", # Line contains TODO, consider resolving the issue
49+
"FIX003", # Line contains XXX, consider resolving the issue
50+
"I001",
51+
"PLW1510", # `subprocess.run` without explicit `check` argument
52+
"S101", # Use of 'assert' detected
53+
"S603", # `subprocess` call: check for execution of untrusted input
54+
"S607", # Starting a process with a partial executable path
55+
"TD",
56+
"PLR2004", # Magic value used in comparison, consider replacing `...` with a constant variable
57+
"PLR0913", # Too many arguments in function definition (6 > 5)
58+
"PTH107", # `os.remove()` should be replaced by `Path.unlink()`
59+
"PTH108", # `os.unlink()` should be replaced by `Path.unlink()`
60+
"PTH110", # `os.path.exists()` should be replaced by `Path.exists()`
61+
"PTH116", # `os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()`
62+
"PTH123", # `open()` should be replaced by `Path.open()`
63+
"PT022", # No teardown in fixture `fw_cfg_factory`, use `return` instead of `yield`
64+
"Q000", # Single quotes found but double quotes preferred
65+
"UP022", # Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
66+
]
67+
68+
[tool.basedpyright]
69+
reportAny = "none"
70+
reportArgumentType = "none"
71+
reportAttributeAccessIssue = "none"
72+
reportMissingParameterType = "none"
73+
reportMissingTypeStubs = "none"
74+
reportOptionalMemberAccess = "none"
75+
reportUnknownArgumentType = "none"
76+
reportUnknownMemberType = "none"
77+
reportUnknownParameterType = "none"
78+
reportUnknownVariableType = "none"
79+
reportUnusedCallResult = "none"
80+
reportUnusedParameter = "none"

pytest.ini renamed to test/pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[pytest]
22
addopts =
33
--pdbcls=IPython.terminal.debugger:Pdb
4-
--ignore=test/install
4+
--ignore=tests/install
55
--strict-markers
66
markers:
77
deb: mark tests related to deb packaging

test/tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)