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
Merged

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

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 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
Collaborator

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
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 commented Sep 20, 2017

Looking into the coverage failures...

@pfmoore
Copy link
Contributor Author

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
Collaborator

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 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
Collaborator

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
Collaborator

Thank you so much for doing this @pfmoore! 🍰

@theacodes
Copy link
Collaborator

All good. Merging. :)

@theacodes theacodes merged commit 95863f7 into wntrblm:master Sep 20, 2017
@pfmoore
Copy link
Contributor Author

pfmoore commented Sep 20, 2017

Glad to help 😄

@dhermes
Copy link
Collaborator

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonparrott Should this be a None-check?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done #59

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

- Using single quotes instead of double quotes
- Adding Args/Returns section to docstring
theacodes pushed a commit that referenced this pull request 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 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
Collaborator

theacodes commented Oct 9, 2017 via email

@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
Development

Successfully merging this pull request may close these issues.

3 participants