-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from Carifio24/registries
Use registries
- Loading branch information
Showing
10 changed files
with
115 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from os.path import join | ||
from subprocess import run | ||
|
||
from glue_ar.registries import compressor | ||
from glue_ar.utils import PACKAGE_DIR | ||
|
||
|
||
NODE_MODULES_DIR = join(PACKAGE_DIR, "js", "node_modules") | ||
GLTF_PIPELINE_FILEPATH = join(NODE_MODULES_DIR, "gltf-pipeline", "bin", "gltf-pipeline.js") | ||
GLTFPACK_FILEPATH = join(NODE_MODULES_DIR, "gltfpack", "cli.js") | ||
|
||
|
||
@compressor("draco") | ||
def compress_gltf_pipeline(filepath: str): | ||
run(["node", GLTF_PIPELINE_FILEPATH, "-i", filepath, "-o", filepath, "-d"], capture_output=True) | ||
|
||
|
||
@compressor("meshoptimizer") | ||
def compress_gltfpack(filepath: str): | ||
run(["node", GLTFPACK_FILEPATH, "-i", filepath, "-o", filepath], capture_output=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from collections.abc import Callable | ||
from typing import Tuple, Type, Union | ||
|
||
from glue.config import DictRegistry | ||
|
||
|
||
__all__ = ["builder", "compressor"] | ||
|
||
|
||
class BuilderRegistry(DictRegistry): | ||
|
||
def add(self, extensions: Union[str, Tuple[str]], builder: Type): | ||
if isinstance(extensions, str): | ||
self._members[extensions] = builder | ||
else: | ||
for ext in extensions: | ||
self._members[ext] = builder | ||
|
||
def __call__(self, extensions: Union[str, Tuple[str]]): | ||
def adder(builder: Type): | ||
self.add(extensions, builder) | ||
return builder | ||
return adder | ||
|
||
|
||
builder = BuilderRegistry() | ||
|
||
|
||
class CompressorRegistry(DictRegistry): | ||
|
||
def add(self, name: str, compressor: Callable[[str], None]): | ||
self._members[name] = compressor | ||
|
||
def __call__(self, name: str): | ||
def adder(compressor: Callable[[str], None]): | ||
self.add(name, compressor) | ||
return compressor | ||
return adder | ||
|
||
|
||
compressor = CompressorRegistry() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from ..registries import BuilderRegistry, CompressorRegistry | ||
|
||
|
||
def test_builder_registry(): | ||
|
||
builder_registry = BuilderRegistry() | ||
|
||
@builder_registry("ext") | ||
class ExtBuilder: | ||
pass | ||
|
||
@builder_registry(("ext1", "ext2")) | ||
class ExtsBuilder: | ||
pass | ||
|
||
assert builder_registry.members == {"ext": ExtBuilder, | ||
"ext1": ExtsBuilder, | ||
"ext2": ExtsBuilder} | ||
|
||
|
||
def test_compressor_registry(): | ||
|
||
compressor_registry = CompressorRegistry() | ||
|
||
@compressor_registry("dummy") | ||
def dummy_compressor(_filepath: str): | ||
pass | ||
|
||
assert compressor_registry.members == {"dummy": dummy_compressor} |