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

Locate the Python interpreter via the py.exe launcher #53

Merged
merged 6 commits into from Sep 20, 2017

Conversation

@pfmoore
Copy link
Contributor

@pfmoore pfmoore commented Sep 19, 2017

On Windows, if the default strategy for finding a versioned interpreter fails, ask the py.exe launcher to locate it for us.

@pfmoore
Copy link
Contributor Author

@pfmoore pfmoore commented Sep 19, 2017

Some outstanding questions:

  • Does this need tests? It probably should, but the existing tests say "Not testing multiple interpreters on Windows" and I can see why - it's going to be quite hard to test this without mocking a lot of stuff (and possibly reqriting some of the code to make it more testable)
  • Should this check replace the existing hard-coded list of interpreters? In theory, it's more reliable and the py.exe launcher should always be present.
  • If we do keep both approaches, should the default list or the py.exe check be first?

@theacodes
Copy link
Owner

@theacodes theacodes commented Sep 19, 2017

Thank you so much for doing this, @pfmoore!

Does this need tests? It probably should, but the existing tests say "Not testing multiple interpreters on Windows" and I can see why - it's going to be quite hard to test this without mocking a lot of stuff (and possibly reqriting some of the code to make it more testable)

I can handle this - it's likely we'll need to mock some stuff for coverage purposes but have a real test for when on an actual windows platform.

Should this check replace the existing hard-coded list of interpreters? In theory, it's more reliable and the py.exe launcher should always be present.

I think so, yes.

If we do keep both approaches, should the default list or the py.exe check be first?

Let's just drop the old method.

"""
ver = "-%s.%s" % (v_maj, v_min)
script = "import sys; print(sys.executable)"
py_exe = distutils.spawn.find_executable('py')
Copy link
Owner

@theacodes theacodes Sep 19, 2017

TIL about distutils.spawn.find_executable! Should we use that over py.path.local.sysfind which we use in command?

Copy link
Contributor Author

@pfmoore pfmoore Sep 19, 2017

Honestly, I doubt it matters (I lifted that code from tox unchanged). I'd be inclined to go for consistency and follow current practice by using py.path.local.sysfind in both places. I'll change this.

(BTW, there's also shutil.which in Python 3.3+. Who said "one obvious way"? 😄)

Copy link
Owner

@theacodes theacodes Sep 19, 2017

(BTW, there's also shutil.which in Python 3.3+. Who said "one obvious way"? 😄)

I'd love to make nox 3+ only. Sigh.

Copy link
Contributor Author

@pfmoore pfmoore Sep 19, 2017

I'll also make the change to drop the old approach, as noted in your other comment. I can do the tests too, if you want, but if you have a preferred style/approach for the tests and would rather cover that yourself, that's fine too.

Copy link
Owner

@theacodes theacodes Sep 19, 2017

We use pytest so as long as it's not terribly different from what's there go for it. :)

@pfmoore
Copy link
Contributor Author

@pfmoore pfmoore commented Sep 20, 2017

Looking into the coverage failures...

@pfmoore pfmoore force-pushed the win_interpreter_via_launcher branch from 43724a7 to 6d26c83 Sep 20, 2017
@pfmoore
Copy link
Contributor Author

@pfmoore pfmoore commented Sep 20, 2017

There's a remaining coverage failure - line 153 in nox/virtualenv.py:

        if self.interpreter:
            cmd.extend(['-p', self._resolved_interpreter])

I'm not sure why the changes I've made would have caused this line to no longer be executed. @jonparrott do you have any suggestions?

@theacodes
Copy link
Owner

@theacodes theacodes commented Sep 20, 2017

I'm not sure why the changes I've made would have caused this line to no longer be executed. @jonparrott do you have any suggestions?

It's my fault, you can disregard that coverage issue.

@pfmoore
Copy link
Contributor Author

@pfmoore pfmoore commented Sep 20, 2017

I like that sort of answer ;-) In which case I think this is good to go. Could you check it over for me?

@theacodes
Copy link
Owner

@theacodes theacodes commented Sep 20, 2017

LGTM- I updated the docstring to mention pep 397. I'm gonna wait for CI to merge (I know it'll fail due to coverage, just want to make sure that's the only failure).

@theacodes
Copy link
Owner

@theacodes theacodes commented Sep 20, 2017

Thank you so much for doing this @pfmoore! 🍰

@theacodes
Copy link
Owner

@theacodes theacodes commented Sep 20, 2017

All good. Merging. :)

@theacodes theacodes merged commit 95863f7 into theacodes:master Sep 20, 2017
1 of 2 checks passed
@pfmoore
Copy link
Contributor Author

@pfmoore pfmoore commented Sep 20, 2017

Glad to help 😄

@dhermes
Copy link
Collaborator

@dhermes dhermes commented Sep 20, 2017

🎉 Yay Windows!

"""
script = "import sys; print(sys.executable)"
py_exe = py.path.local.sysfind('py')
if py_exe:
Copy link
Collaborator

@dhermes dhermes Sep 20, 2017

@jonparrott Should this be a None-check?

Copy link
Owner

@theacodes theacodes Sep 20, 2017

Possibly. If you want you can send a follow-up PR.

Copy link
Collaborator

@dhermes dhermes Sep 20, 2017

Done #59

dhermes added a commit to dhermes/nox that referenced this issue Sep 20, 2017
Follow-up to theacodes#53. Also

- Using single quotes instead of double quotes
- Adding Args/Returns section to docstring
theacodes pushed a commit that referenced this issue Sep 20, 2017
* Adding None-check to `locate_via_py`.

Follow-up to #53. Also

- Using single quotes instead of double quotes
- Adding Args/Returns section to docstring

* Updating unit test mocks: faithfully mock `sysfind`.
@dhermes
Copy link
Collaborator

@dhermes dhermes commented Oct 9, 2017

BTW I am living life happily in Windows land and I can confirm this PR works great (and nox was broken-ish before I pip install git+https://github.com/jonparrott/nox/)

@theacodes
Copy link
Owner

@theacodes theacodes commented Oct 9, 2017

@dhermes dhermes mentioned this pull request Oct 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants