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

Allow bypassing the install only flag #181

Closed
wants to merge 1 commit into from
Closed

Allow bypassing the install only flag #181

wants to merge 1 commit into from

Conversation

s0undt3ch
Copy link
Contributor

The reason behind this change is because, for our particular use case, we run some code against the virtualenv python in order to choose what requirements to install.
With this change, we can call nox with --install-only which skips all of the session.run calls, with the exception of those for which we explicitly pass bypass_install_only.

@dhermes
Copy link
Collaborator

dhermes commented Apr 19, 2019

This seems unnecessary. You can use session.posargs to pass through your option and then use a return statement in your session.

@dhermes
Copy link
Collaborator

dhermes commented Apr 19, 2019

You could also subclass Session and override install

@s0undt3ch
Copy link
Contributor Author

You're missing the point. It has nothing to do with posargs.

Nox is responsible to install dependencies.
We lock dependencies based on python version and distro.
We need to know what's the python version on the virtualenv to install the right dependencies, and for that we get sys.version_info from the virtualenv's python, through a session.run.
If we can't know the version info, we can't install the right set of dependencies, hence, the proposed bypass.

@dhermes
Copy link
Collaborator

dhermes commented Apr 19, 2019

If you want to know the currently running Python:

@nox.session(py=("3.7", ...))
def foo(session):
    interpreter = session.virtualenv.interpreter
    ...

You can also scope requirements to specific Python versions with environment markers in a requirements.txt:

SomeProject == 5.4 ; python_version < '2.7'
OtherProject; sys_platform == 'win32'

Sorry for the misunderstanding. I was trying to say you could use posargs to achieve the same effect.

@s0undt3ch
Copy link
Contributor Author

I'm not creating PRs just because...

I know I can get the python version from there, but our goal is to make our users life easier, so, we also have 2 and 3 as valid python versions(thus nox sessions too), but we lock our requirements against the python major AND minor version information.
So that won't work.

@s0undt3ch
Copy link
Contributor Author

@nox.session(py=("2", ...))
def foo(session):
    interpreter = session.virtualenv.interpreter
    print(interpreter)
    ...
❯ nox -e 'runtests-zeromq-2(coverage=False)' -- -v --proxy
nox > Running session runtests-zeromq-2(coverage=False)
nox > Creating virtualenv using python2 in /home/vampas/projects/SaltStack/salt/branches/2017.7.9/.nox/runtests-zeromq-2-coverage-false
nox > Session runtests-zeromq-2(coverage=False) was successful.
nox > Running session runtests-parametrized-2(coverage=False, crypto=None, transport='zeromq')
nox > Creating virtualenv using python2 in /home/vampas/projects/SaltStack/salt/branches/2017.7.9/.nox/runtests-parametrized-2-coverage-false-crypto-none-transport-zeromq
2

notice the above lonely 2...

@theacodes
Copy link
Collaborator

Yeah this is too far. I don't like the idea of an argument that reverses a flag that itself reverses an argument.

It's just Python, you can use nox.command.run directly or use subprocess with session.virtualenv.bin if you need to here.

@theacodes theacodes closed this Apr 23, 2019
@s0undt3ch
Copy link
Contributor Author

Your suggestions mean recreating the logic nox has on the noxfile or don't use nox at all(subprocess), that defeats the purpose of having nox to help out setting up the virtualenv...

@theacodes
Copy link
Collaborator

theacodes commented May 22, 2019

I think for now this still just doesn't appeal to my sensibilities. Another alternative is to use session arguments to do what you want:

@nox.session
def thing(session):
     if "setup-only" in session.posargs:
         ...
     else:
         ...

Or have a shared session like:

@nox.session
def setup(sesssion):
    ...

@nox.session
def thing(session)
    setup(session)
    ...

Happy to revisit this later as "no is temporary, but yes is forever" - https://twitter.com/solomonstre/status/715277134978113536?lang=en

s0undt3ch added a commit to s0undt3ch/salt that referenced this pull request Jun 14, 2019
To get some information from the system, which we then use to choose the
appropriate static requirements file, we need to run some commands,
something that nox will refuse to do if `--install-only` is passed.

We work around it by manually patching the value of
`session._runner.global_config.install_only` for the commands that we
MUST run, and only those and then we set it back to the value it had
before.

For additional information about why we have to do this, please see:
   wntrblm/nox#181
s0undt3ch added a commit to s0undt3ch/salt that referenced this pull request Jun 14, 2019
To get some information from the system, which we then use to choose the
appropriate static requirements file, we need to run some commands,
something that nox will refuse to do if `--install-only` is passed.

We work around it by manually patching the value of
`session._runner.global_config.install_only` for the commands that we
MUST run, and only those and then we set it back to the value it had
before.

For additional information about why we have to do this, please see:
   wntrblm/nox#181
s0undt3ch added a commit to s0undt3ch/salt that referenced this pull request Jun 14, 2019
To get some information from the system, which we then use to choose the
appropriate static requirements file, we need to run some commands,
something that nox will refuse to do if `--install-only` is passed.

We work around it by manually patching the value of
`session._runner.global_config.install_only` for the commands that we
MUST run, and only those and then we set it back to the value it had
before.

For additional information about why we have to do this, please see:
   wntrblm/nox#181
s0undt3ch added a commit to s0undt3ch/salt that referenced this pull request Jun 17, 2019
To get some information from the system, which we then use to choose the
appropriate static requirements file, we need to run some commands,
something that nox will refuse to do if `--install-only` is passed.

We work around it by manually patching the value of
`session._runner.global_config.install_only` for the commands that we
MUST run, and only those and then we set it back to the value it had
before.

For additional information about why we have to do this, please see:
   wntrblm/nox#181
s0undt3ch added a commit to s0undt3ch/salt that referenced this pull request Jun 17, 2019
To get some information from the system, which we then use to choose the
appropriate static requirements file, we need to run some commands,
something that nox will refuse to do if `--install-only` is passed.

We work around it by manually patching the value of
`session._runner.global_config.install_only` for the commands that we
MUST run, and only those and then we set it back to the value it had
before.

For additional information about why we have to do this, please see:
   wntrblm/nox#181
s0undt3ch added a commit to s0undt3ch/salt that referenced this pull request Jun 17, 2019
To get some information from the system, which we then use to choose the
appropriate static requirements file, we need to run some commands,
something that nox will refuse to do if `--install-only` is passed.

We work around it by manually patching the value of
`session._runner.global_config.install_only` for the commands that we
MUST run, and only those and then we set it back to the value it had
before.

For additional information about why we have to do this, please see:
   wntrblm/nox#181
johnclyde pushed a commit to johnclyde/salt that referenced this pull request Aug 5, 2019
To get some information from the system, which we then use to choose the
appropriate static requirements file, we need to run some commands,
something that nox will refuse to do if `--install-only` is passed.

We work around it by manually patching the value of
`session._runner.global_config.install_only` for the commands that we
MUST run, and only those and then we set it back to the value it had
before.

For additional information about why we have to do this, please see:
   wntrblm/nox#181
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants