Skip to content

Commit

Permalink
Minor refactoring (#69)
Browse files Browse the repository at this point in the history
* Minor refactoring

* Update Template

* Fix docstring
  • Loading branch information
lkuchenb authored May 17, 2024
1 parent 7052672 commit c8ce093
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bullseye
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bookworm

ENV PYTHONUNBUFFERED 1

Expand Down
2 changes: 1 addition & 1 deletion lock/requirements-dev-template.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ setuptools>=69.5
# required since switch to pyproject.toml and pip-tools
tomli_w>=1.0

uv>=0.1.39
uv>=0.1.44
36 changes: 18 additions & 18 deletions lock/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -726,24 +726,24 @@ urllib3==2.2.1 \
--hash=sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d \
--hash=sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19
# via requests
uv==0.1.39 \
--hash=sha256:2333dd52e6734e0da6722bdd7b7257d0f8beeac89623c5cfc3888b4c56bc812e \
--hash=sha256:2ae930189742536f8178617c4ec05cb10271cb3886f6039abd36ee6ab511b160 \
--hash=sha256:2bda6686a9bb1370d7f53436d34f8ede0fa1b9877b5e152aedd9b22fc3cb33a9 \
--hash=sha256:3330bd7ab8a6160d815fdc36f48479edf6db8b58d39d20959555095ea7eb63c5 \
--hash=sha256:3365e0631a738a482d2379e565a230b135f7c5665394313829ccabf7c76c1362 \
--hash=sha256:388018659e5d73fdeb8ce13c1d812391ec981bf446ab86fb9c0e3d227f727da2 \
--hash=sha256:4c6ee1148f23aa5d6edf1a1106cc33c4aa57bdbfe8d4c5068c672105415d3b99 \
--hash=sha256:6b2acc907f7a1735dd9ffeb20d8c7aeeb86b1e5ba0a999e09433ad7f2789dc78 \
--hash=sha256:7848d703201e6867ae2c70d611e6ffd53d5e5adfc2c9abe89b6d021975e43e81 \
--hash=sha256:7ee426e0c5fa048cc44f3ac78e476121ef4365bb8bc9199d3cbffc372a80e55d \
--hash=sha256:88f5601ee957f9be2efc7a24d186f9d2641053806e107e0e42c5e522882c89e0 \
--hash=sha256:93217578e68a431df235173e390ad7df090499367cd7f5c811520fd4ea3d5047 \
--hash=sha256:c131dba5fe5079d9c5f06846649e35662901a9afd9b31de17714c63e042d91d2 \
--hash=sha256:c20b9023dac12ee518de79c91df313be7abb052440cb78f8ffb20dea81d3289e \
--hash=sha256:cd6d9629ab0e22ab2336b8d6363573ea5a7060ef82ff5d3e6da4b1b30522ef13 \
--hash=sha256:ce911087f56edc97a5792c17f682ed7611fedead0ea117f56bb6f3942eb3e7b3 \
--hash=sha256:fba96b3049aea5c1394cd360e5900e4af39829df48ed6fc55eba115c00c8195a
uv==0.1.44 \
--hash=sha256:012fcfc3789f303ee3ff9f2a6e09bc589710fed7c2dcbad4379832072bad7a95 \
--hash=sha256:05774eb086b18aad488c3140daa62a235e3f270f62bd3cc4aaaa54eed927cc5b \
--hash=sha256:26d07edb37e7bfddc3b4e1faa13420e6048ddd974b34fbc1c19fcf9bacef9e5b \
--hash=sha256:2e5a60af214f42b621aa37ad320253c64f77dbfacafa710dc42d34965c2cd27f \
--hash=sha256:2f95acffcdac507de9c8f8ed037e529df3ccea274b4453df05df3f331543f5fc \
--hash=sha256:3eeac3d8be69831430743f3d00f84ddccfbd56b6835bb52d17f97914c9adfdff \
--hash=sha256:567486ce0ad2f9778782ba6ee19d2b65516c4f4bf2b7b4fc66fc2712cd46c6d0 \
--hash=sha256:768369a0bbdea8c3a670388ec1b4a11fe5871ef40d84a43844e9b8d97a1c2ca5 \
--hash=sha256:7983b00d95290dcdea8488fa8ecdfdef5c8e7d3c92c90b8dcf405cc26b707add \
--hash=sha256:8f90e80e11da409ce88424381f5c91e7f908d6a7eec53ed4ae60c5d76698d126 \
--hash=sha256:9ef3448111b47ab95874fbf2c5ca8efd52f54de14086079e52b588d037d243f1 \
--hash=sha256:b04eb0c8dedadfe434f9756bdc1c8a09a75df83884ba4cc7d97985ee819e4f32 \
--hash=sha256:b076828cef1f1ae1c3b54fa97b9e16b32816acc521ca6ff4a54fd8b16df67eef \
--hash=sha256:d60e5b77b958c559324882da13ffa642dcd511e6a7eb9b07e7308a6d71e248de \
--hash=sha256:d82c7338f8bcb0551672e759e4115c035246321059692416ee03ebe08629b913 \
--hash=sha256:e247dca0d8d42d71032ac99ef3d72a4fcbad4ae3114ef5979878a81a40fed274 \
--hash=sha256:e8cb1047b8f81ef09e15ec8d1b8dfc371594232e2e4f3ef3acf8991fcda20a57
virtualenv==20.26.1 \
--hash=sha256:604bfdceaeece392802e6ae48e69cec49168b9c5f4a44e483963f9242eb0e78b \
--hash=sha256:7aa9982a728ae5892558bff6a2839c00b9ed145523ece2274fad6f414690ae75
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


class AddContentPropertiesTransformer(DataTransformer[AddContentPropertiesConfig]):
"""A transformer that deletes content properties from data."""
"""A transformer that adds content properties to the data."""

def transform(self, data: DataPack) -> DataPack:
"""Transforms 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 c8ce093

Please sign in to comment.