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

Draft
wants to merge 2 commits 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.

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.
I also need to check Windows, pipx doesn't use process replacement there; the original PR said it "wasn't reliable" for pipx. Not sure about us. pypa/pipx#531 The Python docs seem to indicate it's not as fancy there, but it seems like it should work. Edit: it doesn't. :)

Fix #414.

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

fix: version based on pipx

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

fix: subprocess on Windows

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

fix: uv or virtualenv, test

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

fix: windows

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

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

fix: resolve nox path on Windows

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Have noxfile.py install dependencies for itself
1 participant