Skip to content

Commit

Permalink
feat: Add support for the portable version of maya, which can be foun…
Browse files Browse the repository at this point in the history
…d by adding the MAYA_LOCATION environment variable.
  • Loading branch information
liujingjing committed May 9, 2024
1 parent a3554a7 commit fdfdd21
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 41 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ MAYA_UMBRELLA_IGNORE_BACKUP
SET MAYA_UMBRELLA_IGNORE_BACKUP=true
```

如果是便携版Maya,可以通过添加 `MAYA_LOCATION` 环境变量指定路径 `d:/your/path/Maya2025`
```shell
SET MAYA_LOCATION=d:/your/path/Maya2025
```


# API
获取当前场景没有被修复的病毒文件

Expand Down
74 changes: 33 additions & 41 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: UTF-8 -*-
import sys
import shutil

import nox
Expand All @@ -14,20 +15,16 @@

def _setup_maya(maya_version):
"""Set up the appropriate Maya version for testing."""
try:
import winreg
except ImportError:
return {}
try:
key = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
f"SOFTWARE\\Autodesk\\Maya\\{maya_version}\\Setup\\InstallPath",
)
root, _ = winreg.QueryValueEx(key, "MAYA_INSTALL_LOCATION")
if not os.path.isdir(root):
print("Failed to locate the appropriate Maya path in the registration list.")
except OSError:
return
root = _get_registry("MAYA_INSTALL_LOCATION",
f"SOFTWARE\\Autodesk\\Maya\\{maya_version}\\Setup\\InstallPath"
)
if not root:
maya_location = os.environ.get("MAYA_LOCATION")

if maya_location:
root = os.path.join(maya_location, f"Maya{maya_version}")
else:
return
bin_root = os.path.join(root, "bin")
return {"maya_root": root, "bin_root": bin_root}

Expand All @@ -36,6 +33,19 @@ def _assemble_env_paths(*paths):
return ";".join(paths)


def _get_registry(key_name, path):
try:
import winreg # noqa: F401
except ImportError:
return {}
try:
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path) as key:
value, _ = winreg.QueryValueEx(key, key_name)
return value
except WindowsError:
return None


@nox.session
def lint(session: nox.Session) -> None:
session.install("wemake-python-styleguide")
Expand Down Expand Up @@ -190,34 +200,16 @@ def dynamic_session(session: nox.Session):
)


def add_dynamic_maya_standalone_session(maya_version, mayapy, command):
session_name = f"maya-{maya_version}-s"

@nox.session(name=session_name, python=False)
def dynamic_session(session: nox.Session):
parser = argparse.ArgumentParser(prog=f"nox -s maya-{maya_version}-s")
parser.add_argument("pattern", type=str)
args = parser.parse_args(session.posargs)
session.run(
mayapy,
command,
args.pattern,
env={"PYTHONPATH": ROOT},
)


# Dynamic to set up nox sessions for Maya 2018-2026.
# For example, to run tests for Maya 2018, run:
# nox -s maya-2018
for maya_version in range(2018, 2026):
maya_setup = _setup_maya(maya_version)
if maya_setup:
add_dynamic_maya_session(f"maya-{maya_version}", os.path.join(maya_setup["bin_root"], "maya.exe"))
maya_python = os.path.join(maya_setup["bin_root"], "mayapy.exe")
test_runner = os.path.join(ROOT, "tests", "_test_runner.py")
add_dynamic_maya_test_session(maya_version, maya_python, test_runner)
standalone_runner = os.path.join(ROOT, "run_maya_standalone.py")
add_dynamic_maya_standalone_session(maya_version, maya_python, standalone_runner)
maya_version = sys.argv[-1].split('-')[-1]
maya_setup = _setup_maya(maya_version)
if maya_setup:
add_dynamic_maya_session(f"maya-{maya_version}", os.path.join(maya_setup["bin_root"], "maya.exe"))
maya_python = os.path.join(maya_setup["bin_root"], "mayapy.exe")
test_runner = os.path.join(ROOT, "tests", "_test_runner.py")
add_dynamic_maya_test_session(maya_version, maya_python, test_runner)


@nox.session(name="make-zip")
Expand Down Expand Up @@ -255,6 +247,6 @@ def make_install_zip(session: nox.Session):
for root, _, files in os.walk(build_root):
for file in files:
zip_obj.write(os.path.join(root, file),
os.path.relpath(os.path.join(root, file),
os.path.join(build_root, ".")))
os.path.relpath(os.path.join(root, file),
os.path.join(build_root, '.')))
print("Saving to %s" % zip_file)

0 comments on commit fdfdd21

Please sign in to comment.