mirror of
https://github.com/p2p-ld/nwb-linkml.git
synced 2024-11-12 17:54:29 +00:00
decrease deprecation warnings
This commit is contained in:
parent
15d1f0d7b1
commit
24e0b704ff
2 changed files with 31 additions and 10 deletions
|
@ -56,7 +56,7 @@ class LinkML_Meta(BaseModel):
|
|||
tree_root: bool = False
|
||||
|
||||
|
||||
def default_template(pydantic_ver: str = "1", extra_classes:Optional[List[Type[BaseModel]]] = None) -> str:
|
||||
def default_template(pydantic_ver: str = "2", extra_classes:Optional[List[Type[BaseModel]]] = None) -> str:
|
||||
"""Constructs a default template for pydantic classes based on the version of pydantic"""
|
||||
### HEADER ###
|
||||
template = """
|
||||
|
@ -68,7 +68,12 @@ from __future__ import annotations
|
|||
from datetime import datetime, date
|
||||
from enum import Enum
|
||||
from typing import List, Dict, Optional, Any, Union, ClassVar
|
||||
from pydantic import BaseModel as BaseModel, Field
|
||||
from pydantic import BaseModel as BaseModel, Field"""
|
||||
if pydantic_ver == '2':
|
||||
template += """
|
||||
from pydantic import ConfigDict
|
||||
"""
|
||||
template +="""
|
||||
from nptyping import Shape, Float, Float32, Double, Float64, LongLong, Int64, Int, Int32, Int16, Short, Int8, UInt, UInt32, UInt16, UInt8, UInt64, Number, String, Unicode, Unicode, Unicode, String, Bool, Datetime64
|
||||
from nwb_linkml.types import NDArray
|
||||
import sys
|
||||
|
@ -102,12 +107,14 @@ class ConfiguredBaseModel(WeakRefShimBaseModel,
|
|||
"""
|
||||
else:
|
||||
template += """
|
||||
class ConfiguredBaseModel(BaseModel,
|
||||
validate_assignment = True,
|
||||
validate_default = True,
|
||||
extra = {% if allow_extra %}'allow'{% else %}'forbid'{% endif %},
|
||||
arbitrary_types_allowed = True,
|
||||
use_enum_values = True):
|
||||
class ConfiguredBaseModel(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
validate_assignment = True,
|
||||
validate_default = True,
|
||||
extra = {% if allow_extra %}'allow'{% else %}'forbid'{% endif %},
|
||||
arbitrary_types_allowed = True,
|
||||
use_enum_values = True
|
||||
)
|
||||
"""
|
||||
### Injected Fields
|
||||
template += """
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Monkeypatches to external modules
|
||||
"""
|
||||
|
||||
def patch_npytyping():
|
||||
def patch_npytyping_perf():
|
||||
"""
|
||||
npytyping makes an expensive call to inspect.stack()
|
||||
that makes imports of pydantic models take ~200x longer than
|
||||
|
@ -38,6 +38,19 @@ def patch_npytyping():
|
|||
dataframe.DataFrameMeta.__module__ = property(new_module_dataframe)
|
||||
base_meta_classes.SubscriptableMeta._get_module = new_get_module
|
||||
|
||||
def patch_nptyping_warnings():
|
||||
"""
|
||||
nptyping shits out a bunch of numpy deprecation warnings from using
|
||||
olde aliases
|
||||
"""
|
||||
import warnings
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
category=DeprecationWarning,
|
||||
module='nptyping.*'
|
||||
)
|
||||
|
||||
|
||||
def patch_schemaview():
|
||||
"""
|
||||
Patch schemaview to correctly resolve multiple layers of relative imports.
|
||||
|
@ -96,5 +109,6 @@ def patch_schemaview():
|
|||
SchemaView.imports_closure = imports_closure
|
||||
|
||||
def apply_patches():
|
||||
patch_npytyping()
|
||||
patch_npytyping_perf()
|
||||
patch_nptyping_warnings()
|
||||
patch_schemaview()
|
Loading…
Reference in a new issue