-
-
Notifications
You must be signed in to change notification settings - Fork 151
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
Add ability for many nox tasks to reuse the same session/virtual env #167
Comments
I think a way of doing this would be using https://nox.readthedocs.io/en/stable/config.html#nox.sessions.Session.posargs, of course you'll lose the feature of listing sessions ( Also, maybe #72 is more useful here? |
Maybe doing this from the command line? Like |
Are there plans to implement this? I'd be happy to work on it and create a feature PR. |
Go for it! Let us know if you need help.
…On Fri, Jan 10, 2020, 6:37 PM Marko Paunovic ***@***.***> wrote:
Are there plans to implement this? I'd be happy to work on this and create
a PR.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#167>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB5I43APPEA33IG5BFJNLDQ5EBCDANCNFSM4GYEQ5TA>
.
|
A related approach that would save time around environment creation/reuse is #265. |
I like the solution proposed at #286 (comment) |
I also like the solution proposed at #286 (comment). Just a quick thought, you can use "notify" to simulate some parts of this, with some caveats:
This could then be used as below. The first invocation will only create that shared virtual environment since the other two only notify that one, which will be ignored since each session can only run once. The second two only "lint" or only "format" the code. But only one could be done on each invocation of Nox.
This obviously isn't a very great solution, but just something that came to mind. I'd certainly like to get the proper solution implemented. |
Hi all! There is an implementation of this over on #631 (comment). It would be great to get some feedback there. |
FYI, this was the syntax I came up with thinking about this before reading the issues: import nox
@nox.env(python="3.6")
def all_tests(session):
session.install('-rrequirements.txt')
session.install('-rrequirements_test.txt')
session.install('-rrequirements_docs.txt')
session.install('-rrequirements_dist.txt')
@all_tests.session()
def build_docs(session):
session.run('sphinx-build', 'source', 'build/html')
@all_tests.session()
def pylint(session):
session.run("pylint", "code")
@all_tests.session()
def yapf(session):
session.run("yapf", "-r", "-d", "code") You could even pass a restricted session in this case that wouldn't allow install in the sessions to reduce potential for order dependent behavior. I assume this is quite a bit of work, just putting down what I though of. |
After some consideration, we're in the process of adopting Nox for https://github.com/spyder-ide/spyder-docs 1 and potentially many of the other, higher-traffic Spyder-IDE org repositories in the future. On Spyder-Docs, we have only a handful of direct dependencies across all tasks (docs, lint, translate, etc) and have adopted a streamlined workflow with them in a single @Spectre5 's workaround was very helpful in suggesting a viable path forward, and we've made a number of further improvements and optimizations that avoid most of the (non-inherent) limitations of that approach. In particular, we:
Here's what that looks like: import nox
nox.options.sessions = ["run_all"]
nox.options.default_venv_backend = "none"
@nox.session(venv_backend="virtualenv", reuse_venv=True)
def install(session):
session.install("-r", "requirements.txt")
if session.posargs:
for task in session.posargs[0]:
task(session)
def _docs(session):
session.run("python", "-m", "sphinx", "doc/", "doc/_build/html", *session.posargs[1:])
@nox.session
def docs(session):
session.notify("install", posargs=([_docs], *session.posargs))
def _lint(session):
session.run("pre-commit", "run", *session.posargs[1:])
@nox.session
def lint(session):
session.notify("install", posargs=([_lint], *session.posargs))
@nox.session
def run_all(session): session.notify("install", posargs=([_docs, _lint])) You could also even implement a simple @nox.session
def run(session):
funcs_to_run = [globals()[f"_{name}"] for name in session.posargs]
session.notify("install", posargs=[funcs_to_run]) It would then be used like so: $ nox custom -- docs lint A real implementation would want to register each function in an explicit lookup table instead of just relying on arbitrary globals (and add friendlier error handling, of course). Sidenote: An alternate approach I explored in depth would be to use nested private functions with pre-baked posargs, e.g. @nox.session(venv_backend="virtualenv", reuse_venv=True)
def install(session):
session.install("-r", "requirements.txt")
if session.posargs:
for task in session.posargs:
task(session)
@nox.session
def lint(session):
posargs = session.posargs
def _docs(session):
session.run("pre-commit", "run", *posargs)
session.notify("install", posargs=[_docs]) However, due to the private nested, pre-baked functions it doesn't work with Footnotes
|
How would this feature be useful?
On windows its slow to build a new environment, having to build identical environments seems a waste.
Describe the solution you'd like
reuse is the new "function"
Describe alternatives you've considered
Havent found an easy way to reuse environments.
The text was updated successfully, but these errors were encountered: