-
-
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
Pass positional arguments to specific sessions #391
Comments
I'm kinda neutral on this. I don't want to complicate Nox's invocations any further, but I can also see the utility in this. I also pathologically avoid long command invocations since it's easy to forget them. I think an alternative I might prefer is to have a session that runs the others with the args: @nox.session
def something(session):
session.notify("run_pytest", "--no-cov", "--headless")
session.notify("build_sphinx_docs", "--doctest") We'd have to modify |
That seems reasonable. Like you said, most people aren't going to remember commands with many arguments. However when it's required, those commands are usually codified in a dedicated script. This |
Cool, I think that should be a rather straightforward change, so if someone
wants to take it on, go for it!
…On Sat, Feb 27, 2021, 12:56 PM Ryan Morshead ***@***.***> wrote:
That seems reasonable. Like you said most people aren't usually going to
remember commands with many arguments. However when it's required, those
commands are usually codified in a dedicated script. This notify idea
mimics that rather nicely and would solve my use case.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#391 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB5I47Z2NWRANDB6VBLDY3TBEW33ANCNFSM4YJDVLWA>
.
|
I have a similar, yet different use case, where I'd like to avoid passing What would you think about giving FWIW, the code below shows my use case and current workaround. There are two @nox.session(python=python_versions)
def tests(session):
session.install(".", "coverage[toml]", "pytest")
try:
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
finally:
if session.interactive:
session.notify("coverage")
@nox.session
def coverage(session):
# Do not use session.posargs unless this is the only session.
has_args = session.posargs and len(session._runner.manifest) == 1
args = session.posargs if has_args else ["report"]
session.install("coverage[toml]")
if not has_args and any(Path().glob(".coverage.*")):
session.run("coverage", "combine")
session.run("coverage", *args) Using what's proposed above, this could be rewritten like this: @nox.session(python=python_versions)
def tests(session):
...
finally:
if session.interactive:
session.notify("coverage", posargs=[])
@nox.session
def coverage(session):
args = session.posargs if session.posargs else ["report"]
... |
Sounds good to me. |
@theacodes I'm not seeing how |
Would it make sense to give |
The Problem
One issue with the way positional arguments work right now is that they are shared between all sessions.
--debug
flag could be a piece of global information that all sessions would want to know about.session.run
command that do not concern the other sessions.Here's a more concrete example...
Imagine that I have two sessions
run_pytest
and another calledbuild_sphinx_docs
. I want to pass extra arguments topytest
when running tests in the first session, and I want to pass arguments tosphinx
when building the documentation.nox -- --debug --no-cov --headless --doctest # ^global ^pytest ^pytest ^sphinx
Presently if I want to do this I have to devise a custom solution for parsing which arguments belong to which session. It would be great if I could specify which arguments belong to which session. Something like:
My Current Solution
In my own projects I created a simple utility to solve the problem described above. Admittedly though my implementation isn't perfect though and could probably use some refinement to make it work in most or all use cases. Here it is though:
And would be used in a
noxfile.py
like this:With usage at the command line looking a bit like this:
One thing I like about the way this works is that I can drop the specificity if I'm only running one session:
These positional arguments are now "global", but because I'm only running one session that doesn't matter, and
get_posargs
gracefully handles that.The text was updated successfully, but these errors were encountered: