Skip to main content

Python learning project by blog posts series 'Hypermodern Python' (by Claudio Jolowicz)

Project description

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, typeguard)

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hotmodern-python-0.1.1.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

hotmodern_python-0.1.1-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page