Replace "safety" with "deps-audit"
`safety check` is deprecated. We use `pip-audit` instead, fed with the hashed dependencies exported from uv.lock. We ignore the known vulnerabilities in `black` v25 for now.
This commit is contained in:
parent
60aa7911d2
commit
6d2578ef80
1 changed files with 54 additions and 16 deletions
70
noxfile.py
70
noxfile.py
|
|
@ -284,29 +284,47 @@ def test(session):
|
||||||
session.run('xdoctest', '--quiet', *args) # --quiet => less verbose output
|
session.run('xdoctest', '--quiet', *args) # --quiet => less verbose output
|
||||||
|
|
||||||
|
|
||||||
@nox.session(python=MAIN_PYTHON)
|
@nox.session(name='deps-audit', python=MAIN_PYTHON, reuse_venv=False)
|
||||||
def safety(session):
|
def audit_pinned_dependencies(session: Session) -> None:
|
||||||
"""Check the dependencies for known security vulnerabilities."""
|
"""Check dependencies for vulnerabilities with `pip-audit`.
|
||||||
|
|
||||||
|
The dependencies are all those pinned in the uv.lock file.
|
||||||
|
|
||||||
|
`pip-audit` uses the Python Packaging Advisory Database,
|
||||||
|
see https://github.com/pypa/advisory-database for details.
|
||||||
|
"""
|
||||||
|
do_not_accept_arguments(session)
|
||||||
|
do_not_reuse(session) # Explicit guard in case `reuse_venv=False` above is removed
|
||||||
|
|
||||||
start(session)
|
start(session)
|
||||||
|
|
||||||
# We do not pin the version of `safety` to always check with
|
# `pip-audit` is not pinned to always check with its latest version
|
||||||
# the latest version. The risk this breaks the CI is rather low.
|
session.install('pip-audit')
|
||||||
session.install('safety')
|
|
||||||
|
|
||||||
with tempfile.NamedTemporaryFile() as requirements_txt:
|
with tempfile.NamedTemporaryFile(suffix='.txt') as requirements_txt:
|
||||||
session.run(
|
session.run(
|
||||||
'poetry',
|
'uv',
|
||||||
'export',
|
'export',
|
||||||
'--dev',
|
'--all-extras',
|
||||||
'--format=requirements.txt',
|
'--all-groups',
|
||||||
f'--output={requirements_txt.name}',
|
'--locked',
|
||||||
external=True,
|
'--no-emit-project',
|
||||||
|
'--quiet',
|
||||||
|
f'--output-file={requirements_txt.name}',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
session.run('pip-audit', '--version')
|
||||||
session.run(
|
session.run(
|
||||||
'safety',
|
'pip-audit',
|
||||||
'check',
|
'--cache-dir=.cache/pip-audit',
|
||||||
f'--file={requirements_txt.name}',
|
'--disable-pip',
|
||||||
'--full-report',
|
'--progress-spinner=off',
|
||||||
|
f'--requirement={requirements_txt.name}',
|
||||||
|
'--strict',
|
||||||
|
# TODO: Remove these ignores once we upgrade to `black` v26
|
||||||
|
'--ignore-vuln=PYSEC-2026-2120',
|
||||||
|
'--ignore-vuln=PYSEC-2026-2121',
|
||||||
|
'--ignore-vuln=CVE-2026-114134',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -477,6 +495,26 @@ def clean_pwd(session):
|
||||||
session.run('rm', '-rf', path)
|
session.run('rm', '-rf', path)
|
||||||
|
|
||||||
|
|
||||||
|
def do_not_accept_arguments(session: Session, *, raise_error: bool = True) -> None:
|
||||||
|
"""Do not accept any `session.posargs`."""
|
||||||
|
if session.posargs:
|
||||||
|
msg = 'be run without any positional arguments behind the "--"'
|
||||||
|
if raise_error:
|
||||||
|
session.error(f'Must {msg}')
|
||||||
|
else:
|
||||||
|
session.warn(f'Should {msg}')
|
||||||
|
|
||||||
|
|
||||||
|
def do_not_reuse(session: Session, *, raise_error: bool = True) -> None:
|
||||||
|
"""Do not reuse a session with the "-r" flag."""
|
||||||
|
if session._runner.venv._reused:
|
||||||
|
msg = 'be run without the "-r" and "-R" flags'
|
||||||
|
if raise_error:
|
||||||
|
session.error(f'Must {msg}')
|
||||||
|
else:
|
||||||
|
session.warn(f'Should {msg}')
|
||||||
|
|
||||||
|
|
||||||
def start(session: Session) -> None:
|
def start(session: Session) -> None:
|
||||||
"""Show generic info about a session."""
|
"""Show generic info about a session."""
|
||||||
if session.posargs:
|
if session.posargs:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue