-
Notifications
You must be signed in to change notification settings - Fork 372
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
Generate .pyc files from .hy files on install #2299
Conversation
08648bc
to
4f725cf
Compare
I don't really know anything about wheels. Is the reason we have to produce version-specific wheels that the compilation has to be done before packaging into a wheel rather than while installing the wheel, because the wheel installation process doesn't allow running any code? |
Also, does the |
4f725cf
to
a5f8e43
Compare
Yup, there's no way to have post-install hooks with wheels, it's essentially just an archive that gets copied into your site-packages. So we have to package the .pyc files into the wheel itself, which means we'll have python-version-specific wheels (since the .pyc files are specific to each python version). Frustratingly enough, pip will compile all .py files to .pyc after a wheel install, but it's a hardcoded check for filenames ending in ".py" and there's no way to hook into it (or anywhere afterwards).
Yup, since the prior call to |
Hmm. What if we just forget about wheels and only provide source distributions? That will simplify things, and there's little advantage to a wheel over a source distribution for a project with no C code like this one, right? |
That also works! If we go that route, then I can just remove |
Okay, sounds good. As I understand the bit with |
a5f8e43
to
eb3fcab
Compare
It isn't strictly necessary; we can have mode always set to |
So why not just leave |
eb3fcab
to
dadf2e0
Compare
...no, no, you're right, that code was only there to make sure that we made hash-based .pycs when pre-packaging wheels. Since we're only supplying sdists from here on out, it's completely redundant (and I ran a couple installs just to double check). |
dadf2e0
to
de9d228
Compare
Thanks. I think this generates and installs the bytecode, but the bytecode isn't being used, at least on my system. I'm on Ubuntu 22.04. Here's what it looks like for me:
Do you find that the files aren't recompiled on your system? |
Ugh, I never tested using
Easy fix is to just compile with I also ran into an additional snafu where if I was installing using Easy fix is to add I'll push these fixes, but I'm also trying to see if there's some not-gross way I can add all of these cases as tests, so CI can catch it if anything breaks down the line. |
de9d228
to
b66c2ba
Compare
The fact that source-file timestamps aren't preserved sounds like a bug in how wheels are implemented, but I guess that's not something we can fix. |
Anyway, this seems to work. Can you update the commit message and add a line to NEWS? Also, you don't need |
b66c2ba
to
5558a32
Compare
I'm worried that make break something arcane; sifting through the setuptools internals, there are a few cases where it uses the name of the command's class for various things. All of the sample code I've seen that overrides setuptools commands use the same |
5558a32
to
3c3587c
Compare
Okay, |
bb9df38
to
1fc85b5
Compare
1fc85b5
to
4b1b130
Compare
Aight I added some tests for checking the generated pyc files after both an sdist install and an install directly from the source folder. They're... really slow, and also potentially require an internet connection (since they'll call I should be able to get to a windows machine by later this week to figure out what's going on there, but everything else is working. ugh I don't know why I keep attempting these weird invasive/internal changes, apparently I'm a glutton for punishment |
I'd say let's not worry about testing. Trying to test this kind of thing automatically, with all the slightly different ways a Python package can be installed, is too messy. |
@scauligi Do you mind if I remove the testing commit and merge this? |
I don't mind; go ahead |
4b1b130
to
c84fb12
Compare
Change setup.py to generate .pyc files from .hy files on install (which will cause setup.py to include them in wheel distributions as well).
Fixes #1747; a similar patch to hyrule's setup.py will fix hylang/hyrule#42. I can't test rpm/deb/etc generation, but with the way this generates the source/wheel distributions it should fix the .pyc recompilation issue regardless of the end package manager.
Note that this now makes wheels specific to a python version (ie instead of
hy-0.21-py3-none-any.whl
, runningsetup.py bdist_wheel
will now generatehy-0.21-cp310-none-any.whl
)So for Pypi we (really, @Kodiologist) will want to generate wheels for each version of python we support. The source distribution doesn't contain .pyc files so it's still version agnostic.