From cc334ae1952359dea589ff26d20b848fa7602044 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Tue, 20 Aug 2024 23:12:01 -0700 Subject: [PATCH] lint --- nwb_linkml/src/nwb_linkml/generators/pydantic.py | 6 +++++- nwb_linkml/src/nwb_linkml/providers/pydantic.py | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/nwb_linkml/src/nwb_linkml/generators/pydantic.py b/nwb_linkml/src/nwb_linkml/generators/pydantic.py index 5dec150..0f824af 100644 --- a/nwb_linkml/src/nwb_linkml/generators/pydantic.py +++ b/nwb_linkml/src/nwb_linkml/generators/pydantic.py @@ -15,8 +15,8 @@ from typing import ClassVar, Dict, List, Optional, Tuple from linkml.generators import PydanticGenerator from linkml.generators.pydanticgen.array import ArrayRepresentation, NumpydanticArray from linkml.generators.pydanticgen.build import ClassResult, SlotResult -from linkml.generators.pydanticgen.template import Import, Imports, PydanticModule from linkml.generators.pydanticgen.pydanticgen import SplitMode +from linkml.generators.pydanticgen.template import Import, Imports, PydanticModule from linkml_runtime.linkml_model.meta import ( ArrayExpression, SchemaDefinition, @@ -96,6 +96,10 @@ class NWBPydanticGenerator(PydanticGenerator): raise ValueError("Slot cannot have both range and any_of defined") def render(self) -> PydanticModule: + """ + Override of super's render method to switch the split_mode before generation depending + on whether it's a namespace schema or not + """ is_namespace = False ns_annotation = self.schemaview.schema.annotations.get("is_namespace", None) if ns_annotation: diff --git a/nwb_linkml/src/nwb_linkml/providers/pydantic.py b/nwb_linkml/src/nwb_linkml/providers/pydantic.py index 21af04f..faf24b5 100644 --- a/nwb_linkml/src/nwb_linkml/providers/pydantic.py +++ b/nwb_linkml/src/nwb_linkml/providers/pydantic.py @@ -3,14 +3,14 @@ Provider for pydantic models. """ import importlib +import multiprocessing as mp import re import sys from importlib.abc import MetaPathFinder from importlib.machinery import ModuleSpec from pathlib import Path from types import ModuleType -from typing import List, Optional, Type, TYPE_CHECKING -import multiprocessing as mp +from typing import TYPE_CHECKING, List, Optional, Type from linkml.generators.pydanticgen.pydanticgen import SplitMode, _ensure_inits, _import_to_path from pydantic import BaseModel @@ -179,7 +179,7 @@ class PydanticProvider(Provider): res.append(serialized) # then each of the other schemas :) - imported_schema: dict[str, "SchemaDefinition"] = { + imported_schema: dict[str, SchemaDefinition] = { gen.generate_module_import(sch): sch for sch in gen.schemaview.schema_map.values() } generated_imports = [i for i in rendered.python_imports if i.schema] @@ -208,10 +208,10 @@ class PydanticProvider(Provider): with mp.Pool(min(mp.cpu_count(), len(tasks))) as pool: mp_results = [pool.apply_async(self._generate_single, t) for t in tasks] for result in mp_results: - res.append(result.get()) + res.append(result.get()) # noqa: PERF401 - false positive else: for task in tasks: - res.append(self._generate_single(*task)) + res.append(self._generate_single(*task)) # noqa: PERF401 - false positive # make __init__.py files if we generated any files if len(module_paths) > 0: