Skip to content

Commit 4bbc3e8

Browse files
authored
IC: uv + ruff (#180)
1 parent 06ca81c commit 4bbc3e8

26 files changed

+776
-661
lines changed

.github/workflows/tests.yml

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Set up Go
2525
uses: actions/setup-go@v5
2626
with:
27-
go-version: '1.22'
27+
go-version-file: go.mod
2828

2929
- name: Build
3030
run: |
@@ -38,19 +38,21 @@ jobs:
3838
env:
3939
RICHGO_FORCE_COLOR: 1
4040

41-
- name: "Setup Python"
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+
48+
- name: "Set up Python"
4249
uses: actions/setup-python@v5
4350
with:
44-
python-version: "3.x"
45-
cache: 'pipenv'
51+
python-version-file: "test/.python-version"
4652

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

5557
- name: Install functional test dependencies
5658
run: |
@@ -63,18 +65,26 @@ jobs:
6365
CROWDSEC_TEST_NETWORK: net-test
6466
CROWDSEC_TEST_TIMEOUT: 60
6567
PYTEST_ADDOPTS: --durations=0 -vv --color=yes -m "not (deb or rpm)"
68+
working-directory: ./test
6669
run: |
6770
# everything except for
6871
# - install (requires root, ignored by default)
6972
# - deb/rpm (on their own workflows)
70-
pipenv run pytest
73+
uv run pytest
7174
# these need root
72-
sudo -E pipenv run pytest ./test/install/no_crowdsec
75+
sudo -E $(which uv) run pytest ./tests/install/no_crowdsec
7376
# these need a running crowdsec
74-
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
7578
install -m 0755 /dev/stdin /usr/local/bin/cscli <<'EOT'
7679
#!/bin/sh
7780
docker exec crowdsec cscli "$@"
7881
EOT
7982
sleep 5
80-
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: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,23 @@ jobs:
2424
- name: Set up Go
2525
uses: actions/setup-go@v5
2626
with:
27-
go-version: '1.22'
27+
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.x"
33-
cache: 'pipenv'
39+
python-version-file: "test/.python-version"
3440

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

4345
- name: Install functional test dependencies
4446
run: |
@@ -53,6 +55,7 @@ jobs:
5355
CROWDSEC_TEST_NETWORK: net-test
5456
CROWDSEC_TEST_TIMEOUT: 60
5557
PYTEST_ADDOPTS: --durations=0 -vv --color=yes
58+
working-directory: ./test
5659
run: |
57-
pipenv run pytest test/pkg/test_build_deb.py
58-
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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[project]
2+
name = "cs-cloudflare-bouncer-tests"
3+
version = "0.1.0"
4+
description = "Tests for cs-cloudflare-bouncer"
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+
"D203", # incorrect-blank-line-before-class
43+
"D212", # Multi-line docstring summary should start at the first line
44+
"D400", # First line should end with a period
45+
"D415", # First line should end with a period, question mark, or exclamation point
46+
"ERA001",
47+
"FIX002", # Line contains TODO, consider resolving the issue
48+
"FIX003", # Line contains XXX, consider resolving the issue
49+
"PLW1510", # `subprocess.run` without explicit `check` argument
50+
"S101", # Use of 'assert' detected
51+
"S603", # `subprocess` call: check for execution of untrusted input
52+
"S607", # Starting a process with a partial executable path
53+
"TD",
54+
"PLR2004", # Magic value used in comparison, consider replacing `...` with a constant variable
55+
"PLR0913", # Too many arguments in function definition (6 > 5)
56+
"PTH107", # `os.remove()` should be replaced by `Path.unlink()`
57+
"PTH108", # `os.unlink()` should be replaced by `Path.unlink()`
58+
"PTH110", # `os.path.exists()` should be replaced by `Path.exists()`
59+
"PTH116", # `os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()`
60+
"PTH123", # `open()` should be replaced by `Path.open()`
61+
"PT022", # No teardown in fixture `fw_cfg_factory`, use `return` instead of `yield`
62+
"UP022", # Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
63+
"Q000",
64+
]
65+
66+
[tool.basedpyright]
67+
reportAny = "none"
68+
reportArgumentType = "none"
69+
reportAttributeAccessIssue = "none"
70+
reportMissingParameterType = "none"
71+
reportMissingTypeStubs = "none"
72+
reportOptionalMemberAccess = "none"
73+
reportUnknownArgumentType = "none"
74+
reportUnknownMemberType = "none"
75+
reportUnknownParameterType = "none"
76+
reportUnknownVariableType = "none"
77+
reportUnusedCallResult = "none"
78+
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.

test/tests/bouncer/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)