My Python learning project by article series 'Hypermodern Python' (by Claudio Jolowicz)
This repo 98% repeats code from these articles with little improvements for Windows environment and except several components (pre-commit, pytype, typeguard, Release Drafter)
Windows has security limitation for temp files: OS does not allow processes other than the one used to create the NamedTemporaryFile to access the file (from here)
That's why I modified code like this:
# noxfile.py
import pathlib
def install_with_constraints(session: Session, *args: str, **kwargs: Any) -> None:
"""Install packages constrained by Poetry's lock file."""
with tempfile.NamedTemporaryFile(delete=False) as requirements:
session.run(
"poetry",
"export",
...
)
session.install(f"--constraint={requirements.name}", *args, **kwargs)
pathlib.Path(requirements.name).unlink()
Use Nox CLI argument --extra-pythons
and full paths to desired version of Python interpreter
Example:
nox --extra-pythons "C:\users\winfan\.pyenv\pyenv-win\versions\3.8.2\python.exe" "C:\users\winfan\.pyenv\pyenv-win\versions\3.9.2\python.exe"
will run all sessions with Python specified in noxfile.py (or skip if not found)
and with all Pythons passed in this command.
See detailed explanation how --extra-pythons
and --extra-python
works from Claudio Jolowicz himself
Create separate noxfile for local execution. Duplicate all sessions and change python versions like this:
# noxfile.local.py
@nox.session(
python=[
r"C:\users\winfan\.pyenv\pyenv-win\versions\3.8.2\python.exe",
r"C:\users\winfan\.pyenv\pyenv-win\versions\3.9.2\python.exe",
],
reuse_venv=True,
)
Then run command in your Terminal nox -f noxfile.local.py
Don't forget to add this file to .gitignore