-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
sessions: require a session? #453
Comments
As a short-term work around, it's possible to pass an existing session to your session functions: @nox.session
def parent(session):
require_1(session)
require_2(session)
...
dependent(session)
@nox.session
def require_1(session): ...
@nox.session
def require_2(session): ...
...
@nox.session
def dependent(session): ... This will work so long as your child sessions don't require unique |
Will this deduplicate the slow step, though? I'd like: @nox.session
def build(session):
... # slow
@nox.session(require=[build])
def test1(session):
...
@nox.session(require=[build])
def test2(session):
... To only build once. I can cache on the build manually, though ("has_run = False, global has_run, has_run=True"). has_built = False
@nox.session
def build(session):
global has_built
if not has_built:
... slow
has_built = True
@nox.session
def test1(session):
build(session)
...
@nox.session(require=[build])
def test2(session):
build(session)
... Or does it do the deduplication already? |
I see. No it does not deduplicate. I'm also realizing that instead of calling the functions directly to stop on an error, you could just set Given all that, what if you organized your tasks like this where you would run @nox.session
def test(session):
session.notify(build)
session.notify(test1)
...
session.notify(testN)
@nox.session
def build(...): ...
@nox.session
def test1(...): ...
@nox.session
def testN(...): ... If you commonly found that you only wanted to run a subset of tests you could do: @nox.session
def test(session):
session.notify(build)
for test_name in session.posargs:
session.notify(test_name, posargs=[]) With usage like Given this common re-use of the |
Notify is backwards from what is useful for this sort of situation. I want to say For the workaround above, a user will see all the above sessions, including Is adding a |
Which generator are you using with CMake? Shouldn't that already take care of incremental builds, even across multiple Nox runs? |
I think that to really implement something like Given that, I still think you can accomplish what you're looking for by not making @nox.session(stop_on_first_error=True)
def test(session):
session.notify(build)
for test_name in session.posargs:
test_func = globals()["test_" + test_name]
session.notify(test_func)
def test_1(session): ...
...
def test_n(session): ... You're usage then could simply be One could certainly argue that the use of |
This would be a cool feature! It's not nox but I've used doit for these types of things before and it works quite well. My only complaint is that it's not as nice as nox when printing (no colours in things like pytest output for example). |
See also #167, maybe this is a duplicate ? |
Python 3.9's topological sorter (or a backport package) sounds really useful for something like this! See https://www.youtube.com/watch?v=_O9q3H6mocg for a nice overview. |
Hi all! There is an implementation of this over on #631. It would be great to get some feedback there. |
How would this feature be useful?
Often, especially with building things like binary extensions (which is where I do a lot of work), it is useful to build once and then use the built products (wheels usually, could also be docs) in other sessions. From looking around, it seems like tools like pip currently are just manually running a function that sets up the required produces, and putting that in front of everything that needs it - which is really slow if this is trying to build something.
In the noxfile I'm working on for CMake currently, I'd like to produce the wheel (several minutes) then run an array of tests (all versions of Python) on it, since it doesn't get tied to the current version of Python. But I've also needed this for a "serve" job for docs depending on a "build" job, for different jobs in packages that depend on building a wheel (even if it's only for the current python version), etc.
Describe the solution you'd like
I feel like this is exactly the opposite of
notify
(or whatever it gets renamed to if #398 changes anything rather than just updating the docs). It could berequires=[...]
, which would list session that have to run to completion before this session starts. Sorequires=[build]
would not start this session until the build session completes, and would add "build" to the queue if it is not explicitly requested.A caching system would be amazing, but is orthogonal and not needed to get a benefit for this.
Describe alternatives you've considered
Maybe there's a way to do this that I'm just missing? Happy if there is already a way to do this that I've missed. It can be partially be done by hand, by writing a function that builds an output the first time it's called, and then just does nothing on each subsequent call.
The text was updated successfully, but these errors were encountered: