@@ -24,36 +24,47 @@ def __init__(
2424 storage_options : dict | None = None ,
2525 fs : fsspec .AbstractFileSystem | None = None ,
2626 walk : bool | None = None ,
27+ types : set [str ] | None = None ,
2728 ):
2829 if fs is None :
2930 fs , path = fsspec .url_to_fs (path , ** (storage_options or {}))
3031 self .fs = fs
3132 self .url = path
3233 self .specs = {}
3334 self .children = {}
34- self .resolve (walk = walk )
35+ self .resolve (walk = walk , types = types )
3536
3637 def is_local (self ) -> bool :
3738 """Did we read this from the local filesystem"""
3839 # see also fsspec.utils.can_be_local for more flexibility with caching.
3940 return isinstance (self .fs , fsspec .implementations .local .LocalFileSystem )
4041
41- def resolve (self , subpath : str = "" , walk : bool | None = None ) -> None :
42+ def resolve (
43+ self ,
44+ subpath : str = "" ,
45+ walk : bool | None = None ,
46+ types : set [str ] | None = None ,
47+ ) -> None :
4248 """Fill out project specs in this directory
4349
4450 :param subpath: find specs at the given subpath
4551 :param walk: if None (default) only try subdirectories if root has
4652 no specs, and don't descend further. If True, recurse all directories;
4753 if False don't descend at all.
54+ :param types: names of types to allow while parsing. If empty or None, allow all
4855 """
4956 fullpath = "/" .join ([self .url , subpath ]) if subpath else self .url
5057 # sorting to ensure consistency
5158 for cls in sorted (registry , key = str ):
5259 try :
5360 logger .debug ("resolving %s as %s" , fullpath , cls )
61+ name = cls .__name__
62+ snake_name = camel_to_snake (cls .__name__ )
63+ if types and name not in types and snake_name not in types :
64+ continue
5465 inst = cls (self )
5566 inst .parse ()
56- self .specs [camel_to_snake ( cls . __name__ ) ] = inst
67+ self .specs [snake_name ] = inst
5768 except ValueError :
5869 logger .debug ("failed" )
5970 except Exception as e :
@@ -71,6 +82,7 @@ def resolve(self, subpath: str = "", walk: bool | None = None) -> None:
7182 fileinfo ["name" ],
7283 fs = self .fs ,
7384 walk = walk or False ,
85+ types = types ,
7486 )
7587 if proj2 .specs :
7688 self .children [sub ] = proj2
@@ -163,8 +175,8 @@ class ProjectSpec:
163175 def __init__ (self , root : Project , subpath : str = "" ):
164176 self .root = root
165177 self .subpath = subpath # not used yet
166- self ._contents = None
167- self ._artifacts = None
178+ self ._contents = AttrDict ()
179+ self ._artifacts = AttrDict ()
168180 if not self .match ():
169181 raise ValueError (f"Not a { type (self ).__name__ } " )
170182
0 commit comments