-
Notifications
You must be signed in to change notification settings - Fork 360
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
Resolved Python module import dependencies #1595
Resolved Python module import dependencies #1595
Conversation
This patch adds calls of `pybind11::module::import()` to the Python bindings of modules that depend on specific other modules. This approach is similar to importing required modules via `import` in Python packages/modules. With this patch in place, it's possible to import any of the MaterialX Python modules in any order. Signed-off-by: Stefan Habel <[email protected]>
either within the `MaterialX` Python package or as a standalone module. Signed-off-by: Stefan Habel <[email protected]>
To test: ```bash cmake . -DMATERIALX_BUILD_PYTHON=ON \ && cmake --build . \ && make install \ && python3 python/MaterialXTest/imports.py ``` Signed-off-by: Stefan Habel <[email protected]>
This looks like a great improvement, thanks @StefanHabel! I'm imagining that this change will allow us to simplify several of the |
Cheers @jstone-lucasfilm! I see, there appear to be a couple of unused imports in some of those scripts, which were likely necessary previously due to these import dependencies, e.g. from MaterialX import PyMaterialXGenShader
from MaterialX import PyMaterialXGenGlsl We are likely able to remove those unused imports from those script files, given that the imported and used modules should import their own dependencies. I can give this a go locally. If this works out (which I expect it will), would we want to remove the new |
(Meta: I'm just realizing that GitHub does not support replying to a comment, other than by quoting from a comment 😑) I looked into this for a little bit. Only python/Scripts/baketextures.py:9:1: F401 'MaterialX.PyMaterialXGenShader' imported but unused
python/Scripts/baketextures.py:10:1: F401 'MaterialX.PyMaterialXGenGlsl' imported but unused
python/Scripts/translateshader.py:12:1: F401 'MaterialX.PyMaterialXGenGlsl as ms_gen_glsl' imported but unused
python/Scripts/translateshader.py:16:5: F401 'MaterialX.PyMaterialXGenMsl as ms_gen_msl' imported but unused The MaterialX imports in import MaterialX as mx
import MaterialX.PyMaterialXGenShader as mx_gen_shader
import MaterialX.PyMaterialXGenGlsl as mx_gen_glsl
import MaterialX.PyMaterialXGenOsl as mx_gen_osl
import MaterialX.PyMaterialXGenMdl as mx_gen_mdl
import MaterialX.PyMaterialXGenMsl as mx_gen_msl We could now sort them alphabetically, if we wanted to, but as they're all used, these separate imports are all still required: import MaterialX as mx
import MaterialX.PyMaterialXGenGlsl as mx_gen_glsl
import MaterialX.PyMaterialXGenMdl as mx_gen_mdl
import MaterialX.PyMaterialXGenMsl as mx_gen_msl
import MaterialX.PyMaterialXGenOsl as mx_gen_osl
import MaterialX.PyMaterialXGenShader as mx_gen_shader Would the idea be to simplify these imports? |
Those are good points, @StefanHabel, and it's true that a dedicated Maybe the best answer is to keep this new script in your pull request, but to additionally simplify the existing |
Also sorted imports in `generateshader.py` alphabetically. Signed-off-by: Stefan Habel <[email protected]>
I've added a commit to remove the unused MaterialX imports: 1cd726c It looks like two checks on Ubuntu have failed with an "Internal Server Error". For example, here's what the error looks like in the raw log of the Python Wheels run for Python 3.8 on Ubuntu:
For comparison, here's what the relevant bit from the log of the successful run of Python 3.7 on Ubuntu looked like:
@jstone-lucasfilm Assuming the two failed checks are random server failures, is there a way to re-run the checks, perhaps only the two that failed? |
@StefanHabel Done! |
Signed-off-by: Jonathan Stone <[email protected]>
@StefanHabel This looks great to me, and my sense is that your simplifications and reordering of imports in our example scripts are now sufficient to validate the improvements that you've made, so I'd say that it's fine to omit |
Signed-off-by: Jonathan Stone <[email protected]>
Thanks @jstone-lucasfilm ! I've edited the description of the PR to remove the notes about the unittest. |
83ae82e
into
AcademySoftwareFoundation:main
```bash $ flake8 python/scripts --select F python/scripts/generateshader.py:28:13: F841 local variable 'result' is assigned to but never used python/scripts/generateshader.py:86:16: F821 undefined name 'err' python/scripts/generateshader.py:87:43: F821 undefined name 'err' python/scripts/genmdl.py:8:1: F401 'string' imported but unused python/scripts/genmdl.py:344:5: F841 local variable 'LIBRARY' is assigned to but never used python/scripts/genmdl.py:525:21: F841 local variable 'outputvalue' is assigned to but never used python/scripts/mxdoc.py:6:1: F401 'os' imported but unused python/scripts/mxformat.py:7:1: F401 'sys' imported but unused python/scripts/mxvalidate.py:6:1: F401 'os' imported but unused python/scripts/mxvalidate.py:28:16: F821 undefined name 'err' python/scripts/mxvalidate.py:29:19: F821 undefined name 'err' ``` With this patch: ```bash $ flake8 python/scripts --select F --count 0 ``` Found while working on AcademySoftwareFoundation#1595. This commit follows 83ae82e. Signed-off-by: Stefan Habel <[email protected]>
This patch adds
pybind11::module::import()
calls to MaterialX Python C extension modulesthat depend on other MaterialX Python C extension modules.
The intention is to allow any of the MaterialX Python C extension modules to be imported
in any order.
A couple of the Python scripts are updated to remove unused MaterialX imports,
and to sort imports alphabetically (which is now possible as the modules import
their own dependencies).
My dev environment, for reference:
Split from #1567.
Update #342.