aha fix black formatting include, generate core by cloning into tmp directory

This commit is contained in:
sneakers-the-rat 2024-08-20 20:26:00 -07:00
parent d03e4107a4
commit 0c51f00596
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
3 changed files with 27 additions and 12 deletions

View file

@ -117,7 +117,11 @@ class GitRepo:
path (:class:`pathlib.Path`): A directory to clone to - path (:class:`pathlib.Path`): A directory to clone to -
if ``None``, use :attr:`~.Config.git_dir` / :attr:`.NamespaceRepo.name` 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.namespace = namespace
self._commit = commit self._commit = commit
@ -135,8 +139,7 @@ class GitRepo:
Temporary directory where this repository will be cloned to Temporary directory where this repository will be cloned to
""" """
if self._temp_directory is None: if self._temp_directory is None:
git_dir = Config().git_dir self._temp_directory = self._base_directory / self.namespace.name
self._temp_directory = git_dir / self.namespace.name
if not self._temp_directory.exists(): if not self._temp_directory.exists():
self._temp_directory.mkdir(parents=True) self._temp_directory.mkdir(parents=True)

View file

@ -101,5 +101,5 @@ warn_unreachable = true
target-version = ['py38', 'py39', 'py310', 'py311'] target-version = ['py38', 'py39', 'py310', 'py311']
enable-unstable-feature = ["string_processing"] enable-unstable-feature = ["string_processing"]
preview = true preview = true
include = "nwb_linkml/.*\\.py$|nwb_schema_language/.*\\.py$" include = "nwb_linkml/.*\\.py$|nwb_schema_language/.*\\.py$|nwb_models/.*\\.py$"
line-length = 100 line-length = 100

View file

@ -50,6 +50,18 @@ def generate_core_pydantic(yaml_path: Path, output_path: Path, dry_run: bool = F
pfile.write(gen_pydantic) 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( def generate_versions(
yaml_path: Path, yaml_path: Path,
pydantic_path: Path, pydantic_path: Path,
@ -64,12 +76,7 @@ def generate_versions(
# repo.clone(force=True) # repo.clone(force=True)
repo.clone() repo.clone()
# use a directory underneath this one as the temporary directory rather than tmp_dir = make_tmp_dir()
# the default hidden one
tmp_dir = Path(__file__).parent / "__tmp__"
if tmp_dir.exists():
shutil.rmtree(tmp_dir)
tmp_dir.mkdir()
linkml_provider = LinkMLProvider(path=tmp_dir, verbose=False) linkml_provider = LinkMLProvider(path=tmp_dir, verbose=False)
pydantic_provider = PydanticProvider(path=tmp_dir, verbose=False) pydantic_provider = PydanticProvider(path=tmp_dir, verbose=False)
@ -227,10 +234,15 @@ def parser() -> ArgumentParser:
def main(): def main():
args = parser().parse_args() 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: if args.hdmf:
repo = GitRepo(HDMF_COMMON_REPO) repo = GitRepo(HDMF_COMMON_REPO, path=git_dir)
else: else:
repo = GitRepo(NWB_CORE_REPO) repo = GitRepo(NWB_CORE_REPO, path=git_dir)
if not args.dry_run: if not args.dry_run:
args.yaml.mkdir(exist_ok=True) args.yaml.mkdir(exist_ok=True)