Skip to content

Commit 98fc726

Browse files
committed
#467 - Introduce nox to manage dev scripts
1 parent 6c896a0 commit 98fc726

File tree

10 files changed

+131
-30
lines changed

10 files changed

+131
-30
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ 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

.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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
uses: actions/setup-python@v4
2828
with:
2929
python-version: 3.13
30-
- name: Install build dependencies
31-
run: pip install --no-cache-dir -U pip .['build']
30+
- name: Install dependencies
31+
run: pip install --no-cache-dir -U pip .['dev']
3232
- name: Upload to PyPI
3333
run: ./scripts/cd.py --upload
3434
env:

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:

noxfile.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import os
2+
3+
import nox
4+
5+
PROJECT_DIR = os.path.dirname(__file__)
6+
THEHIVE4PY_DIR = os.path.join(PROJECT_DIR, "thehive4py/")
7+
TESTS_DIR = os.path.join(PROJECT_DIR, "tests/")
8+
9+
nox.options.default_venv_backend = "none"
10+
nox.options.tags = ["audit", "lint"]
11+
12+
13+
@nox.session(tags=["ci", "lint"])
14+
def style(session: nox.Session):
15+
"""Run style checks with flake8."""
16+
session.run("flake8", THEHIVE4PY_DIR, TESTS_DIR)
17+
18+
19+
@nox.session(tags=["ci", "lint"])
20+
def format(session: nox.Session):
21+
"""Run format checks with black."""
22+
session.run("black", "--check", THEHIVE4PY_DIR, TESTS_DIR)
23+
24+
25+
@nox.session(tags=["ci", "lint"])
26+
def type(session: nox.Session):
27+
"""Run type checks with mypy."""
28+
session.run("mypy", "--install-types", "--non-interactive", THEHIVE4PY_DIR)
29+
30+
31+
@nox.session(tags=["ci", "audit"])
32+
def cve(session: nox.Session):
33+
"""Run cve checks with pip-audit."""
34+
session.run("pip-audit", ".")
35+
36+
37+
@nox.session(tags=["ci", "audit"])
38+
def security(session: nox.Session):
39+
"""Run security checks with bandit."""
40+
session.run("bandit", "-r", THEHIVE4PY_DIR)
41+
42+
43+
@nox.session(tags=["ci", "test"])
44+
def test(session: nox.Session):
45+
"""Run integration tests with pytest."""
46+
47+
if not session.posargs:
48+
session.run("pytest", "-v", "--cov")
49+
else:
50+
session.run("pytest", *session.posargs)
51+
52+
53+
@nox.session(tags=["cd", "build"])
54+
def build(session: nox.Session):
55+
"""Build thehive4py with the build module."""
56+
session.run("rm", "-rf", "build/", "dist/")
57+
session.run("python", "-m", "build", "--sdist", "--wheel")
58+
59+
60+
@nox.session(tags=["cd", "upload"])
61+
def upload(session: nox.Session):
62+
"""Upload thehive4py to PyPI using twine."""
63+
# TODO: change check to upload
64+
session.run("twine", "check", "dist/*")
65+
66+
67+
@nox.session(tags=["cd", "docs"], name="build-docs")
68+
def build_docs(session: nox.Session):
69+
"""Build docs locally."""
70+
session.run("mkdocs", "build", "--clean", "--strict")
71+
72+
73+
@nox.session(tags=["cd", "docs"], name="deploy-docs")
74+
def deploy_docs(session: nox.Session):
75+
"""Deploy docs to gh-pages."""
76+
session.run("mkdocs", "build", "--clean", "--strict")
77+
78+
79+
@nox.session(tags=["utils", "docs"], name="serve-docs")
80+
def serve_docs(session: nox.Session):
81+
"""Serve docs locally."""
82+
session.run("mkdocs", "serve", "--clean", "--strict")
83+
84+
85+
@nox.session(tags=["utils", "docs"], name="linkify-release-notes")
86+
def linkify_release_notes(session: nox.Session):
87+
"""Linkify plain github release notes for the docs."""
88+
session.run("./scripts/linkify_release_notes.py")
89+
90+
91+
@nox.session(tags=["cd", "docs"], name="check-release-notes")
92+
def check_release_notes(session: nox.Session):
93+
"""Check release notes for deployment."""
94+
session.run("./scripts/linkify_release_notes.py", "--check")
95+
session.run(
96+
"bash",
97+
"-c",
98+
r"""
99+
VERSION=$(grep -Po '(?<=version = ")[^"]*' pyproject.toml)
100+
if ! grep -qF "## $VERSION " "docs/release-notes.md"; then
101+
echo "No release notes found for version '$VERSION'"
102+
exit 1
103+
else
104+
echo "Release notes found for version '$VERSION'"
105+
fi
106+
""",
107+
)

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ requires-python = ">=3.9"
1010
dependencies = ["requests~=2.27", "typing_extensions==4.*"]
1111
readme = "README.md"
1212
keywords = ["thehive5", "api", "client"]
13-
license = { text = "MIT" }
13+
license = "MIT"
1414
classifiers = [
1515
"Development Status :: 4 - Beta",
1616
"Intended Audience :: Developers",
@@ -21,7 +21,6 @@ classifiers = [
2121
"Programming Language :: Python :: 3.11",
2222
"Programming Language :: Python :: 3.12",
2323
"Programming Language :: Python :: 3.13",
24-
"License :: OSI Approved :: MIT License",
2524
]
2625
authors = [{ name = "Szabolcs Antal", email = "antalszabolcs01@gmail.com" }]
2726

@@ -31,7 +30,7 @@ build = ["build", "twine"]
3130
docs = ["mkdocs", "mkdocs-material", "mkdocstrings-python", "mike"]
3231
lint = ["black", "flake8-pyproject", "mypy", "pre-commit"]
3332
test = ["pytest", "pytest-cov"]
34-
dev = ["thehive4py[audit, lint, test, build, docs]"]
33+
dev = ["thehive4py[audit, lint, test, build, docs]", "nox"]
3534

3635
[tool.setuptools.packages.find]
3736
include = ["thehive4py*"]

0 commit comments

Comments
 (0)