Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support PEP 723 noxfiles #881

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

henryiii
Copy link
Collaborator

@henryiii henryiii commented Oct 31, 2024

I've started #848. This allows you to write a noxfile like this:

# /// script
# dependencies = ["nox>=1.2.3", "numpy"]
# ///

import nox
import numpy

@nox.session
def example(session: nox.Session) -> None:
    print(numpy.__file__)

Any dependencies, including version ranges and nox, will be checked. If not satisfied, nox will make a new .nox/_nox_script_mode environment, set it up with the above dependencies, and then pass control to the new nox environment. Requires-python is not respected yet, might need #814. That can be added later, not a target for this PR.

I've allowed this to be passed via flag and envvar, but envvar always comes first, and overrides the flag. This ensures the second run will never trigger a third run of nox. If someone has other ideas for ways to ensure this, I'm open. Also, the envvar is needed if you request an older nox, since the flag won't be valid in the "inner" run. --script-mode=fresh allows you to enforce a fresh environment.

It supports both pip and uv; since this is a new feature, defaulted to uv if available, and fallback on pip. Maybe should be configurable; currently it's locked on the "default" is uv|virtualenv.

It's a bit less clever on Windows following pipx's example; pipx doesn't use process replacement there; the original PR said it "wasn't reliable" for pipx. Looks like path quoting is not handled by this method, and it doesn't do anything special on Windows. pypa/pipx#531

Fix #414.

@henryiii henryiii force-pushed the henryiii/feat/pep723full branch 3 times, most recently from c52331d to a834bbe Compare November 5, 2024 15:52
@henryiii henryiii force-pushed the henryiii/feat/pep723full branch 2 times, most recently from 91c4999 to 54dfd70 Compare November 9, 2024 14:48
@henryiii henryiii marked this pull request as ready for review November 9, 2024 14:48
@henryiii henryiii force-pushed the henryiii/feat/pep723full branch 5 times, most recently from 885eb2f to 588320d Compare November 12, 2024 22:12
Signed-off-by: Henry Schreiner <[email protected]>

fix: version based on pipx

Signed-off-by: Henry Schreiner <[email protected]>

fix: subprocess on Windows

Signed-off-by: Henry Schreiner <[email protected]>

fix: uv or virtualenv, test

Signed-off-by: Henry Schreiner <[email protected]>

fix: windows

Signed-off-by: Henry Schreiner <[email protected]>

fix: ignore errors in rmtree (3.8+ should be fine on Windows now)

fix: resolve nox path on Windows

Signed-off-by: Henry Schreiner <[email protected]>
@henryiii henryiii added the awaiting review Needs a review label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review Needs a review
Development

Successfully merging this pull request may close these issues.

Have noxfile.py install dependencies for itself
1 participant