101101 "config_section" : "package_manager_repos" ,
102102 "accepted_configs" : ["package_manager_repo.yaml" , unified_config ],
103103 "singular" : "package manager" ,
104+ "aliases" : ["pkg" , "package" ],
104105 },
105106 ObjectTypes .workflow_managers : {
106107 "file_name" : "workflow_manager.py" ,
109110 "config_section" : "workflow_manager_repos" ,
110111 "accepted_configs" : ["workflow_manager_repo.yaml" , unified_config ],
111112 "singular" : "workflow manager" ,
113+ "aliases" : ["workflow" ],
112114 },
113115 ObjectTypes .systems : {
114116 "file_name" : "system.py" ,
133135 "config_section" : "base_class_repos" ,
134136 "accepted_configs" : ["base_class_repo.yaml" , unified_config ],
135137 "singular" : "base class" ,
138+ "aliases" : ["base" ],
136139 },
137140 ObjectTypes .base_applications : {
138141 "file_name" : "base_application.py" ,
157160 "config_section" : "base_package_manager_repos" ,
158161 "accepted_configs" : ["base_package_manager_repo.yaml" , unified_config ],
159162 "singular" : "base package manager" ,
163+ "aliases" : ["base_pkg" ],
160164 },
161165 ObjectTypes .base_workflow_managers : {
162166 "file_name" : "base_workflow_manager.py" ,
165169 "config_section" : "base_workflow_manager_repos" ,
166170 "accepted_configs" : ["base_workflow_manager_repo.yaml" , unified_config ],
167171 "singular" : "base workflow manager" ,
172+ "aliases" : ["base_workflow" ],
168173 },
169174 ObjectTypes .base_systems : {
170175 "file_name" : "base_system.py" ,
205210}
206211
207212
208- @functools .lru_cache (maxsize = 1 )
213+ def _normalize_type_key (key ):
214+ return str (key ).lower ().replace ("-" , "_" ).replace (" " , "_" )
215+
216+
217+ _TYPE_ALIASES = {}
218+
219+ for _obj in ObjectTypes :
220+ _tdef = type_definitions .get (_obj , {})
221+ _candidates = [
222+ _obj .name ,
223+ _tdef .get ("singular" ),
224+ _tdef .get ("abbrev" ),
225+ _tdef .get ("dir_name" ),
226+ * _tdef .get ("aliases" , []),
227+ ]
228+ for _val in _candidates :
229+ if isinstance (_val , str ):
230+ for _v in (_val , f"{ _val } s" ):
231+ _norm = _normalize_type_key (_v )
232+ _TYPE_ALIASES [_norm ] = _obj
233+ _TYPE_ALIASES [_norm .replace ("_" , "-" )] = _obj
234+
235+
209236def get_object_type_map ():
210237 """Returns a mapping from string representations of object types (singular,
211238 plural, abbrev, hyphens/underscores) to their corresponding ObjectType enum."""
212- mapping = {}
213- for obj_type , type_def in type_definitions .items ():
214- candidates = set ()
215- for key in ("abbrev" , "dir_name" , "singular" ):
216- val = type_def .get (key )
217- if val :
218- val = val .replace (" " , "_" )
219- candidates .update ([val , val .replace ("_" , "-" ), val .replace ("-" , "_" )])
239+ return _TYPE_ALIASES
240+
220241
221- for cand in candidates :
222- mapping [cand ] = obj_type
223- return mapping
242+ def simplify_object_type (type_name ):
243+ """Convert a type string or ObjectTypes member to an ObjectTypes enum member.
244+
245+ Args:
246+ type_name (ObjectTypes | str): Object type to simplify / normalize.
247+
248+ Returns:
249+ (ObjectTypes): The matching ObjectTypes enum member.
250+
251+ Raises:
252+ UnknownObjectTypeError: If type_name does not match any valid object type.
253+ """
254+ if isinstance (type_name , ObjectTypes ):
255+ return type_name
256+
257+ if isinstance (type_name , str ):
258+ key = _normalize_type_key (type_name )
259+ if key in _TYPE_ALIASES :
260+ return _TYPE_ALIASES [key ]
261+
262+ raise UnknownObjectTypeError (type_name )
263+
264+
265+ get_object_type = simplify_object_type
224266
225267
226268def _gen_path (repo_dirs = None , obj_type = default_type ):
227269 """Create a RepoPath for a specific object, add it to sys.meta_path, and return it."""
270+ obj_type = simplify_object_type (obj_type )
228271 section_name = type_definitions [obj_type ]["config_section" ]
229272 singular_name = type_definitions [obj_type ]["singular" ]
230273 repo_dirs = repo_dirs or ramble .config .get (section_name )
@@ -259,6 +302,7 @@ def list_object_files(obj_inst, object_type):
259302 This is currently used by `ramble deployment` to copy relevant files
260303 to create a self-contained repo.
261304 """
305+ object_type = simplify_object_type (object_type )
262306 type_def = type_definitions [object_type ]
263307 base_type = ObjectTypes [f"base_{ type_def ['dir_name' ]} " ]
264308 base_type_def = type_definitions [base_type ]
@@ -299,11 +343,13 @@ def list_object_files(obj_inst, object_type):
299343
300344def all_object_names (object_type = default_type ):
301345 """Convenience wrapper around ``ramble.repository.all_object_names()``."""
346+ object_type = simplify_object_type (object_type )
302347 return paths [object_type ].all_object_names ()
303348
304349
305350def get (spec , object_type = default_type ):
306351 """Convenience wrapper around ``ramble.repository.get()``."""
352+ object_type = simplify_object_type (object_type )
307353 return paths [object_type ].get (spec )
308354
309355
@@ -314,6 +360,7 @@ def get_base_class(spec):
314360
315361def get_obj_class (spec , object_type = default_type ):
316362 """Convenience wrapper around ``ramble.repository.get_obj_class()``."""
363+ object_type = simplify_object_type (object_type )
317364 return paths [object_type ].get_obj_class (spec )
318365
319366
@@ -324,6 +371,7 @@ def set_path(repo, object_type=default_type):
324371 ``sys.meta_path`` if it is a ``Repo`` or ``RepoPath``.
325372 """
326373 global paths # noqa: F824
374+ object_type = simplify_object_type (object_type )
327375 paths [object_type ] = repo
328376
329377 # make the new repo_path an importer if needed
@@ -345,6 +393,7 @@ def use_repositories(*paths_and_repos, object_type=default_type):
345393 RepoPath: Corresponding RepoPath object
346394 """
347395 global paths # noqa: F824
396+ object_type = simplify_object_type (object_type )
348397
349398 # Construct a temporary RepoPath object from
350399 temporary_repositories = RepoPath (* paths_and_repos , object_type = object_type )
@@ -1572,6 +1621,18 @@ class RepoError(ramble.error.RambleError):
15721621 """Superclass for repository-related errors."""
15731622
15741623
1624+ class UnknownObjectTypeError (RepoError ):
1625+ """Raised when an unknown or invalid object type is specified."""
1626+
1627+ def __init__ (self , type_name ):
1628+ valid_types = ", " .join (OBJECT_NAMES )
1629+ super ().__init__ (
1630+ f"Unknown object type '{ type_name } '." ,
1631+ f"Allowed types are: { valid_types } "
1632+ "(singular, plural, and abbreviation forms are accepted)." ,
1633+ )
1634+
1635+
15751636class NoRepoConfiguredError (RepoError ):
15761637 """Raised when there are no repositories configured."""
15771638
0 commit comments