Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lkuchenb committed May 16, 2024
1 parent 7052672 commit 794686c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""A transformation to add content properties."""

from metldata.builtin_transformations.add_content_properties.main import (
ADD_CONTENT_PROPERTIES_TRANSFORMATION, # noqa: F401
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,14 @@
from pydantic import Field
from pydantic_settings import BaseSettings

from metldata.builtin_transformations.common import NewContentSchemaPath

DEFAULT_CONTENT_SCHEMA: Final[dict[str, Any]] = {
"type": "object",
"additionalProperties": False,
}


class NewContentSchemaPath(BaseSettings):
"""A model describing the path of an object property within the content schema that
is yet to be added. The model comprises a path to an already existing object within
the content schema and the name of a property to be added to that object's schema
"""

object_path: str = Field(
...,
description=(
"The path to the content object to which a property shall be added. The"
+ " path must be specified in dot notation, equivalently to JavaScript"
+ " property accessors."
),
examples=["some_property.another_nested_property"],
)

property_name: str = Field(..., description="The name of the property to be added.")


class AddContentPropertyInstruction(BaseSettings):
"""A model describing an instruction to add a new content property to a class in a
schemapack, including an associated default value in corresponding data.
Expand Down
20 changes: 20 additions & 0 deletions src/metldata/builtin_transformations/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Common models and functions for the built-in transformations."""

from metldata.builtin_transformations.common.contentschema import (
NewContentSchemaPath, # noqa: F401
)
37 changes: 37 additions & 0 deletions src/metldata/builtin_transformations/common/contentschema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Models and functions related to content schema manipulation."""

from pydantic import Field
from pydantic_settings import BaseSettings


class NewContentSchemaPath(BaseSettings):
"""A model describing the path of an object property within the content schema that
is yet to be added. The model comprises a path to an already existing object within
the content schema and the name of a property to be added to that object's schema
"""

object_path: str = Field(
...,
description=(
"The path to the content object to which a property shall be added. The"
+ " path must be specified in dot notation, equivalently to JavaScript"
+ " property accessors."
),
examples=["some_property.another_nested_property"],
)

property_name: str = Field(..., description="The name of the property to be added.")
4 changes: 2 additions & 2 deletions tests/fixtures/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from schemapack.spec.datapack import DataPack
from schemapack.spec.schemapack import SchemaPack

from metldata.builtin_transformations.add_content_properties.main import (
from metldata.builtin_transformations.add_content_properties import (
ADD_CONTENT_PROPERTIES_TRANSFORMATION,
)
from metldata.builtin_transformations.delete_properties.main import (
from metldata.builtin_transformations.delete_properties import (
PROPERTY_DELETION_TRANSFORMATION,
)
from metldata.builtin_transformations.infer_relations import (
Expand Down

0 comments on commit 794686c

Please sign in to comment.