From 0c51f00596762df885d4c284f73c5ea64b04a309 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Tue, 20 Aug 2024 20:26:00 -0700 Subject: [PATCH] aha fix black formatting include, generate core by cloning into tmp directory --- nwb_linkml/src/nwb_linkml/providers/git.py | 9 ++++--- pyproject.toml | 2 +- scripts/generate_core.py | 28 +++++++++++++++------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/nwb_linkml/src/nwb_linkml/providers/git.py b/nwb_linkml/src/nwb_linkml/providers/git.py index 8219aaf..77afc59 100644 --- a/nwb_linkml/src/nwb_linkml/providers/git.py +++ b/nwb_linkml/src/nwb_linkml/providers/git.py @@ -117,7 +117,11 @@ class GitRepo: path (:class:`pathlib.Path`): A directory to clone to - if ``None``, use :attr:`~.Config.git_dir` / :attr:`.NamespaceRepo.name` """ - self._temp_directory = path + if path is None: + self._base_directory = Config().git_dir + else: + self._base_directory = Path(path) + self._temp_directory = None self.namespace = namespace self._commit = commit @@ -135,8 +139,7 @@ class GitRepo: Temporary directory where this repository will be cloned to """ if self._temp_directory is None: - git_dir = Config().git_dir - self._temp_directory = git_dir / self.namespace.name + self._temp_directory = self._base_directory / self.namespace.name if not self._temp_directory.exists(): self._temp_directory.mkdir(parents=True) diff --git a/pyproject.toml b/pyproject.toml index 30d5e43..99b5e1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,5 +101,5 @@ warn_unreachable = true target-version = ['py38', 'py39', 'py310', 'py311'] enable-unstable-feature = ["string_processing"] preview = true -include = "nwb_linkml/.*\\.py$|nwb_schema_language/.*\\.py$" +include = "nwb_linkml/.*\\.py$|nwb_schema_language/.*\\.py$|nwb_models/.*\\.py$" line-length = 100 \ No newline at end of file diff --git a/scripts/generate_core.py b/scripts/generate_core.py index 620d9d4..ad593cf 100644 --- a/scripts/generate_core.py +++ b/scripts/generate_core.py @@ -50,6 +50,18 @@ def generate_core_pydantic(yaml_path: Path, output_path: Path, dry_run: bool = F pfile.write(gen_pydantic) +def make_tmp_dir(clear: bool = False) -> Path: + # use a directory underneath this one as the temporary directory rather than + # the default hidden one + tmp_dir = Path(__file__).parent / "__tmp__" + if tmp_dir.exists() and clear: + for p in tmp_dir.iterdir(): + if p.is_dir() and not p.name == "git": + shutil.rmtree(tmp_dir) + tmp_dir.mkdir(exist_ok=True) + return tmp_dir + + def generate_versions( yaml_path: Path, pydantic_path: Path, @@ -64,12 +76,7 @@ def generate_versions( # repo.clone(force=True) repo.clone() - # use a directory underneath this one as the temporary directory rather than - # the default hidden one - tmp_dir = Path(__file__).parent / "__tmp__" - if tmp_dir.exists(): - shutil.rmtree(tmp_dir) - tmp_dir.mkdir() + tmp_dir = make_tmp_dir() linkml_provider = LinkMLProvider(path=tmp_dir, verbose=False) pydantic_provider = PydanticProvider(path=tmp_dir, verbose=False) @@ -227,10 +234,15 @@ def parser() -> ArgumentParser: def main(): args = parser().parse_args() + + tmp_dir = make_tmp_dir(clear=True) + git_dir = tmp_dir / "git" + git_dir.mkdir(exist_ok=True) + if args.hdmf: - repo = GitRepo(HDMF_COMMON_REPO) + repo = GitRepo(HDMF_COMMON_REPO, path=git_dir) else: - repo = GitRepo(NWB_CORE_REPO) + repo = GitRepo(NWB_CORE_REPO, path=git_dir) if not args.dry_run: args.yaml.mkdir(exist_ok=True)