Skip to content

Safe wheel import #905

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

Merged
merged 4 commits into from
Jul 3, 2019
Merged

Conversation

chrisjbremner
Copy link
Contributor

@chrisjbremner chrisjbremner commented Jul 2, 2019

What does this implement/fix? Explain your changes.

I upgraded from 2.3.0 to 2.4.0 today, which seems to include the addition of a wheel import in the setup.py file. I am trying to install my own package that includes pythonnet on a machine that does not typically have wheel installed, therefore, I have to include wheel in my install_requires file. The line looks like this, note that I have put wheel first to install it before pythonnet:

install_requires = ["wheel", "pythonnet==2.4.0"]  # pythonnet v2.4.0 requires wheel

Unfortunately, this still fails due to pip collecting all the packages first, which calls python setup.py egg_info for pythonnet, before wheel is installed (which occurs after all package collection is complete):

Collecting wheel (from mypackage)
Downloading pythonnet-2.4.0 (1.8MB)
100% \|████████████████████████████████\| 1.9MB 45.9MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "", line 1, in
    File "/tmp/pip-install-fvrk22zh/pythonnet/setup.py", line 18, in
      from wheel import bdist_wheel

ModuleNotFoundError: No module named 'wheel'

To resolve this, I put the wheel import inside of a try/except, so that it doesn't fail while collecting the package, and would only fail if I tried to call bdist_wheel if I didn't have wheel installed.

Here's an example of another setup.py file that also try/excepts around the import of wheel when setting up the cmdclass dictionary.

And a blog post that describes a similar try/except pattern near the bottom.
...

Does this close any currently open issues?

No
...

Any other comments?

...

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

@filmor
Copy link
Member

filmor commented Jul 3, 2019

Can you check whether it suffices to drop the filter in the requirements.txt?

@chrisjbremner
Copy link
Contributor Author

Isn't the requirements.txt just for development/deployment purposes? If I install it via pypi it doesn't make use of requirements.txt, so it doesn't seem like dropping the filter would resolve the issue?

@codecov-io
Copy link

Codecov Report

Merging #905 into master will decrease coverage by 0.1%.
The diff coverage is 89.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #905      +/-   ##
==========================================
- Coverage   76.35%   76.25%   -0.11%     
==========================================
  Files          65       65              
  Lines        6023     6030       +7     
  Branches      990      990              
==========================================
- Hits         4599     4598       -1     
- Misses       1090     1099       +9     
+ Partials      334      333       -1
Flag Coverage Δ
#setup_linux 65.44% <57.89%> (+0.14%) ⬆️
#setup_windows 75.48% <89.47%> (-0.11%) ⬇️
Impacted Files Coverage Δ
setup.py 86.71% <89.47%> (-0.37%) ⬇️
src/runtime/delegatemanager.cs 81.96% <0%> (-4.92%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df0574d...16dcc1d. Read the comment docs.

@filmor filmor merged commit 93968d2 into pythonnet:master Jul 3, 2019
@filmor
Copy link
Member

filmor commented Jul 3, 2019

Yeah, I got a bit confused because I stumbled over this recently when testing something on a Linux machine where wheel wasn't installed by pip from the requirements file.

Anyways, thank you very much for your contribution :)

@chrisjbremner chrisjbremner deleted the safe_wheel_import branch July 3, 2019 22:45
@chrisjbremner
Copy link
Contributor Author

Thanks for the speedy review! What's the process for requesting a minor version bump/release? Is there anything I could help with?

@filmor
Copy link
Member

filmor commented Jul 4, 2019

There is no process as of now. I'll have a look whether I can do a quick 2.4.1 this month, there were a few improvements over 2.4.0 already.

@chrisjbremner
Copy link
Contributor Author

Great, thank you!

@chrisjbremner
Copy link
Contributor Author

@filmor any update on whether a 2.4.1 release is possible? Thanks!

AlexCatarino pushed a commit to QuantConnect/pythonnet that referenced this pull request Jun 18, 2020
Only allow wheel commands if wheel is installed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants