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

Improve Python install #19

Open
mgorny opened this issue Apr 30, 2020 · 3 comments
Open

Improve Python install #19

mgorny opened this issue Apr 30, 2020 · 3 comments

Comments

@mgorny
Copy link
Contributor

mgorny commented Apr 30, 2020

Besides installing cvise to site-packages, we need to get the modules byte-compiled. Now, that's a non-trivial task and CMake is horrible at it, so it'd be best to actually use distutils/setuptools for that. Ideally, the package could be split into two, one containing common C/C++ tooling that could shared between cvise and creduce, and the other containing the Python driver.

Why byte-compiling is hard? The exact commands used depend on Python interpreter and version used. There are different commands for Python <3.5, PyPy(2), Python 3 (and PyPy3) >=3.5, Jython… and these are the implementations we used. Even Python upstream recently gets it wrong, and we have to patch Python for it.

The 'fallback' code we have for it:
https://gitweb.gentoo.org/repo/gentoo.git/tree/eclass/python-utils-r1.eclass#n595

I don't think you want to repeat it verbatim in CMakeLists.txt and maintain it going forward.

@marxin
Copy link
Owner

marxin commented May 1, 2020

Besides installing cvise to site-packages, we need to get the modules byte-compiled. Now, that's a non-trivial task and CMake is horrible at it, so it'd be best to actually use distutils/setuptools for that. Ideally, the package could be split into two, one containing common C/C++ tooling that could shared between cvise and creduce, and the other containing the Python driver.

It would be ideal, but now there's some divergence, partially because I cherry-picked some long-lasting pull requests of creduce.

Why byte-compiling is hard? The exact commands used depend on Python interpreter and version used. There are different commands for Python <3.5, PyPy(2), Python 3 (and PyPy3) >=3.5, Jython… and these are the implementations we used. Even Python upstream recently gets it wrong, and we have to patch Python for it.

It seems to me as a nice optimization, but in case of C-Vise one expects the script running for quite some time, so caching is probably not a crucial need.

The 'fallback' code we have for it:
https://gitweb.gentoo.org/repo/gentoo.git/tree/eclass/python-utils-r1.eclass#n595

I don't think you want to repeat it verbatim in CMakeLists.txt and maintain it going forward.

Maybe we can create a cmake function that will both install .py file and it's cached file?
Thanks for the idea!

@mgorny
Copy link
Contributor Author

mgorny commented May 1, 2020

Besides installing cvise to site-packages, we need to get the modules byte-compiled. Now, that's a non-trivial task and CMake is horrible at it, so it'd be best to actually use distutils/setuptools for that. Ideally, the package could be split into two, one containing common C/C++ tooling that could shared between cvise and creduce, and the other containing the Python driver.

It would be ideal, but now there's some divergence, partially because I cherry-picked some long-lasting pull requests of creduce.

But do these break backwards compatibility? I was thinking of taking your version and using it in creduce.

Why byte-compiling is hard? The exact commands used depend on Python interpreter and version used. There are different commands for Python <3.5, PyPy(2), Python 3 (and PyPy3) >=3.5, Jython… and these are the implementations we used. Even Python upstream recently gets it wrong, and we have to patch Python for it.

It seems to me as a nice optimization, but in case of C-Vise one expects the script running for quite some time, so caching is probably not a crucial need.

The main problem is not really whether the cache exists but that Python will try to write one if it doesn't. This means orphan files, and we have QA checks in place to detect that.

The 'fallback' code we have for it:
https://gitweb.gentoo.org/repo/gentoo.git/tree/eclass/python-utils-r1.eclass#n595
I don't think you want to repeat it verbatim in CMakeLists.txt and maintain it going forward.

Maybe we can create a cmake function that will both install .py file and it's cached file?

I think the usual approach is to byte-compile all files after they're installed.

Though I'd still lean towards using distutils for that. You can always make CMake call setup.py with proper arguments, roughly ${PYTHON_EXECUTABLE} setup.py install --prefix=${CMAKE_INSTALL_PREFIX} --root=${DESTDIR} (sorry, I don't recall exactly how to substitute DESTDIR there).

@marxin
Copy link
Owner

marxin commented May 1, 2020

But do these break backwards compatibility? I was thinking of taking your version and using it in creduce.

No, there's no breakage of the compatibility. Feel free to use C-Vise's binaries for creduce.

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

No branches or pull requests

2 participants