diff --git a/README.md b/README.md index f619e73..d42cde0 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,12 @@ MAYA_UMBRELLA_LANG ```shell MAYA_UMBRELLA_IGNORE_BACKUP ``` + +如果是便携版Maya,可以通过添加 `MAYA_LOCATION` 环境变量指定路径如 `d:/your/path` 并且在 `/path/`路径下放maya版本文件夹, 比如Maya2024, Maya完整路径是 `d:/your/path/Maya2024` +```shell +SET MAYA_LOCATION=d:/your/path/ +``` + 如果忽略请设置为 ```shell SET MAYA_UMBRELLA_IGNORE_BACKUP=true diff --git a/noxfile.py b/noxfile.py index 20ba4f8..d84b033 100644 --- a/noxfile.py +++ b/noxfile.py @@ -14,21 +14,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: + root = _get_registry("MAYA_INSTALL_LOCATION", + f"SOFTWARE\\Autodesk\\Maya\\{maya_version}\\Setup\\InstallPath" + ) + + maya_location = os.environ.get("MAYA_LOCATION", root) + if not maya_location: + print("maya not found.") return - bin_root = os.path.join(root, "bin") + + bin_root = os.path.join(maya_location, "bin") return {"maya_root": root, "bin_root": bin_root} @@ -36,6 +31,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") @@ -209,15 +217,18 @@ def dynamic_session(session: nox.Session): # 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) +parser = argparse.ArgumentParser() +parser.add_argument('-s') +args = parser.parse_args() +maya_version = "".join(filter(str.isdigit, args.s)) +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) @nox.session(name="make-zip")