Source code for cgl.plugins.substance.setup.setup
import logging
import os
from pathlib import Path
from cgl.core.config.edit import edit_user_config
from cgl.core.config.query import get_user_dir, AlchemyConfigManager
from cgl.core.utils.general import cgl_execute, cgl_copy
CFG = AlchemyConfigManager()
[docs]
def setup():
"""
runs the pip install requirements.txt using substance painter's build in version of python, this will ensure that blender
is set up to work with Alchemy out the gate.
Returns:
"""
program_files = os.getenv("PROGRAMFILES")
substance_python_path = (
r"{}\Adobe\Adobe Substance 3D Painter\resources\pythonsdk\python.exe".format(
program_files
)
)
print(substance_python_path)
if os.path.exists(substance_python_path):
code_root = Path(CFG.get_code_root())
requirements_path = code_root / "cgl" / "plugins" / "substance" / "setup" / "requirements.txt"
os.chdir(code_root)
command = f'"{substance_python_path}" -m pip install -r "{str(requirements_path)}"'
cgl_execute(command, working_directory=str(code_root), verbose=True)
edit_user_config(["software", "SUBSTANCE"], substance_python_path)
if not os.path.exists(requirements_path):
print('Requirements file not found at "{}"'.format(requirements_path))
else:
print(substance_python_path)
logging.info("Substance Painter not found")
[docs]
def copy_user_setup():
code_root = Path(CFG.get_code_root())
copy_source = code_root / "cgl" / "plugins" / "substance" / "userSetup.py"
user_path = Path(get_user_dir())
# substance_startup_path = os.path.join(
# user_path,
# "Documents",
# "Adobe",
# "Adobe Substance 3D Painter",
# "python",
# "startup",
# )
substance_startup_path = user_path / "Documents" / "Adobe" / "Adobe Substance 3D Painter" / "python" / "startup"
print(substance_startup_path)
system_substance_startup_path = os.path.join(
os.path.expanduser("~"),
"Documents",
"Adobe",
"Adobe Substance 3D Painter",
"python",
"startup",
)
system_substance_startup_path = Path(system_substance_startup_path)
if not os.path.exists(substance_startup_path):
if os.path.exists(system_substance_startup_path):
substance_startup_path = system_substance_startup_path
# TODO - i need to hard code the ALC_PYTHON_PATH as well as the ALC_CODE_ROOT, or we need them as env vars.
# so far this is one of the only places where we need to hard code the path to the code root.
this = substance_startup_path.resolve()
print(this)
if os.path.exists(this):
copy_destination = substance_startup_path / "userSetup.py"
print("Copying \"{}\" to \"{}\"".format(copy_source.as_posix(), copy_destination.as_posix()))
cgl_copy(source=copy_source.as_posix(), destination=copy_destination.as_posix(), verbose=True)
else:
print("Path Does Not Exist: {}".format(substance_startup_path))
[docs]
def main():
"""
Main function to run the setup.
"""
setup()
# copy_user_setup()
print("Substance Painter setup complete.")
if __name__ == "__main__":
main()