esgvoc 0.1.2__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of esgvoc might be problematic. Click here for more details.

esgvoc/api/__init__.py CHANGED
@@ -2,7 +2,6 @@ from esgvoc.api.search import MatchingTerm, SearchType, SearchSettings
2
2
  from esgvoc.api.report import (ValidationError,
3
3
  ValidationReport,
4
4
  ValidationErrorVisitor,
5
- BasicValidationErrorVisitor,
6
5
  ProjectTermError,
7
6
  UniverseTermError)
8
7
  from esgvoc.api.universe import (get_all_terms_in_universe,
@@ -27,7 +26,13 @@ from esgvoc.api.projects import (get_all_projects,
27
26
  valid_term_in_project,
28
27
  valid_term_in_collection,
29
28
  valid_term)
30
-
29
+ from esgvoc.api.project_specs import (DrsType,
30
+ DrsPartKind,
31
+ DrsConstant,
32
+ DrsCollection,
33
+ DrsPart,
34
+ DrsSpecification,
35
+ ProjectSpecs)
31
36
 
32
37
  __all__ = ["MatchingTerm",
33
38
  "SearchType",
@@ -35,7 +40,6 @@ __all__ = ["MatchingTerm",
35
40
  "ValidationError",
36
41
  "ValidationReport",
37
42
  "ValidationErrorVisitor",
38
- "BasicValidationErrorVisitor",
39
43
  "ProjectTermError",
40
44
  "UniverseTermError",
41
45
  "get_all_terms_in_universe",
@@ -59,4 +63,11 @@ __all__ = ["MatchingTerm",
59
63
  "valid_term_in_all_projects",
60
64
  "valid_term_in_project",
61
65
  "valid_term_in_collection",
62
- "valid_term"]
66
+ "valid_term",
67
+ "DrsType",
68
+ "DrsPartKind",
69
+ "DrsConstant",
70
+ "DrsCollection",
71
+ "DrsPart",
72
+ "DrsSpecification",
73
+ "ProjectSpecs"]
@@ -1,3 +1,4 @@
1
+ from esgvoc.api.data_descriptors.directory_date import DirectoryDate
1
2
  from pydantic import BaseModel
2
3
 
3
4
  from esgvoc.api.data_descriptors.activity import Activity
@@ -25,12 +26,14 @@ from esgvoc.api.data_descriptors.table import Table
25
26
  from esgvoc.api.data_descriptors.time_range import TimeRange
26
27
  from esgvoc.api.data_descriptors.variable import Variable
27
28
  from esgvoc.api.data_descriptors.variant_label import VariantLabel
29
+ from esgvoc.api.data_descriptors.directory_date import DirectoryDate
28
30
 
29
31
 
30
32
  DATA_DESCRIPTOR_CLASS_MAPPING: dict[str, type[BaseModel]] = {
31
33
  "activity": Activity,
32
34
  "consortium": Consortium,
33
35
  "date": Date,
36
+ "directory_date": DirectoryDate,
34
37
  "experiment": Experiment,
35
38
  "forcing_index": ForcingIndex,
36
39
  "frequency": Frequency,
@@ -0,0 +1,48 @@
1
+
2
+
3
+
4
+ from __future__ import annotations
5
+ from typing import (
6
+ List
7
+ )
8
+ from pydantic.version import VERSION as PYDANTIC_VERSION
9
+ if int(PYDANTIC_VERSION[0])>=2:
10
+ from pydantic import (
11
+ BaseModel,
12
+ ConfigDict
13
+ )
14
+ else:
15
+ from pydantic import (
16
+ BaseModel
17
+ )
18
+
19
+ metamodel_version = "None"
20
+ version = "None"
21
+
22
+
23
+ class ConfiguredBaseModel(BaseModel):
24
+ model_config = ConfigDict(
25
+ validate_assignment = True,
26
+ validate_default = True,
27
+ extra = "allow",
28
+ arbitrary_types_allowed = True,
29
+ use_enum_values = True,
30
+ strict = False,
31
+ )
32
+ pass
33
+
34
+ class Part(ConfiguredBaseModel):
35
+ id: str
36
+ type : str
37
+ is_required : bool
38
+
39
+ class DirectoryDate(ConfiguredBaseModel):
40
+
41
+
42
+ id: str
43
+ type: str
44
+ regex : str
45
+
46
+ # Model rebuild
47
+ # see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model
48
+ DirectoryDate.model_rebuild()
@@ -0,0 +1,82 @@
1
+ from enum import Enum
2
+ from typing import Annotated, Literal
3
+
4
+ from pydantic import BaseModel, ConfigDict, Field
5
+
6
+
7
+ class DrsType(str, Enum):
8
+ """
9
+ The types of DRS specification (directory, file name and dataset id).
10
+ """
11
+ DIRECTORY = "directory"
12
+ """The DRS directory specification type."""
13
+ FILE_NAME = "file_name"
14
+ """The DRS file name specification type."""
15
+ DATASET_ID = "dataset_id"
16
+ """The DRS dataset id specification type."""
17
+
18
+
19
+ class DrsPartKind(str, Enum):
20
+ """
21
+ The kinds of DRS part (constant and collection).
22
+ """
23
+ CONSTANT = "constant"
24
+ """The constant part type."""
25
+ COLLECTION = "collection"
26
+ """The collection part type."""
27
+
28
+
29
+ class DrsConstant(BaseModel):
30
+ """
31
+ A constant part of a DRS specification (e.g., cmip5).
32
+ """
33
+ value: str
34
+ """The value of the a constant part."""
35
+ kind: Literal[DrsPartKind.CONSTANT] = DrsPartKind.CONSTANT
36
+ """The DRS part kind."""
37
+ def __str__(self) -> str:
38
+ return self.value
39
+
40
+
41
+ class DrsCollection(BaseModel):
42
+ """
43
+ A collection part of a DRS specification (e.g., institution_id for CMIP6).
44
+ """
45
+ collection_id: str
46
+ """The collection id."""
47
+ is_required: bool
48
+ """Whether the collection is required for the DRS specification or not."""
49
+ kind: Literal[DrsPartKind.COLLECTION] = DrsPartKind.COLLECTION
50
+ """The DRS part kind."""
51
+ def __str__(self) -> str:
52
+ return self.collection_id
53
+
54
+
55
+ DrsPart = Annotated[DrsConstant | DrsCollection, Field(discriminator="kind")]
56
+ """A fragment of a DRS specification"""
57
+
58
+
59
+ class DrsSpecification(BaseModel):
60
+ """
61
+ A DRS specification.
62
+ """
63
+ type: DrsType
64
+ """The type of the specification."""
65
+ separator: str
66
+ """The textual separator string or character."""
67
+ properties: dict|None = None
68
+ """The other specifications (e.g., file name extension for file name DRS specification)."""
69
+ parts: list[DrsPart]
70
+ """The parts of the DRS specification."""
71
+
72
+ class ProjectSpecs(BaseModel):
73
+ """
74
+ A project specifications.
75
+ """
76
+ project_id: str
77
+ """The project id."""
78
+ description: str
79
+ """The description of the project."""
80
+ drs_specs: list[DrsSpecification]
81
+ """The DRS specifications of the project (directory, file name and dataset id."""
82
+ model_config = ConfigDict(extra = "allow")