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

Note this is available in tox as requires = ..., but before PEP 723 there wasn't a clean way to do this for nox.

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 6 times, most recently from 588320d to dd0c6a0 Compare November 13, 2024 03:34
@henryiii henryiii added the awaiting review Needs a review label Nov 14, 2024
fix: version based on pipx

fix: subprocess on Windows

fix: uv or virtualenv, test

fix: windows

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

fix: resolve nox path on Windows

chore: update for recent linting/typing additions

Signed-off-by: Henry Schreiner <[email protected]>
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