|
7 | 7 |
|
8 | 8 |
|
9 | 9 | import platform |
| 10 | +import re |
10 | 11 | from pathlib import Path |
11 | 12 |
|
12 | 13 | import nox |
@@ -39,8 +40,24 @@ def check_poetry(session: Session) -> None: |
39 | 40 | """Check whether Poetry is correctly configured.""" |
40 | 41 | session.run("poetry", "check", "--no-interaction", external=True) |
41 | 42 |
|
| 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 |
42 | 60 |
|
43 | | -# @session # uncomment this line to only run on the current python interpreter |
44 | 61 | @session(python=python_versions_to_test) # missing versions can be installed with `pyenv install ...` |
45 | 62 | # do not forget check / set the versions with `pyenv global`, or `pyenv local` in case of virtual environment |
46 | 63 | def tests(session: Session) -> None: |
|
0 commit comments