diff options
| author | Koro4e <96347170+Koro4e@users.noreply.github.com> | 2026-11-23 17:00:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-23 10:00:20 -0600 |
| commit | b66e184ebe9e6c12f6fa60faf2cf32e042d8cd2a (patch) | |
| tree | 104194338b1096e11ef9a680347b25f0204f4cb7 | |
| parent | d8e8f23b975b6c7d383125ace7378cba3dbffe38 (diff) | |
batch_glb: --textures must name a directory (#6747)
Squash-merged after diff review of PR #6747 - batch_glb: --textures must name a directory
| -rw-r--r-- | tests/test_batch_glb.py | 19 | ||||
| -rw-r--r-- | tools/batch_glb.py | 11 |
2 files changed, 28 insertions, 2 deletions
diff --git a/tests/test_batch_glb.py b/tests/test_batch_glb.py index 06940a597..6cc3bd416 100644 --- a/tests/test_batch_glb.py +++ b/tests/test_batch_glb.py | |||
| @@ -83,6 +83,25 @@ class TestBatchGlb(unittest.TestCase): | |||
| 83 | self.assertIn(error, result.stderr) | 83 | self.assertIn(error, result.stderr) |
| 84 | self.assertEqual(result.stdout, "") | 84 | self.assertEqual(result.stdout, "") |
| 85 | 85 | ||
| 86 | def test_a_textures_path_that_is_not_a_directory_is_a_usage_error(self) -> None: | ||
| 87 | # before the validator a typo'd --textures path returned an empty index and the run still | ||
| 88 | # embedded nothing and exited 0, as if the folder had no textures. | ||
| 89 | with tempfile.TemporaryDirectory() as in_dir, tempfile.TemporaryDirectory() as out_dir: | ||
| 90 | with open(os.path.join(in_dir, "m.obj"), "w", encoding="utf-8", newline="\n") as f: | ||
| 91 | f.write("o m\nv 0 0 0\nv 1 0 0\nv 0 1 0\nf 1 2 3\n") | ||
| 92 | not_a_dir = os.path.join(in_dir, "textures.txt") | ||
| 93 | with open(not_a_dir, "wb") as f: | ||
| 94 | f.write(b"x") | ||
| 95 | result = subprocess.run( | ||
| 96 | [sys.executable, "-I", os.path.join(TOOLS, "batch_glb.py"), | ||
| 97 | in_dir, out_dir, "--textures", not_a_dir], | ||
| 98 | capture_output=True, text=True, check=False, | ||
| 99 | ) | ||
| 100 | self.assertEqual(result.returncode, 2, result.stderr) | ||
| 101 | self.assertIn("argument --textures", result.stderr) | ||
| 102 | self.assertIn("not a directory", result.stderr) | ||
| 103 | self.assertEqual(os.listdir(out_dir), []) | ||
| 104 | |||
| 86 | def test_cli_accepts_valid_jobs_and_max_tex_size(self) -> None: | 105 | def test_cli_accepts_valid_jobs_and_max_tex_size(self) -> None: |
| 87 | with tempfile.TemporaryDirectory() as in_dir, tempfile.TemporaryDirectory() as out_dir: | 106 | with tempfile.TemporaryDirectory() as in_dir, tempfile.TemporaryDirectory() as out_dir: |
| 88 | obj_path = os.path.join(in_dir, "test_model.obj") | 107 | obj_path = os.path.join(in_dir, "test_model.obj") |
diff --git a/tools/batch_glb.py b/tools/batch_glb.py index e19f21c66..12f1949a0 100644 --- a/tools/batch_glb.py +++ b/tools/batch_glb.py | |||
| @@ -28,9 +28,16 @@ import glb_writer | |||
| 28 | import dds_png | 28 | import dds_png |
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | def _existing_texture_dir(value: str) -> str: | ||
| 32 | """--textures must name a directory: a typo otherwise silently embedded nothing and still exited 0.""" | ||
| 33 | if not os.path.isdir(value): | ||
| 34 | raise argparse.ArgumentTypeError(f"not a directory: {value}") | ||
| 35 | return value | ||
| 36 | |||
| 37 | |||
| 31 | def _build_texture_index(texture_dir: str | None) -> dict[str, str]: | 38 | def _build_texture_index(texture_dir: str | None) -> dict[str, str]: |
| 32 | """Index available texture files (.png and .dds) by lowercase basename without extension.""" | 39 | """Index available texture files (.png and .dds) by lowercase basename without extension.""" |
| 33 | if not texture_dir or not os.path.isdir(texture_dir): | 40 | if not texture_dir: |
| 34 | return {} | 41 | return {} |
| 35 | index: dict[str, str] = {} | 42 | index: dict[str, str] = {} |
| 36 | for entry in os.scandir(texture_dir): | 43 | for entry in os.scandir(texture_dir): |
| @@ -233,7 +240,7 @@ def main(argv: list[str] | None = None) -> int: | |||
| 233 | ) | 240 | ) |
| 234 | parser.add_argument( | 241 | parser.add_argument( |
| 235 | "--textures", | 242 | "--textures", |
| 236 | type=str, | 243 | type=_existing_texture_dir, |
| 237 | default=None, | 244 | default=None, |
| 238 | help="Optional directory containing textures (.png or .dds) to link and embed", | 245 | help="Optional directory containing textures (.png or .dds) to link and embed", |
| 239 | ) | 246 | ) |