Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

RegistryMixin - tooling for easier registry/plugin patterns across NM repos #365

Merged
merged 8 commits into from
Oct 5, 2023

Conversation

bfineran
Copy link
Contributor

@bfineran bfineran commented Sep 12, 2023

proposes a structure that can be used as a universal registry for NM parent classes that follow a registry pattern or future plugins

Classes or factories that require a registry can add RegistryMixin as a parent class to get access to the functionality. The included classmethods should work for each class that contains the mixin separately.

Supports either loading values either from the registered names or a file:name pattern for custom file impelementations.

brief example from doc

class Dataset(RegistryMixin):
    pass


# register with default name
@Dataset.register()
class ImageNetDataset(Dataset):
    pass

# load as "ImageNetDataset"
imagenet = Dataset.load("ImageNetDataset")

# register with custom name
@Dataset.register(name="cifar-dataset")
class Cifar(Dataset):
    pass

# load as "cifar-dataset"
cifar = Dataset.load_from_registry("cifar-dataset")

# load from custom file that implements a dataset
mnist = Dataset.load_from_registry("/path/to/mnnist_dataset.py:MnistDataset")

test_plan:
simple unit tests included

@bfineran bfineran requested a review from markurtz September 12, 2023 19:31
@bfineran bfineran self-assigned this Sep 12, 2023
Satrat
Satrat previously approved these changes Sep 20, 2023
Co-authored-by: Rahul Tuli <[email protected]>
@bfineran bfineran merged commit 23f40e7 into main Oct 5, 2023
@bfineran bfineran deleted the registry-mixin branch October 5, 2023 18:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants