Skip to content

Commit ae2b0cf

Browse files
authored
Merge pull request #472 from TheHive-Project/467-investigate-the-usefulness-of-the-nox-project-for-dev-scripts
#467 - Introduce nox to manage dev scripts
2 parents 6c896a0 + 91bceb5 commit ae2b0cf

File tree

14 files changed

+175
-323
lines changed

14 files changed

+175
-323
lines changed

.github/workflows/_build-docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
uses: actions/setup-python@v4
1212
with:
1313
python-version: 3.13
14-
- name: Install build dependencies
15-
run: pip install --no-cache-dir -U pip .['docs']
14+
- name: Install dependencies
15+
run: pip install --no-cache-dir -U pip .['dev']
1616
- name: Build docs
17-
run: ./scripts/cd.py --build-docs
17+
run: nox --session=build-docs

.github/workflows/_build-package.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
uses: actions/setup-python@v4
1212
with:
1313
python-version: 3.13
14-
- name: Install build dependencies
15-
run: pip install --no-cache-dir -U pip .['build']
14+
- name: Install dependencies
15+
run: pip install --no-cache-dir -U pip .['dev']
1616
- name: Build package
17-
run: ./scripts/cd.py --build
17+
run: nox --session=build
1818
- name: Upload built distributions
1919
uses: actions/upload-artifact@v4
2020
with:

.github/workflows/_check-release-notes.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ jobs:
1111
uses: actions/setup-python@v4
1212
with:
1313
python-version: 3.13
14+
- name: Install dependencies
15+
run: pip install --no-cache-dir -U pip .['dev']
1416
- name: Check release notes
15-
run: ./scripts/linkify_release_notes.py --check
16-
- name: Lookup version in release notes
17-
run: |
18-
VERSION=$(grep -Po '(?<=version = ")[^"]*' pyproject.toml)
19-
if ! grep -qF "## $VERSION " "docs/release-notes.md"; then
20-
echo "No release notes found for version '$VERSION'"
21-
exit 1
22-
fi
17+
run: nox --session=check-release-notes

.github/workflows/_deploy-docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ jobs:
1111
uses: actions/setup-python@v4
1212
with:
1313
python-version: 3.13
14-
- name: Install build dependencies
15-
run: pip install --no-cache-dir -U pip .['docs']
14+
- name: Install dependencies
15+
run: pip install --no-cache-dir -U pip .['dev']
1616
- name: Configure git
1717
run: |
1818
git fetch origin gh-pages --depth=1
1919
git config --local user.email "github-actions[bot]@users.noreply.github.com"
2020
git config --local user.name "github-actions[bot]"
2121
- name: Deploy to github pages
22-
run: ./scripts/cd.py --deploy-docs
22+
run: nox --session=deploy-docs

.github/workflows/_integration-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
with:
1616
python-version: 3.13
1717
- name: Install dependencies
18-
run: pip install --no-cache-dir -U pip .['test']
18+
run: pip install --no-cache-dir -U pip .['dev']
1919
- name: Run integration tests
20-
run: scripts/ci.py --test
20+
run: nox --session=test
2121
- name: Upload coverage results
2222
uses: codecov/codecov-action@v4
2323
with:

.github/workflows/_static-checks.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ jobs:
1616
python-version: ${{ matrix.python-version }}
1717
- name: Install dependencies
1818
run: pip install --no-cache-dir -U pip .['dev']
19-
- name: Lint check with flake8
20-
run: scripts/ci.py --lint
19+
- name: Style check with flake8
20+
run: nox --session=style
2121
- name: Format check with black
22-
run: scripts/ci.py --format
22+
run: nox --session=format
2323
- name: Type check with mypy
24-
run: scripts/ci.py --type
24+
run: nox --session=type
2525
- name: CVE check with pip-audit
26-
run: scripts/ci.py --cve
26+
run: nox --session=cve
2727
- name: Security check with bandit
28-
run: scripts/ci.py --security
28+
run: nox --session=security

.github/workflows/_upload-package.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
13-
- name: Compare tag and package version
14-
run: |
15-
TAG=${GITHUB_REF#refs/*/}
16-
VERSION=$(grep -Po '(?<=version = ")[^"]*' pyproject.toml)
17-
if [ "$TAG" != "$VERSION" ]; then
18-
echo "Tag value and package version are different: ${TAG} != ${VERSION}"
19-
exit 1
20-
fi
2113
- name: Download built distributions
2214
uses: actions/download-artifact@v4
2315
with:
@@ -27,10 +19,10 @@ jobs:
2719
uses: actions/setup-python@v4
2820
with:
2921
python-version: 3.13
30-
- name: Install build dependencies
31-
run: pip install --no-cache-dir -U pip .['build']
22+
- name: Install dependencies
23+
run: pip install --no-cache-dir -U pip .['dev']
3224
- name: Upload to PyPI
33-
run: ./scripts/cd.py --upload
25+
run: nox --session=upload
3426
env:
3527
TWINE_REPOSITORY_URL: https://upload.pypi.org/legacy/
3628
TWINE_USERNAME: __token__

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repos:
44
hooks:
55
- id: ci-checks
66
name: ci-checks
7-
entry: scripts/ci.py
7+
entry: nox
88
language: system
99
pass_filenames: false
1010
always_run: true

README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,17 +307,23 @@ To contribute to `thehive4py`, follow these steps:
307307

308308
## Run CI checks before pushing changes
309309

310-
To ensure the integrity of your changes and maintain code quality, you can run CI checks before pushing your changes to the repository. Use one of the following methods:
310+
The project is utilizing the [nox] library to define and run automated dev scripts.
311+
312+
To ensure the integrity of your changes and maintain code quality you can use the provided sessions from the local `noxfile.py`.
313+
For example you can run CI checks before pushing your changes to the repository. Use one of the following methods:
311314

312315
**Method 1: Manual check**
313316

314-
Run the CI checks manually by executing the following command:
317+
Run the CI checks manually by using the following command:
315318

316-
```
317-
python scripts/ci.py
318-
```
319+
nox
320+
321+
This will trigger all CI checks except tests as the `noxfile.py` is configured to do so by default.
322+
323+
324+
To run individual checks one can list all the available sessions with:
319325

320-
This command will trigger the CI checks and provide feedback on any issues that need attention.
326+
nox --list
321327

322328
**Method 2: Automatic checks with pre-commit hooks [experimental]**
323329

@@ -353,15 +359,25 @@ Once TheHive is responsive the suite will initialize the instance with a setup r
353359
Please note that due to this initial setup the very first test run will idle for some time to make sure everything is up and running. Any other subsequent runs' statup time should be significantly faster.
354360

355361
### Testing locally
356-
To execute the whole test suite locally one can use the `scripts/ci.py` utility script like:
362+
To execute the whole test suite locally one can use the `test` session provided by the local `noxfile.py` utility script like:
363+
364+
nox --session=test
365+
366+
or
367+
368+
nox -s test
369+
370+
for short.
371+
372+
Note however that the above will command execute the entire test suite which can take several minutes to complete.
373+
In case one wants to execute only a portion of the test suite then the easiest workaround is to pass additional arguments to the session e.g.:
357374

358-
./scripts/ci.py --test
375+
nox -s test -- tests/test_observable_endpoint.py -v
359376

360-
Note however that the above will execute the entire test suite which can take several minutes to complete.
361-
In case one wants to execute only a portion of the test suite then the easiest workaround is to use `pytest` and pass the path to the specific test module. For example to only execute tests for the alert endpoints one can do:
377+
The nox command will parse additional arguments after the `--` option terminator argument and they will be passed to the underlying `pytest` command.
362378

363-
pytest -v tests/test_alert_endpoint.py
364379

365380
[get-docker]: https://docs.docker.com/get-docker/
366381
[query-api-docs]: https://docs.strangebee.com/thehive/api-docs/#operation/Query%20API
367382
[thehive-image]: https://hub.docker.com/r/strangebee/thehive
383+
[nox]: https://nox.thea.codes/en/stable/

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ plugins:
7575
- mkdocstrings:
7676
handlers:
7777
python:
78-
import:
78+
inventories:
7979
- https://docs.python.org/3/objects.inv
8080
- https://requests.readthedocs.io/en/stable/objects.inv
8181
options:

0 commit comments

Comments
 (0)