Skip to content

hotenov/hotmodern-python

Repository files navigation

PyPI Tests codecov.io Docs

hotmodern-python

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)

Notes for Windows host

Functions with temp file on Windows

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()

Run Nox sessions with pyenv's Python versions

Option A

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

Option B

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

About

My repo for learning Python based on blog series 'Hypermodern Python' (by Claudio Jolowicz). Repeated with an effort on Windows host (with pyenv and poetry)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages