make allow_repo an instance-level setting

This commit is contained in:
sneakers-the-rat 2023-10-11 20:55:03 -07:00
parent 38d83f3279
commit 52754112aa
3 changed files with 15 additions and 8 deletions

View file

@ -164,7 +164,7 @@ class MapArrayLikeAttributes(DatasetMap):
if all([cls.dims, cls.shape]) and \ if all([cls.dims, cls.shape]) and \
cls.neurodata_type_inc != 'VectorData' and \ cls.neurodata_type_inc != 'VectorData' and \
has_attrs(cls) and \ has_attrs(cls) and \
(dtype is 'AnyType' or dtype in flat_to_linkml): (dtype == 'AnyType' or dtype in flat_to_linkml):
return True return True
else: else:

View file

@ -82,6 +82,11 @@ class Provider(ABC):
Attributes: Attributes:
config (:class:`.Config`): Configuration for the directories used by this config (:class:`.Config`): Configuration for the directories used by this
provider, unless overridden by ``path`` provider, unless overridden by ``path``
allow_repo (bool): Allow the pathfinder to return the installed repository/package,
useful to enforce building into temporary directories, decoupling finding a path
during loading vs. building. Building into the repo is still possible if both
namespace and version are provided (ie. the path is fully qualified) and
:attr:`.config`'s path is the repository path.
cache_dir (:class:`pathlib.Path`): The main cache directory under which the other cache_dir (:class:`pathlib.Path`): The main cache directory under which the other
providers will store the things they provide providers will store the things they provide
""" """
@ -90,6 +95,7 @@ class Provider(ABC):
def __init__(self, def __init__(self,
path: Optional[Path] = None, path: Optional[Path] = None,
allow_repo: bool = True,
verbose: bool = True): verbose: bool = True):
if path is not None: if path is not None:
config = Config(cache_dir=path) config = Config(cache_dir=path)
@ -97,6 +103,7 @@ class Provider(ABC):
config = Config() config = Config()
self.config = config self.config = config
self.cache_dir = config.cache_dir self.cache_dir = config.cache_dir
self.allow_repo = allow_repo
self.verbose = verbose self.verbose = verbose
@property @property
@ -124,7 +131,7 @@ class Provider(ABC):
self, self,
namespace: str, namespace: str,
version: Optional[str] = None, version: Optional[str] = None,
allow_repo: bool = True allow_repo: Optional[bool] = None
) -> Path: ) -> Path:
""" """
Get the location for a given namespace of this type. Get the location for a given namespace of this type.
@ -141,12 +148,11 @@ class Provider(ABC):
recent *version*, but the most recently *generated* version recent *version*, but the most recently *generated* version
because it's assumed that's the one you want if you're just because it's assumed that's the one you want if you're just
gesturally reaching for one. gesturally reaching for one.
allow_repo (bool): Allow the pathfinder to return the installed repository/package, allow_repo (bool): Optional - override instance-level ``allow_repo`` attr
useful to enforce building into temporary directories, decoupling finding a path
during loading vs. building. Building into the repo is still possible if both
namespace and version are provided (ie. the path is fully qualified) and
:attr:`.config`'s path is the repository path.
""" """
if allow_repo is None:
allow_repo = self.allow_repo
namespace_module = module_case(namespace) namespace_module = module_case(namespace)
namespace_path = self.path / namespace_module namespace_path = self.path / namespace_module
if not namespace_path.exists() and namespace in ('core', 'hdmf-common') and allow_repo: if not namespace_path.exists() and namespace in ('core', 'hdmf-common') and allow_repo:

View file

@ -38,10 +38,11 @@ CORE_MODULES = (
) )
def test_linkml_provider(tmp_output_dir, repo_version, schema_version, schema_dir): def test_linkml_provider(tmp_output_dir, repo_version, schema_version, schema_dir):
provider = LinkMLProvider(path=tmp_output_dir) provider = LinkMLProvider(path=tmp_output_dir, allow_repo=False)
# clear any prior output # clear any prior output
shutil.rmtree(provider.path, ignore_errors=True) shutil.rmtree(provider.path, ignore_errors=True)
assert not provider.path.exists() assert not provider.path.exists()
assert not provider.namespace_path('core', repo_version).exists()
# end to end, check that we can get the 'core' repo at the latest version # end to end, check that we can get the 'core' repo at the latest version
# in the gitrepo # in the gitrepo