mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-20 06:35:36 +08:00
Allow methods configs to be discovered from external packages. (#1357)
* Allow method_config to be registered from external packages * Add license * Add MethodSpecification class + fix linter errors ---------
This commit is contained in:
1 parent
bf64769128
commit
59f71eda0e
7 files changed
+183
No files matched your search
@@ -0,0 +1,51 @@
|
||||
"""
|
||||
Tests for the nerfstudio.plugins.registry module.
|
||||
"""
|
||||
import sys
|
||||
|
||||
from nerfstudio.engine.trainer import TrainerConfig
|
||||
from nerfstudio.pipelines.base_pipeline import VanillaPipelineConfig
|
||||
from nerfstudio.plugins import registry
|
||||
from nerfstudio.plugins.types import MethodSpecification
|
||||
|
||||
if sys.version_info < (3, 10):
|
||||
import importlib_metadata
|
||||
else:
|
||||
from importlib import metadata as importlib_metadata
|
||||
|
||||
|
||||
TestConfig = MethodSpecification(
|
||||
config=TrainerConfig(
|
||||
method_name="test-method",
|
||||
pipeline=VanillaPipelineConfig(),
|
||||
optimizers={},
|
||||
),
|
||||
description="Test description",
|
||||
)
|
||||
|
||||
|
||||
def test_discover_methods():
|
||||
"""Tests if a custom method gets properly registered using the discover_methods method"""
|
||||
entry_points_backup = registry.entry_points
|
||||
|
||||
def entry_points(group=None):
|
||||
return importlib_metadata.EntryPoints(
|
||||
[
|
||||
importlib_metadata.EntryPoint(
|
||||
name="test", value="test_registry:TestConfig", group="nerfstudio.method_configs"
|
||||
)
|
||||
]
|
||||
).select(group=group)
|
||||
|
||||
try:
|
||||
# Mock importlib entry_points
|
||||
registry.entry_points = entry_points
|
||||
|
||||
# Discover plugins
|
||||
methods, _ = registry.discover_methods()
|
||||
assert "test-method" in methods
|
||||
config = methods["test-method"]
|
||||
assert isinstance(config, TrainerConfig)
|
||||
finally:
|
||||
# Revert mock
|
||||
registry.entry_points = entry_points_backup
|
||||
Reference in new issue
Block a user