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

Support indicating that a command *is* an install command #761

Closed
Julian opened this issue Feb 11, 2024 · 4 comments · Fixed by #770
Closed

Support indicating that a command *is* an install command #761

Julian opened this issue Feb 11, 2024 · 4 comments · Fixed by #770

Comments

@Julian
Copy link
Contributor

Julian commented Feb 11, 2024

How would this feature be useful?

nox supports --no-install and -R options for not running installation commands, usually for use when reusing existing environments, and to speed up development where the install process is often the long pole.

But there doesn't seem to be a good way to indicate when something run via session.run is an install command -- specifically, if you're installing something not via pip or conda etc, which you may want to skip in the same scenarios as the above.

Concretely -- given a Javascript project, one might run (p)npm install to install all the project dependencies, followed by some test runner, e.g. jest, all under a noxenv called ui-tests.

In this scenario it would be nice if nox -s ui-tests -R was able to not run the install command, but the existing -R of course has no way to know which command to skip.

Even doing this externally (in the noxfile) seems nontrivial, as it seems the way session.install does this is by accessing private internals, e.g.:

nox/nox/sessions.py

Lines 629 to 630 in 5c82dc5

if self._runner.global_config.no_install and venv._reused:
return None

Describe the solution you'd like

Add a session.run_install(...) command which runs a subprocess but assumes that subprocess is an installation command which will be skipped when using -R / --no-install.

Refactoring session.install and session.conda_install to call this to do their no_install check seems also like a nice minor internal refactor.

Describe alternatives you've considered

I personally don't like boolean flags (as a rule), but session.run(..., is_install=True) is an alternative for those who are less averse.

A further alternative is to make more things public API (e.g. whether no_install is active) so that someone can do this themselves in their noxfile, but given that nox itself has 2 places where it itself wants this, it seems like something generally useful to me.

Anything else?

A concrete noxfile where I wanted this functionality is here.

@cjolowicz
Copy link
Collaborator

This already exists, but for historic reasons it's called session.run_always. It keeps tripping up people. IMO we should alias this to session.run_install, keeping the old name for compatibility.

@Julian
Copy link
Contributor Author

Julian commented Feb 12, 2024

Huh, I swear I saw run_always and for some reason thought it still wasn't the right thing, but looking at it again it does indeed look like you're right!

I understand the history I think, there was only a --install-only original right, and so this was "run in that case too" hence the "always" -- but yeah the name seems really unfortunate now.

@henryiii
Copy link
Collaborator

So .run_always does not run if installs are skipped, only .run is run?

@Julian
Copy link
Contributor Author

Julian commented Feb 19, 2024

Yup. On main of my repo all works as expected using it, though I'm going to likely alias it directly in my noxfile to remove the confusion.

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

Successfully merging a pull request may close this issue.

3 participants