-
Notifications
You must be signed in to change notification settings - Fork 492
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: Support "compiling" source files exclusively to .pyc #1192
base: master
Are you sure you want to change the base?
Conversation
d55c93e
to
6b0f3fa
Compare
Introduce the option CTK_COMPILE_PYTHON_SCRIPT_SKIP_SCRIPT_COPY to support disabling the copy of `*.py` script into the build directory. Update CMake function `ctkFunctionAddCompilePythonScriptTargets` to accept the `SKIP_SCRIPT_COPY` option. Update CMake macro `ctkMacroCompilePythonScript` to call `ctkFunctionAddCompilePythonScriptTargets` passing SKIP_SCRIPT_COPY based on the value of CTK_COMPILE_PYTHON_SCRIPT_SKIP_SCRIPT_COPY Address warning when using CMake >= 3.13, setting CMP0077 to NEW. See https://cmake.org/cmake/help/latest/policy/CMP0077.html Co-authored-by: Jean-Christophe Fillion-Robin <[email protected]>
More work is still need as By configuring CTK with
We will need to address this before moving forward. I will follow-up with some suggestions. |
Introduce the option CTK_COMPILE_PYTHON_SCRIPT_KEEP_ONLY_PYC to support remove `*.py` scripts once the corresponding `.pyc` file has been generated in the destination directory. Update `_ctk_add_compile_python_directories_target` to accept `keep_only_pyc` argument. Update CMake function `ctkFunctionAddCompilePythonScriptTargets` to accept the `KEEP_ONLY_PYC` option and call `_ctk_add_compile_python_directories_target` accordingly. Update CMake macro `ctkMacroCompilePythonScript` to call `ctkFunctionAddCompilePythonScriptTargets` passing KEEP_ONLY_PYC based on the value of `CTK_COMPILE_PYTHON_SCRIPT_KEEP_ONLY_PYC`. Address warning when using CMake >= 3.13, setting CMP0077 to NEW. See https://cmake.org/cmake/help/latest/policy/CMP0077.html Co-authored-by: Jean-Christophe Fillion-Robin <[email protected]>
I revisited the approach, suggested commit message for
|
@MujassimJamal Could you test on your side ? 🙏 @jamesobutler @lassoan I revisited the original approach to instead accept the option To illustrate here is a screenshot of the generated1 script:
called by the The code highlighted in red is included only if Footnotes
|
Thanks, @jcfr, for proposing an alternative approach. Indeed, the previous approach of skipping the copy target created issues for me during scratch builds, as you mentioned that compiled files must be copied to the destination first. Since then, I've been using an unofficial hard-coded temporary solution, which involves completely removing 'py' files once they are compiled. To achieve this, I directly used the following code snippet in the file if 'qt-scripted-modules' in fullname:
print('Removing', fullname, '...')
os.remove(fullname) I'm okay with the alternative approach you proposed, as it allows explicit control over the behavior. I'll test it from my side and provide an update here. 🚀 |
Were you able to test in the context of your project ? |
@jcfr Thank you for your patience. Yes, I've recently tested it and encountered numerous errors in the Python console. The majority of these errors were related to:
When I open the application after a build, only a blank main window is visible; all the widgets are gone (e.g slice views, 3D view, module panel, etc.). Perhaps this occurred because it removes ".py" files not only from the lib/{AppName}/qt-scripted-modules directory but also from other directories (e.g. bin etc.) within the Slicer-build. |
@jcfr, I want to know if you are planning to proceed with this PR? |
Based on your tests1, Slicer would need to also be updated to make this feature useful. Would you be able to open a pull request against Slicer do address those? Footnotes |
Sure, I will open a pull request with necessary changes to the Slicer. |
To support “compiling” source file exclusively to .pyc, the CMake function
ctkFunctionAddCompilePythonScriptTargets
has been improved to accept a new parameter optionSKIP_SCRIPT_COPY
. This new option controls the definition of the targetCopySlicerPythonScriptFiles
.Introduce the option CTK_COMPILE_PYTHON_SCRIPT_KEEP_ONLY_PYC to support removing `*.py` scripts once the corresponding `.pyc` file has been generated in the destination directory.
Update
_ctk_add_compile_python_directories_target
to acceptkeep_only_pyc
argument.Update CMake function
ctkFunctionAddCompilePythonScriptTargets
to accept theKEEP_ONLY_PYC
option and call_ctk_add_compile_python_directories_target
accordingly.Update CMake macro
ctkMacroCompilePythonScript
to callctkFunctionAddCompilePythonScriptTargets
passing KEEP_ONLY_PYC based on the value ofCTK_COMPILE_PYTHON_SCRIPT_KEEP_ONLY_PYC
.Address warning when using CMake >= 3.13, setting CMP0077 to NEW.
See https://cmake.org/cmake/help/latest/policy/CMP0077.html
Related pull requests:
Related discussions: