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

Session attributes to represent the state of reuse-existing-virtualenvs and no-install #710

Open
MicaelJarniac opened this issue May 12, 2023 · 0 comments

Comments

@MicaelJarniac
Copy link
Contributor

How would this feature be useful?

Sometimes, it might be useful to know the state of reuse-existing-virtualenvs and no-install, for example, to skip some run actions.

In my case, I want to run mypy --non-interactive --install-types when it's creating new virtualenvs and installing dependencies, but I want to run just mypy when it's reusing virtualenvs and not installing dependencies.

I can use run_always to have mypy --non-interactive --install-types run only when it's installing dependencies, but I couldn't find a way to then have mypy not run (other than running with --install-only), so if it's also installing dependencies, it'll end up running Mypy twice.

# noxfile.py
import nox

python_versions = ["3.9", "3.10", "3.11"]
constraints = ("-c", "constraints.txt")

@nox.session(python=python_versions)
def type_check_code(session: nox.Session) -> None:
    session.install(*constraints, ".[dev]")

    session.run_always("mypy", "--non-interactive", "--install-types")
    session.run("mypy")

Describe the solution you'd like

I'd like there to be session.reuse_existing_virtualenvs, session.no_install and session.install_only attributes that would represent the state of the --reuse-existing-virtualenvs, --no-install, and --install-only flags, respectively.

In my case, this would allow me to do the following:

# noxfile.py
import nox

python_versions = ["3.9", "3.10", "3.11"]
constraints = ("-c", "constraints.txt")

@nox.session(python=python_versions)
def type_check_code(session: nox.Session) -> None:
    session.install(*constraints, ".[dev]")

    if session.no_install:
        session.run("mypy")
    else:
        session.run_always("mypy", "--non-interactive", "--install-types")

Describe alternatives you've considered

No response

Anything else?

It might be useful to also have other flags represented by attributes. They could also be inside a session.flags object, like session.flags.no_install, to keep them more organized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant