From 3a426454c680bab3c4534101960475f38df20bdd Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Wed, 11 Oct 2023 21:31:00 -0700 Subject: [PATCH] trying to debug on CI by abusing warnings lol --- nwb_linkml/pyproject.toml | 3 ++ nwb_linkml/src/nwb_linkml/__init__.py | 2 ++ nwb_linkml/src/nwb_linkml/config.py | 12 ++++++- .../test_providers/test_provider_schema.py | 31 +++++++++++++++++-- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/nwb_linkml/pyproject.toml b/nwb_linkml/pyproject.toml index 5451559..ee6aa74 100644 --- a/nwb_linkml/pyproject.toml +++ b/nwb_linkml/pyproject.toml @@ -12,6 +12,9 @@ packages = [ {include = "nwb_linkml", from="src"}, #{include = "nwb_schema_language", from="../nwb_schema_language/src"} ] +include = [ + 'src/nwb_linkml/schema/**/*' +] [tool.poetry.dependencies] diff --git a/nwb_linkml/src/nwb_linkml/__init__.py b/nwb_linkml/src/nwb_linkml/__init__.py index 4d5d3cf..399a1b8 100644 --- a/nwb_linkml/src/nwb_linkml/__init__.py +++ b/nwb_linkml/src/nwb_linkml/__init__.py @@ -1,3 +1,5 @@ from nwb_linkml.monkeypatch import apply_patches apply_patches() +from nwb_linkml.config import Config + diff --git a/nwb_linkml/src/nwb_linkml/config.py b/nwb_linkml/src/nwb_linkml/config.py index 83c8298..3a42140 100644 --- a/nwb_linkml/src/nwb_linkml/config.py +++ b/nwb_linkml/src/nwb_linkml/config.py @@ -2,8 +2,9 @@ Manage the operation of nwb_linkml from environmental variables """ import tempfile +from typing import Any from pathlib import Path -from pydantic import Field, DirectoryPath, computed_field, field_validator, FieldValidationInfo +from pydantic import Field, DirectoryPath, computed_field, field_validator, model_validator, FieldValidationInfo from pydantic_settings import BaseSettings, SettingsConfigDict class Config(BaseSettings): @@ -48,6 +49,15 @@ class Config(BaseSettings): assert v.exists() return v + @model_validator(mode='after') + def folder_exists(self) -> 'Config': + for field, path in self.model_dump().items(): + if isinstance(path, Path): + path.mkdir(exist_ok=True, parents=True) + assert path.exists() + return self + + def __post_init__(self): self.cache_dir.mkdir(exist_ok=True) self.linkml_dir.mkdir(exist_ok=True) diff --git a/nwb_linkml/tests/test_providers/test_provider_schema.py b/nwb_linkml/tests/test_providers/test_provider_schema.py index 336eb1f..f794475 100644 --- a/nwb_linkml/tests/test_providers/test_provider_schema.py +++ b/nwb_linkml/tests/test_providers/test_provider_schema.py @@ -4,6 +4,8 @@ import os import sys import warnings from pathlib import Path +import yaml +from pprint import pformat from typing import Optional, Union, List from ..fixtures import tmp_output_dir @@ -13,6 +15,7 @@ import pytest from nwb_linkml.providers.schema import LinkMLProvider, PydanticProvider import nwb_linkml from nwb_linkml.maps.naming import version_module_case +from nwb_linkml.providers.git import DEFAULT_REPOS CORE_MODULES = ( @@ -40,9 +43,9 @@ def test_linkml_provider(tmp_output_dir, repo_version, schema_version, schema_di provider = LinkMLProvider(path=tmp_output_dir, allow_repo=False) # clear any prior output - shutil.rmtree(provider.path, ignore_errors=True) + shutil.rmtree(provider.path) assert not provider.path.exists() - assert not provider.namespace_path('core', repo_version).exists() + assert not (provider.namespace_path('core', repo_version) / 'namespace.yaml').exists() # end to end, check that we can get the 'core' repo at the latest version # in the gitrepo @@ -52,6 +55,30 @@ def test_linkml_provider(tmp_output_dir, repo_version, schema_version, schema_di assert all([mod in core.schema.imports for mod in CORE_MODULES]) assert schema_dir in [path.name for path in (provider.path / 'core').iterdir()] +def test_linkml_build_from_yaml(tmp_output_dir): + core = DEFAULT_REPOS['core'] + git_dir = nwb_linkml.Config().git_dir / 'core' + if git_dir.exists(): + shutil.rmtree(str(git_dir)) + ns_file = core.provide_from_git('2.6.0') + assert git_dir.exists() + assert ns_file.exists() + + # for the sake of debugging CI... + with open(ns_file) as nfile: + ns_yaml = yaml.safe_load(nfile) + warnings.warn(pformat(ns_yaml)) + files = [str(f) for f in list(ns_file.parent.glob('*.yaml'))] + warnings.warn('\n'.join(files)) + + provider = LinkMLProvider(path=tmp_output_dir, allow_repo=False) + + res = provider.build_from_yaml(ns_file) + warnings.warn(pformat(res)) + + + + @pytest.mark.skip() @pytest.mark.depends(on=['test_linkml_provider'])