poly-hammer-utils 0.4.2__tar.gz → 0.4.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/PKG-INFO +2 -3
  2. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/README.md +1 -3
  3. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/pyproject.toml +1 -1
  4. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/extension/character_control_rig.py +7 -2
  5. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/extension/character_dna.py +63 -11
  6. poly_hammer_utils-0.4.4/src/poly_hammer_utils/extension/core_bindings.py +114 -0
  7. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/extension/packager.py +11 -0
  8. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/__init__.py +0 -0
  9. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/addon/packager.py +0 -0
  10. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/addon/release.py +0 -0
  11. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/constants.py +0 -0
  12. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/extension/builder.py +0 -0
  13. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/extension/character_assembly.py +0 -0
  14. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/extension/meta_human_dna.py +0 -0
  15. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/extension/release.py +0 -0
  16. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/extension/server.py +0 -0
  17. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/github/release.py +0 -0
  18. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/helpers.py +0 -0
  19. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/launch.py +0 -0
  20. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/resources/scripts/blender/startup.py +0 -0
  21. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/resources/scripts/unreal/init_unreal.py +0 -0
  22. {poly_hammer_utils-0.4.2 → poly_hammer_utils-0.4.4}/src/poly_hammer_utils/utilities.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: poly-hammer-utils
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary:
5
5
  Author: Poly Hammer
6
6
  Author-email: info@polyhammer.com
@@ -21,6 +21,5 @@ Description-Content-Type: text/markdown
21
21
  [![Publish](https://github.com/poly-hammer/poly-hammer-utils/actions/workflows/publish.yaml/badge.svg)](https://github.com/poly-hammer/poly-hammer-utils/actions/workflows/publish.yaml)
22
22
  ![PyPI - Version](https://img.shields.io/pypi/v/poly-hammer-utils)
23
23
 
24
-
25
-
26
24
  A general purpose package that holds our dev utilities.
25
+
@@ -3,6 +3,4 @@
3
3
  [![Publish](https://github.com/poly-hammer/poly-hammer-utils/actions/workflows/publish.yaml/badge.svg)](https://github.com/poly-hammer/poly-hammer-utils/actions/workflows/publish.yaml)
4
4
  ![PyPI - Version](https://img.shields.io/pypi/v/poly-hammer-utils)
5
5
 
6
-
7
-
8
- A general purpose package that holds our dev utilities.
6
+ A general purpose package that holds our dev utilities.
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "poly-hammer-utils"
3
- version = "0.4.2"
3
+ version = "0.4.4"
4
4
  description = ""
5
5
  authors = ["Poly Hammer <info@polyhammer.com>"]
6
6
  readme = "README.md"
@@ -8,6 +8,7 @@ from poly_hammer_utils.extension.server import update_extension_index
8
8
  from poly_hammer_utils.extension.packager import (
9
9
  package_extension,
10
10
  copy_and_rename_addon,
11
+ get_addon_platforms,
11
12
  )
12
13
  from poly_hammer_utils.extension.release import create_production_release
13
14
 
@@ -27,11 +28,15 @@ def create_release(addon_folder: Path, releases_folder: Path):
27
28
 
28
29
  s3_prefix = BLENDER_EXTENSION_SERVER_S3_FOLDER
29
30
 
31
+ # Split into one package per platform once the manifest declares platforms, so each
32
+ # package carries only that platform's native wheel
33
+ split_platforms = bool(get_addon_platforms(source_folder=temp_addon_folder))
34
+
30
35
  # Create the new .zip files for the addon's various platforms
31
36
  addon_zip_files = package_extension(
32
37
  source_folder=temp_addon_folder,
33
38
  output_folder=releases_folder,
34
- split_platforms=False,
39
+ split_platforms=split_platforms,
35
40
  )
36
41
 
37
42
  # Generate the updated extension index and upload it and the addons .zip file to S3
@@ -41,7 +46,7 @@ def create_release(addon_folder: Path, releases_folder: Path):
41
46
  s3_folder=s3_prefix,
42
47
  local_zip_files=addon_zip_files,
43
48
  source_folder=temp_addon_folder,
44
- split_platform=False
49
+ split_platform=split_platforms
45
50
  )
46
51
 
47
52
  # Create the actual GitHub release (This only creates a release if the current environment is production)
@@ -3,6 +3,7 @@ import logging
3
3
  import zipfile
4
4
  import tempfile
5
5
  import shutil
6
+ import tomllib
6
7
  from pathlib import Path
7
8
  from poly_hammer_utils.constants import ENVIRONMENT
8
9
  from poly_hammer_utils.utilities import download_and_unzip_to_folder
@@ -10,6 +11,7 @@ from poly_hammer_utils.github.release import GitHubRelease
10
11
  from poly_hammer_utils.extension.packager import package_extension, rename_addon, parse_blender_extension_zip_info
11
12
  from poly_hammer_utils.extension.server import update_extension_index
12
13
  from poly_hammer_utils.extension.release import create_production_release
14
+ from poly_hammer_utils.extension.core_bindings import CORE_LICENSE, LICENSE_FOLDER, get_core_bindings
13
15
 
14
16
  BLENDER_EXTENSION_SERVER_S3_BUCKET = 'poly-hammer-portal-staging-app-data'
15
17
  if ENVIRONMENT == 'production':
@@ -18,6 +20,9 @@ if ENVIRONMENT == 'production':
18
20
  BLENDER_EXTENSION_SERVER_S3_FOLDER = 'products/blender-extensions/character_dna'
19
21
 
20
22
  OPEN_RIG_LOGIC_REPO = 'poly-hammer/OpenRigLogic'
23
+ OPEN_RIG_LOGIC_LICENSE = f'{LICENSE_FOLDER}/OPEN_RIGLOGIC.md'
24
+ # Every interpreter folder holds its binaries at the top and exactly these licenses beneath them.
25
+ BINDING_LICENSES = frozenset({OPEN_RIG_LOGIC_LICENSE, CORE_LICENSE})
21
26
 
22
27
  TITLE = 'Character DNA'
23
28
 
@@ -31,9 +36,9 @@ IGNORE_PATTERNS = [
31
36
  logger = logging.getLogger(__name__)
32
37
 
33
38
 
34
- def get_open_rig_logic_bindings(auth_token: str) -> tuple[Path, list[Path]]:
39
+ def get_open_rig_logic_bindings(auth_token: str, tag: str = 'latest') -> tuple[Path, list[Path]]:
35
40
  """
36
- Download the latest OpenRigLogic Python bindings release and stage every
41
+ Download the selected OpenRigLogic Python bindings release and stage every
37
42
  asset into a single ``<os>/<arch>/<pyver>/<file>`` tree.
38
43
 
39
44
  Each release asset already extracts to that exact layout, so the files are
@@ -51,7 +56,9 @@ def get_open_rig_logic_bindings(auth_token: str) -> tuple[Path, list[Path]]:
51
56
  bindings_root.mkdir(parents=True, exist_ok=True)
52
57
 
53
58
  releases = GitHubRelease(repo=OPEN_RIG_LOGIC_REPO, github_token=auth_token)
54
- tag_name, attachments = releases.get_releases_attachments(tag='latest')
59
+ tag_name, attachments = releases.get_releases_attachments(tag=tag)
60
+ if not tag_name or (tag != 'latest' and tag_name != tag):
61
+ raise ValueError(f'Missing required OpenRigLogic release: {tag}')
55
62
  logger.info(f'Downloading OpenRigLogic bindings from release "{tag_name}"')
56
63
 
57
64
  file_paths = []
@@ -69,11 +76,24 @@ def get_open_rig_logic_bindings(auth_token: str) -> tuple[Path, list[Path]]:
69
76
  # consolidated bindings root unchanged.
70
77
  for file_path in extracted:
71
78
  relative_path = file_path.relative_to(extract_dir)
79
+ if '__pycache__' in relative_path.parts or file_path.suffix in {'.pyc', '.pyo'}:
80
+ continue
81
+ if len(relative_path.parts) != 4 and Path(*relative_path.parts[3:]).as_posix() != OPEN_RIG_LOGIC_LICENSE:
82
+ raise ValueError(
83
+ f'Unexpected OpenRigLogic release path "{relative_path.as_posix()}" in {tag_name}; '
84
+ f'bindings must sit at the top of each interpreter folder with only '
85
+ f'{OPEN_RIG_LOGIC_LICENSE} beneath them (OpenRigLogic v13.5.2-ph.2 or newer)'
86
+ )
72
87
  destination = bindings_root / relative_path
73
88
  destination.parent.mkdir(parents=True, exist_ok=True)
74
89
  shutil.move(str(file_path), str(destination))
75
90
  file_paths.append(destination)
76
91
 
92
+ folders = {path.relative_to(bindings_root).parts[:3] for path in file_paths}
93
+ for folder in sorted(folders):
94
+ if not (bindings_root.joinpath(*folder) / OPEN_RIG_LOGIC_LICENSE).is_file():
95
+ raise ValueError(f'OpenRigLogic {tag_name} has no {OPEN_RIG_LOGIC_LICENSE} in {"/".join(folder)}')
96
+
77
97
  return bindings_root, file_paths
78
98
 
79
99
 
@@ -113,6 +133,31 @@ def add_bindings_to_zips(
113
133
  logger.error(f"Error: {file_path} not found")
114
134
 
115
135
 
136
+ def verify_binding_layout(addon_zip_file: Path):
137
+ """
138
+ Require every packaged interpreter folder to hold its files at the top level
139
+ plus exactly the OpenRigLogic and Character DNA licenses under ``license/``.
140
+
141
+ Args:
142
+ addon_zip_file (Path): A packaged platform-specific addon ``.zip``.
143
+ """
144
+ folders = {}
145
+ with zipfile.ZipFile(addon_zip_file) as zip_file_handle:
146
+ for name in zip_file_handle.namelist():
147
+ parts = Path(name).parts
148
+ if len(parts) < 6 or parts[0] != 'bindings':
149
+ continue
150
+ folders.setdefault('/'.join(parts[:4]), set()).add(Path(*parts[4:]).as_posix())
151
+ if not folders:
152
+ raise ValueError(f'{addon_zip_file.name} contains no interpreter bindings')
153
+ for folder, nested in sorted(folders.items()):
154
+ if nested != BINDING_LICENSES:
155
+ raise ValueError(
156
+ f'{addon_zip_file.name}: {folder} must contain only {sorted(BINDING_LICENSES)} '
157
+ f'below its binaries, found {sorted(nested)}'
158
+ )
159
+
160
+
116
161
  def copy_and_rename(addon_folder: Path, pro: bool = False) -> Path:
117
162
  """
118
163
  Copy the addon source to a temporary folder, producing either the free or
@@ -133,11 +178,13 @@ def copy_and_rename(addon_folder: Path, pro: bool = False) -> Path:
133
178
  if pro:
134
179
  temp_addon_folder = Path(tempfile.mkdtemp()) / f"{addon_folder.name}_pro"
135
180
 
136
- shutil.copytree(
137
- addon_folder,
138
- temp_addon_folder,
139
- ignore=shutil.ignore_patterns(*IGNORE_PATTERNS)
140
- )
181
+ def ignore(directory, names):
182
+ ignored = set(shutil.ignore_patterns(*IGNORE_PATTERNS)(directory, names))
183
+ if Path(directory) == addon_folder / 'bindings':
184
+ ignored.update({'windows', 'linux', 'macos'} & set(names))
185
+ return ignored
186
+
187
+ shutil.copytree(addon_folder, temp_addon_folder, ignore=ignore)
141
188
 
142
189
  if pro:
143
190
  rename_addon(
@@ -156,6 +203,11 @@ def copy_and_rename(addon_folder: Path, pro: bool = False) -> Path:
156
203
  def create_release(addon_folder: Path, releases_folder: Path, pro: bool = False):
157
204
  token = os.environ['GH_PAT']
158
205
 
206
+ addon_version = tomllib.loads((addon_folder / 'blender_manifest.toml').read_text(encoding='utf-8'))['version']
207
+ core_root, core_files, core_manifest = get_core_bindings(token, addon_version)
208
+ bindings_root, binding_files = get_open_rig_logic_bindings(
209
+ auth_token=token, tag=core_manifest['sdk']['release']
210
+ )
159
211
  temp_addon_folder = copy_and_rename(addon_folder=addon_folder, pro=pro)
160
212
 
161
213
  s3_prefix = BLENDER_EXTENSION_SERVER_S3_FOLDER
@@ -170,15 +222,15 @@ def create_release(addon_folder: Path, releases_folder: Path, pro: bool = False)
170
222
  split_platforms=True,
171
223
  )
172
224
 
173
- # Download the latest OpenRigLogic bindings and stage them
174
- bindings_root, binding_files = get_open_rig_logic_bindings(auth_token=token)
175
-
176
225
  # Update each addon .zip to include the matching platform's bindings
177
226
  add_bindings_to_zips(
178
227
  addon_zip_files=addon_zip_files,
179
228
  bindings_root=bindings_root,
180
229
  binding_files=binding_files,
181
230
  )
231
+ add_bindings_to_zips(addon_zip_files, core_root, core_files)
232
+ for addon_zip_file in addon_zip_files:
233
+ verify_binding_layout(addon_zip_file)
182
234
 
183
235
  # Generate the updated extension index and upload it and the addons .zip file to S3
184
236
  update_extension_index(
@@ -0,0 +1,114 @@
1
+ """Download the exact native Core release required by a Character DNA add-on."""
2
+
3
+ import hashlib
4
+ import io
5
+ import json
6
+ import tempfile
7
+ import zipfile
8
+ from pathlib import Path, PurePosixPath
9
+
10
+ import httpx
11
+
12
+ from poly_hammer_utils.github.release import GitHubRelease
13
+
14
+ REPOSITORY = "poly-hammer/character-dna-core"
15
+ MANIFEST = "character-dna-core-manifest.json"
16
+ PLATFORMS = ("windows-x64", "linux-x64", "macos-arm64")
17
+ PYTHONS = ("py311", "py313")
18
+ LICENSE_FOLDER = "license"
19
+ CORE_LICENSE = f"{LICENSE_FOLDER}/CHARACTER_DNA.md"
20
+ CORE_FILES = ("character_dna_core.pyi", "character_dna_core.json", CORE_LICENSE)
21
+
22
+
23
+ def download_asset(asset, auth_token: str) -> bytes:
24
+ response = httpx.get(
25
+ asset.url,
26
+ headers={
27
+ "Authorization": f"Bearer {auth_token}",
28
+ "Accept": "application/octet-stream",
29
+ },
30
+ follow_redirects=True,
31
+ timeout=120.0,
32
+ )
33
+ response.raise_for_status()
34
+ return response.content
35
+
36
+
37
+ def get_core_bindings(
38
+ auth_token: str, addon_version: str
39
+ ) -> tuple[Path, list[Path], dict]:
40
+ """Verify all six interpreter folders before exposing any downloaded files."""
41
+ expected_tag = f"v{addon_version}"
42
+ releases = GitHubRelease(repo=REPOSITORY, github_token=auth_token)
43
+ tag, attachments = releases.get_releases_attachments(tag=expected_tag)
44
+ if tag != expected_tag:
45
+ raise ValueError(
46
+ f"Publish Character DNA Core {expected_tag} before packaging this add-on"
47
+ )
48
+ assets = {asset.name: asset for asset in attachments}
49
+ if MANIFEST not in assets or len(assets) != len(attachments):
50
+ raise ValueError("Core release has no unique manifest")
51
+ manifest = json.loads(download_asset(assets[MANIFEST], auth_token))
52
+ if manifest["version"] != addon_version or manifest["repository"] != REPOSITORY:
53
+ raise ValueError("Core release and add-on versions differ")
54
+ expected_assets = {
55
+ f"character-dna-core-{addon_version}-{platform}.zip" for platform in PLATFORMS
56
+ }
57
+ rows = manifest["artifacts"]
58
+ if len(rows) != 3 or {row["name"] for row in rows} != expected_assets:
59
+ raise ValueError("Core release platform matrix is incomplete")
60
+ contents = {}
61
+ for row in rows:
62
+ if row["name"] not in assets:
63
+ raise ValueError(f"Missing Core release asset: {row['name']}")
64
+ data = download_asset(assets[row["name"]], auth_token)
65
+ if hashlib.sha256(data).hexdigest() != row["sha256"]:
66
+ raise ValueError(f"Core release checksum mismatch: {row['name']}")
67
+ platform = next(p for p in PLATFORMS if row["name"].endswith(f"-{p}.zip"))
68
+ system, architecture = platform.split("-")
69
+ with zipfile.ZipFile(io.BytesIO(data)) as archive:
70
+ for member in archive.infolist():
71
+ name = member.filename
72
+ path = PurePosixPath(name)
73
+ if (
74
+ len(path.parts) < 4
75
+ or path.parts[:2] != (system, architecture)
76
+ or path.parts[2] not in PYTHONS
77
+ or "\\" in name
78
+ or ".." in path.parts
79
+ or name in contents
80
+ or (member.external_attr >> 16) & 0o170000 == 0o120000
81
+ ):
82
+ raise ValueError(f"Unexpected Core release path: {name}")
83
+ # Binaries sit at the top of the interpreter folder; only the license is nested.
84
+ filename = PurePosixPath(*path.parts[3:]).as_posix()
85
+ if filename not in CORE_FILES:
86
+ extension = ".pyd" if system == "windows" else ".so"
87
+ if (
88
+ len(path.parts) != 4
89
+ or not filename.startswith("character_dna_core.")
90
+ or not filename.endswith(extension)
91
+ ):
92
+ raise ValueError(f"Unexpected native Core file: {name}")
93
+ content = archive.read(member)
94
+ if hashlib.sha256(content).hexdigest() != manifest["files"].get(name):
95
+ raise ValueError(f"Core file checksum mismatch: {name}")
96
+ contents[name] = content
97
+ if set(contents) != set(manifest["files"]):
98
+ raise ValueError("Core release file manifest is incomplete")
99
+ for platform in PLATFORMS:
100
+ for python in PYTHONS:
101
+ prefix = f"{platform.replace('-', '/')}/{python}/"
102
+ names = {
103
+ name.removeprefix(prefix) for name in contents if name.startswith(prefix)
104
+ }
105
+ if len(names) != 4 or not set(CORE_FILES) <= names:
106
+ raise ValueError(f"Incomplete Core interpreter folder: {prefix}")
107
+ root = Path(tempfile.mkdtemp(prefix="character-dna-core-")) / "bindings"
108
+ paths = []
109
+ for name, data in sorted(contents.items()):
110
+ target = root / name
111
+ target.parent.mkdir(parents=True, exist_ok=True)
112
+ target.write_bytes(data)
113
+ paths.append(target)
114
+ return root, paths, manifest
@@ -31,6 +31,17 @@ def get_addon_version(
31
31
  return manifest_data.get('version', '')
32
32
  return ''
33
33
 
34
+
35
+ def get_addon_platforms(
36
+ source_folder: Path,
37
+ ) -> list[str]:
38
+ file_path = source_folder / 'blender_manifest.toml'
39
+ # Read the platforms from the manifest file; an empty list means every platform
40
+ if file_path.exists():
41
+ manifest_data = tomlkit.parse(file_path.read_text())
42
+ return [str(platform) for platform in manifest_data.get('platforms', [])]
43
+ return []
44
+
34
45
  def parse_blender_extension_zip_info(url: str) -> tuple[str, str]:
35
46
  # parse the platform and arch from the attachment name
36
47
  base = Path(url).stem.split('-')[-1]