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

Resolved Python module import dependencies #1595

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions python/Scripts/baketextures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

import sys, os, argparse
from sys import platform

import MaterialX as mx
from MaterialX import PyMaterialXGenShader
from MaterialX import PyMaterialXGenGlsl
from MaterialX import PyMaterialXRender as mx_render
from MaterialX import PyMaterialXRenderGlsl as mx_render_glsl
if platform == "darwin":
Expand Down
5 changes: 3 additions & 2 deletions python/Scripts/generateshader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
'''

import sys, os, argparse, subprocess

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
import MaterialX.PyMaterialXGenOsl as mx_gen_osl
import MaterialX.PyMaterialXGenShader as mx_gen_shader

def validateCode(sourceCodeFile, codevalidator, codevalidatorArgs):
if codevalidator:
Expand Down
6 changes: 2 additions & 4 deletions python/Scripts/translateshader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
'''

import sys, os, argparse
import MaterialX as mx

from sys import platform

import MaterialX as mx
from MaterialX import PyMaterialXGenShader as mx_gen_shader
from MaterialX import PyMaterialXGenGlsl as ms_gen_glsl
from MaterialX import PyMaterialXRender as mx_render
from MaterialX import PyMaterialXRenderGlsl as mx_render_glsl
if platform == "darwin":
from MaterialX import PyMaterialXGenMsl as ms_gen_msl
from MaterialX import PyMaterialXRenderMsl as mx_render_msl

def main():
Expand Down
12 changes: 12 additions & 0 deletions source/PyMaterialX/PyMaterialX.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,16 @@
#include <pybind11/operators.h>
#include <pybind11/stl.h>

// Define a macro to import a PyMaterialX module, e.g. `PyMaterialXCore`,
// either within the `MaterialX` Python package, e.g. in `installed/python/`,
// or as a standalone module, e.g. in `lib/`
#define PYMATERIALX_IMPORT_MODULE(MODULE_NAME) \
try \
{ \
pybind11::module::import("MaterialX." #MODULE_NAME); \
} \
catch (const py::error_already_set&) \
{ \
pybind11::module::import(#MODULE_NAME); \
}
#endif
3 changes: 3 additions & 0 deletions source/PyMaterialX/PyMaterialXFormat/PyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ PYBIND11_MODULE(PyMaterialXFormat, mod)
{
mod.doc() = "Module containing Python bindings for the MaterialXFormat library";

// PyMaterialXFormat depends on types defined in PyMaterialXCore
PYMATERIALX_IMPORT_MODULE(PyMaterialXCore);

bindPyFile(mod);
bindPyXmlIo(mod);
bindPyUtil(mod);
Expand Down
3 changes: 3 additions & 0 deletions source/PyMaterialX/PyMaterialXGenGlsl/PyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ PYBIND11_MODULE(PyMaterialXGenGlsl, mod)
{
mod.doc() = "Module containing Python bindings for the MaterialXGenGlsl library";

// PyMaterialXGenGlsl depends on types defined in PyMaterialXGenShader
PYMATERIALX_IMPORT_MODULE(PyMaterialXGenShader);

bindPyGlslShaderGenerator(mod);
bindPyGlslResourceBindingContext(mod);

Expand Down
3 changes: 3 additions & 0 deletions source/PyMaterialX/PyMaterialXGenMdl/PyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ PYBIND11_MODULE(PyMaterialXGenMdl, mod)
{
mod.doc() = "Module containing Python bindings for the MaterialXGenMdl library";

// PyMaterialXGenMdl depends on types defined in PyMaterialXGenShader
PYMATERIALX_IMPORT_MODULE(PyMaterialXGenShader);

bindPyMdlShaderGenerator(mod);
};
3 changes: 3 additions & 0 deletions source/PyMaterialX/PyMaterialXGenMsl/PyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ PYBIND11_MODULE(PyMaterialXGenMsl, mod)
{
mod.doc() = "Module containing Python bindings for the MaterialXGenMsl library";

// PyMaterialXGenMsl depends on types defined in PyMaterialXGenShader
PYMATERIALX_IMPORT_MODULE(PyMaterialXGenShader);

bindPyMslShaderGenerator(mod);
bindPyMslResourceBindingContext(mod);
}
3 changes: 3 additions & 0 deletions source/PyMaterialX/PyMaterialXGenOsl/PyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ PYBIND11_MODULE(PyMaterialXGenOsl, mod)
{
mod.doc() = "Module containing Python bindings for the MaterialXGenOsl library";

// PyMaterialXGenOsl depends on types defined in PyMaterialXGenShader
PYMATERIALX_IMPORT_MODULE(PyMaterialXGenShader);

bindPyOslShaderGenerator(mod);
}
3 changes: 3 additions & 0 deletions source/PyMaterialX/PyMaterialXRender/PyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ PYBIND11_MODULE(PyMaterialXRender, mod)
{
mod.doc() = "Module containing Python bindings for the MaterialXRender library";

// PyMaterialXRender depends on types defined in PyMaterialXCore
PYMATERIALX_IMPORT_MODULE(PyMaterialXCore);

bindPyMesh(mod);
bindPyGeometryHandler(mod);
bindPyLightHandler(mod);
Expand Down
3 changes: 3 additions & 0 deletions source/PyMaterialX/PyMaterialXRenderGlsl/PyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ PYBIND11_MODULE(PyMaterialXRenderGlsl, mod)
{
mod.doc() = "Module containing Python bindings for the MaterialXRenderGlsl library";

// PyMaterialXRenderGlsl depends on types defined in PyMaterialXRender
PYMATERIALX_IMPORT_MODULE(PyMaterialXRender);

bindPyGlslProgram(mod);
bindPyGlslRenderer(mod);
bindPyGLTextureHandler(mod);
Expand Down
3 changes: 3 additions & 0 deletions source/PyMaterialX/PyMaterialXRenderMsl/PyModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
{
mod.doc() = "Module containing Python bindings for the MaterialXRenderMsl library";

// PyMaterialXRenderMsl depends on types defined in PyMaterialXRender
PYMATERIALX_IMPORT_MODULE(PyMaterialXRender);

bindPyMslProgram(mod);
bindPyMslRenderer(mod);
bindPyMetalTextureHandler(mod);
Expand Down
3 changes: 3 additions & 0 deletions source/PyMaterialX/PyMaterialXRenderOsl/PyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ PYBIND11_MODULE(PyMaterialXRenderOsl, mod)
{
mod.doc() = "Module containing Python bindings for the MaterialXRenderOsl library";

// PyMaterialXRenderOsl depends on types defined in PyMaterialXRender
PYMATERIALX_IMPORT_MODULE(PyMaterialXRender);

bindPyOslRenderer(mod);
}