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

ENH: Always compile python scripts as legacy .pyc files #1188

Merged
merged 1 commit into from
Jan 28, 2024

Conversation

jcfr
Copy link
Member

@jcfr jcfr commented Jan 27, 2024

Refine the script introduced in commit db3f4d9 ("Re-create python compile script only if needed and fix dependency. See #449", 2014-04-16) by explicitly specifying the cfile parameter. Disable the default behavior (introduced in Python 3.2) of generating .pyc files in the __pycache__ directory, as outlined in PEP-3147.

This improvement is needed for Slicer-based applications, enabling them to locate scripted modules and plugins as either .py or .pyc files in a specific directory.

References:

Refine the script introduced in commit db3f4d9 ("Re-create python compile
script only if needed and fix dependency. See commontk#449", 2014-04-16) by explicitly
specifying the `cfile` parameter. Disable the default behavior (introduced in
Python 3.2) of generating .pyc files in the `__pycache__` directory, as outlined
in PEP-3147.

This improvement is needed for Slicer-based applications, enabling them to
locate scripted modules and plugins as either .py or .pyc files in a specific
directory.

References:
* PEP-3147: https://peps.python.org/pep-3147/
* Slicer Forum Discussion: https://discourse.slicer.org/t/how-to-hide-the-code-of-the-script-module/26135/14
* Python Documentation: https://docs.python.org/3/library/py_compile.html#py_compile.compile
Copy link

@MujassimJamal MujassimJamal left a comment

Choose a reason for hiding this comment

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

Tested and approved.

@jcfr
Copy link
Member Author

jcfr commented Jan 28, 2024

Thanks for the review.

@jamesobutler @lassoan Any suggestions before we move forward with the integration?

Copy link
Contributor

@jamesobutler jamesobutler left a comment

Choose a reason for hiding this comment

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

The old legacy location of pyc files is fine with me.

I’ve been doing a compile step in my Slicer extension CMakeLists along with specifying the .pyc versions to include in the package.
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import compileall;compileall.compile_dir('${CMAKE_CURRENT_SOURCE_DIR}', legacy=True, optimize=2, force=True)")

@jcfr jcfr merged commit 4aba4e2 into commontk:master Jan 28, 2024
3 checks passed
@jcfr jcfr deleted the compile-script-as-legacy-pyc-files branch January 28, 2024 16:14
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