Skip to content

Commit

Permalink
chore: Add new nox session to make zip
Browse files Browse the repository at this point in the history
Signed-off-by: loonghao <[email protected]>
  • Loading branch information
loonghao committed May 7, 2024
1 parent c49c39a commit aff25d5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ docs_src/_build/

run_pycharm.bat

coverage.xml
coverage.xml
.zip
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ manual_test_in_maya.start()
nox -s ruff_check
```

# 生成安装包
执行下面的命令可以在<repo>/.zip下面创建zip,参数 `--version` 当前工具的版本号
```shell
nox -s make-zip -- --version 0.5.0
```

# 环境变量

我们可以通过下列环境变量去修改maya_umbrella的一些设置,方便有pipeline的公司可以更好的集成
Expand Down
44 changes: 43 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# -*- coding: UTF-8 -*-
import shutil

import nox
import argparse
import os
from pathlib import Path
from typing import Iterator, Tuple
import zipfile

PACKAGE_NAME = "maya_umbrella"
ROOT = os.path.dirname(__file__)
Expand All @@ -11,7 +15,7 @@
def _setup_maya(maya_version):
"""Set up the appropriate Maya version for testing."""
try:
import winreg # noqa: F401
import winreg # noqa: F401
except ImportError:
return {}
try:
Expand Down Expand Up @@ -196,3 +200,41 @@ def dynamic_session(session: nox.Session):
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")
def make_install_zip(session: nox.Session):
temp_dir = os.path.join(ROOT, ".zip")
build_root = os.path.join(temp_dir, "maya_umbrella")
script_dir = os.path.join(build_root, "scripts")
shutil.rmtree(temp_dir, ignore_errors=True)
bat_template = """
@echo off
SET "batPath=%~dp0"
SET "modContent=+ maya_umbrella {version} %batPath%"
SET "modFilePath=%~dp0maya_umbrella.mod"
echo %modContent% > "%modFilePath%"
xcopy "%~dp0maya_umbrella.mod" "%USERPROFILE%\\documents\\maya\\modules\\" /y
del /f "%~dp0maya_umbrella.mod"
pause
"""
parser = argparse.ArgumentParser(prog="nox -s make-zip")
parser.add_argument("--version", default="0.5.0", help="Version to use for the zip file")
args = parser.parse_args(session.posargs)
version = str(args.version)
print(f"make zip to current version: {version}")

shutil.copytree(os.path.join(ROOT, "maya_umbrella"),
os.path.join(script_dir, "maya_umbrella"))
with open(os.path.join(build_root, "install.bat"), "w") as f:
f.write(bat_template.format(version=version))

shutil.copy2(os.path.join(ROOT, "maya", "userSetup.py"),
os.path.join(script_dir, "userSetup.py"))

with zipfile.ZipFile(os.path.join(temp_dir, f"{PACKAGE_NAME}-{version}.zip"), "w") as zip:
for root, _, files in os.walk(build_root):
for file in files:
zip.write(os.path.join(root, file),
os.path.relpath(os.path.join(root, file),
os.path.join(build_root, '.')))

0 comments on commit aff25d5

Please sign in to comment.