Skip to content

Commit 60cda1a

Browse files
committed
Added warning in case of outdated dependencies in development environment
1 parent 9542144 commit 60cda1a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

noxfile.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
import platform
10+
import re
1011
from pathlib import Path
1112

1213
import nox
@@ -39,8 +40,24 @@ def check_poetry(session: Session) -> None:
3940
"""Check whether Poetry is correctly configured."""
4041
session.run("poetry", "check", "--no-interaction", external=True)
4142

43+
@session # to only run on the current python interpreter
44+
def check_development_environment(session: Session) -> None:
45+
"""Check whether the development environment is up to date with the dependencies, and try to update if necessary."""
46+
output: str = session.run("poetry", "install", "--sync", "--dry-run", "--with", "test", silent=True, external=True)
47+
match = re.search(r"Package operations: (\d+) installs, (\d+) updates, (\d+) removals, \d+ skipped", output)
48+
assert match is not None
49+
groups = match.groups()
50+
installs, updates, removals = int(groups[0]), int(groups[1]), int(groups[2])
51+
if installs > 0 or updates > 0:
52+
# packages = re.findall(r"• Installing .* | • Updating .*", output, flags=re.MULTILINE)
53+
# assert packages is not None
54+
session.warn(f"""
55+
Your development environment is out of date ({installs} installs, {updates} updates).
56+
Update with 'poetry install --sync', using '--with' and '-E' for optional dependencies, extras respectively.
57+
Note: {removals} packages are not in the specification (i.e. installed manually) and may be removed.
58+
To preview changes, run 'poetry install --sync --dry-run' (with optional dependencies and extras).""")
59+
assert False
4260

43-
# @session # uncomment this line to only run on the current python interpreter
4461
@session(python=python_versions_to_test) # missing versions can be installed with `pyenv install ...`
4562
# do not forget check / set the versions with `pyenv global`, or `pyenv local` in case of virtual environment
4663
def tests(session: Session) -> None:

0 commit comments

Comments
 (0)