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

Don't create pyc files when building tables #135

Merged
merged 4 commits into from May 2, 2018
Merged

Conversation

stefanor
Copy link
Contributor

We don't want to include pyc files in source distributions.

@eliben
Copy link
Owner

eliben commented Jul 30, 2016

I'm not sure I follow. Shoudln't they just be excluded from the manifest?

It seems useful to create .pycs when doing install? and install calls _run_build_tables too

@stefanor
Copy link
Contributor Author

stefanor commented Jul 30, 2016

Shouldn't they just be excluded from the manifest?

So, that was my initial thought too. But they are excluded from the manifest, yet still appearing in the sdist.

The problem here is that we are running a python script directly in the package build directory, between the source copying (that reads MANIFEST.in) and building the tarball.

It seems useful to create .pycs when doing install?

pip will do that on the actual install. Shipping pycs in the source tarballs is not the way to solve that problem.

and install calls _run_build_tables too

Yes 100%. This doesn't change that.

@eliben
Copy link
Owner

eliben commented Aug 1, 2016

It seems useful to create .pycs when doing install?
pip will do that on the actual install.

Please bear with me here; there were a lot of issues with these tables in the past. The problem is, if there's no .pyc in the install directory, the .pyc is created locally where users of pycparser live, which is very bad because pycparser is used transitively but a lot of tools today.

Currently _build_tables is run during installation to generate new .py files that weren't shipped. I'm not 100% sure pip actually does that, since this is a custom step that happens after the actual installation.

Therefore, at the very least I wouldn't run with -B during install, perhaps only during sdist.

@eliben
Copy link
Owner

eliben commented Oct 6, 2016

Any updates on this?

@stefanor
Copy link
Contributor Author

Sorry, I haven't been on top of GitHub notifications.

there were a lot of issues with these tables in the past

My issue is entirely with the pyc files, which result from the way the tables are built. Not with the tables.

After that, I'm going to reply out of order, because I think that makes a little more sense.

Currently _build_tables is run during installation to generate new .py files that weren't shipped. I'm not 100% sure pip actually does that, since this is a custom step that happens after the actual installation.

Yeah, you can't do anything during installation in a wheel world, everything should be shipped in the wheel. However, you are running _build_tables during sdist which means those .py files are shipped in source tarballs. And running them during install which gets them into wheels. I think that is all correct. What I'm questioning is including .pyc files, which is a side-effect of the way _build_tables is being run.

The problem is, if there's no .pyc in the install directory, the .pyc is created locally where users of pycparser live

Are you sure about that? That sounds completely wrong. .pyc files should only be created next to their .py source, in Python 2, or in the neighbouring __pycache__ directory in Python 3. If the user doesn't have permission to write the .pyc files in those places, they simply don't get written, and Python doesn't complain. It does affect import performance, but that's it.

Therefore, at the very least I wouldn't run with -B during install, perhaps only during sdist.

I think that'd be wrong. Then you'd ship .pyc files in wheels. But the wheels target all versions of Python, and the .pyc files don't.

@eliben
Copy link
Owner

eliben commented Jan 3, 2017

I think that'd be wrong. Then you'd ship .pyc files in wheels. But the wheels target all versions of Python, and the .pyc files don't.

If -B is used during sdist then there should be no .pyc files in the wheels, right?

@bespokebob
Copy link

If -B is used during sdist then there should be no .pyc files in the wheels, right?

bdist_wheel calls install, so if your install command is creating .pyc files, then they will also be included in the wheel.
See https://github.com/pypa/wheel/blob/master/wheel/bdist_wheel.py#L238

@bespokebob
Copy link

It is also completely wrong to include .pyc files in the sdist, as the .pyc files are being created using whatever version of Python that you used to create the sdist - not the version that the user is installing with.

@eliben
Copy link
Owner

eliben commented Apr 24, 2018

#251 points here

If anyone wants to provide a well-tested PR that removes .pyc from the manifest and be responsibe for its testing and stability, I'll be happy to work together on this.

@josephmancuso
Copy link

josephmancuso commented Apr 24, 2018

For what it's worth there was a release around Jan 30th of this year with changes to .pyc files for Python 3.7 (something with a new hash based pyc)

@josephmancuso
Copy link

josephmancuso commented Apr 24, 2018

Like I said in my other comment on that issue referenced. I used the same version and it suddenly started breaking one day on the python 3.7 dev branch so I'm pretty sure it's a change in the dev branch around that time. ~Jan 24th

@eliben
Copy link
Owner

eliben commented Apr 24, 2018

Fair enough.

I'm going to leave this open until a volunteer is found to fix the issue(s) with .pyc distribution once and for all. This is a messy aspect of Python, and I'm not personally interested in it for this project because I always use pycparser "from source" on the master git branch without actually installing anything. If distributing .pyc files is not best practice, so be it, but be mindful that this leads to other issues like those .pyc files being regenerated in the wrong places when users actually run scripts using the library (or worse, through several layers of dependencies). All of this has to be thoroughly tested and someone has to be ready and willing to intercept breakages and fix them - I'll be happy to release 2.19 that addresses this issue.

@stefanor
Copy link
Contributor Author

FWIW, I tested this at the time :)

@stefanor
Copy link
Contributor Author

Tested master + this branch:

Distribution .py .pyc Utils Tests Tables Comments
sdist ✔️ ✔️ ✔️ setup.pyc is included if present
bdist_wheel ✔️ ✔️ Universal py2+3
bdist ✔️ ✔️ ✔️
bdist_egg ✔️ ✔️ Missing tables

Those are all correct, I think, except for the egg (which nobody uses any more), and the setup.pyc accident.

@eliben
Copy link
Owner

eliben commented May 1, 2018

Can you explain the difference between the 2nd and 3rd lines?

@stefanor
Copy link
Contributor Author

stefanor commented May 1, 2018

bdist is an ancient thing. I hope nobody actually uses them. bdists are targetted at a specific python version on a specific platform, so there is no harm in containing pyc files.

AFAIK wheels never contain pyc files.

@stefanor
Copy link
Contributor Author

stefanor commented May 1, 2018

I think setup.pyc is coming from include setup.* in MANIFEST.in, we can fix that...

Edit: Actually, without the setup.*, I was still getting it, but an exclude seems to do the trick.

@@ -6,6 +6,7 @@ include README.*
include LICENSE
include CHANGES
include setup.*
Copy link
Owner

Choose a reason for hiding this comment

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

Should this just say include setup.py now?

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 tried that, and it still included the pyc. I didn't go too far down that rabbit hole.

Copy link
Owner

Choose a reason for hiding this comment

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

I mean have "include setup.py" and "exclude setup.pyc". The "*" seems mysterious now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's also setup.cfg

setup.py Outdated
call([sys.executable, '_build_tables.py'],
cwd=os.path.join(dir, 'pycparser'))
from subprocess import check_call
check_call([sys.executable, '-B', '_build_tables.py'],
Copy link
Owner

Choose a reason for hiding this comment

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

Would be good to add a comment here explaining why the -B and even linking to the PR discussion

setup.py Outdated
call([sys.executable, '_build_tables.py'],
cwd=os.path.join(dir, 'pycparser'))
from subprocess import check_call
# This is run inside the install dir, so we don't want to leave any .pyc
Copy link
Owner

Choose a reason for hiding this comment

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

It's not clear what the install dir means here - the directory you install it from, or install it to? Please be more explicit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed.

@eliben
Copy link
Owner

eliben commented May 2, 2018

Merging, thanks

@eliben eliben merged commit aedb4ed into eliben:master May 2, 2018
@stefanor stefanor deleted the no-pyc branch May 2, 2018 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants