From 5d3d4d03e628246d6ba64133267e461107c04114 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Thu, 4 Jan 2024 10:29:59 -0800 Subject: [PATCH 1/2] Rename `pydantic_shim.py` to `dsi_pydantic_shim` to reduce collision chance The pydantic shim we provide alongside the dbt-semantic-interfaces package is installed outside of the dbt-semantif-interfaces by pip. That is when the wheel is installed the venv lib looks something like ``` venv/ ... lib/ ...other packages dbt-semantic-interfaces ...other packages pydantic_shim.py ... ``` The problem with this is that if another package is installed which also provides a pydantic shim, we risk a name collision. Put another way if `package_foo` and `dbt-semantic-interfaces` both provide a `pydantic_shim.py` alongside their package, then pip will likely be unhappy. To avoid this we've renamed our shim to `dsi_pydantic_shim.py` to denote our shim as being specific to dbt-semantic-interfaces. --- dbt_semantic_interfaces/dataclass_serialization.py | 2 +- dbt_semantic_interfaces/implementations/base.py | 2 +- dbt_semantic_interfaces/implementations/export.py | 2 +- dbt_semantic_interfaces/implementations/metric.py | 2 +- .../implementations/project_configuration.py | 2 +- dbt_semantic_interfaces/implementations/semantic_model.py | 2 +- dbt_semantic_interfaces/validations/validator_helpers.py | 2 +- pydantic_shim.py => dsi_pydantic_shim.py | 0 8 files changed, 7 insertions(+), 7 deletions(-) rename pydantic_shim.py => dsi_pydantic_shim.py (100%) diff --git a/dbt_semantic_interfaces/dataclass_serialization.py b/dbt_semantic_interfaces/dataclass_serialization.py index 8207f4a3..4bed70aa 100644 --- a/dbt_semantic_interfaces/dataclass_serialization.py +++ b/dbt_semantic_interfaces/dataclass_serialization.py @@ -22,7 +22,7 @@ from typing_extensions import TypeAlias from dbt_semantic_interfaces.pretty_print import pformat_big_objects -from pydantic_shim import BaseModel, create_model +from dsi_pydantic_shim import BaseModel, create_model logger = logging.getLogger(__name__) diff --git a/dbt_semantic_interfaces/implementations/base.py b/dbt_semantic_interfaces/implementations/base.py index 25195649..4a016fec 100644 --- a/dbt_semantic_interfaces/implementations/base.py +++ b/dbt_semantic_interfaces/implementations/base.py @@ -10,7 +10,7 @@ PARSING_CONTEXT_KEY, ParsingContext, ) -from pydantic_shim import BaseModel, root_validator +from dsi_pydantic_shim import BaseModel, root_validator # Type alias for the implicit "Any" type used as input and output for Pydantic's parsing API PydanticParseableValueType = Any # type: ignore[misc] diff --git a/dbt_semantic_interfaces/implementations/export.py b/dbt_semantic_interfaces/implementations/export.py index c586c6e0..152613ce 100644 --- a/dbt_semantic_interfaces/implementations/export.py +++ b/dbt_semantic_interfaces/implementations/export.py @@ -10,7 +10,7 @@ from dbt_semantic_interfaces.type_enums.export_destination_type import ( ExportDestinationType, ) -from pydantic_shim import Field +from dsi_pydantic_shim import Field class PydanticExportConfig(HashableBaseModel, ProtocolHint[ExportConfig]): diff --git a/dbt_semantic_interfaces/implementations/metric.py b/dbt_semantic_interfaces/implementations/metric.py index 1bedf40a..04b4c8a4 100644 --- a/dbt_semantic_interfaces/implementations/metric.py +++ b/dbt_semantic_interfaces/implementations/metric.py @@ -20,7 +20,7 @@ MetricType, TimeGranularity, ) -from pydantic_shim import Field +from dsi_pydantic_shim import Field class PydanticMetricInputMeasure(PydanticCustomInputParser, HashableBaseModel): diff --git a/dbt_semantic_interfaces/implementations/project_configuration.py b/dbt_semantic_interfaces/implementations/project_configuration.py index 93693502..1be46fcf 100644 --- a/dbt_semantic_interfaces/implementations/project_configuration.py +++ b/dbt_semantic_interfaces/implementations/project_configuration.py @@ -19,7 +19,7 @@ ) from dbt_semantic_interfaces.protocols import ProtocolHint from dbt_semantic_interfaces.protocols.project_configuration import ProjectConfiguration -from pydantic_shim import validator +from dsi_pydantic_shim import validator class PydanticProjectConfiguration(HashableBaseModel, ModelWithMetadataParsing, ProtocolHint[ProjectConfiguration]): diff --git a/dbt_semantic_interfaces/implementations/semantic_model.py b/dbt_semantic_interfaces/implementations/semantic_model.py index 933acb55..1c584051 100644 --- a/dbt_semantic_interfaces/implementations/semantic_model.py +++ b/dbt_semantic_interfaces/implementations/semantic_model.py @@ -24,7 +24,7 @@ SemanticModelReference, TimeDimensionReference, ) -from pydantic_shim import validator +from dsi_pydantic_shim import validator class NodeRelation(HashableBaseModel): diff --git a/dbt_semantic_interfaces/validations/validator_helpers.py b/dbt_semantic_interfaces/validations/validator_helpers.py index 1f816cc3..c6d150b5 100644 --- a/dbt_semantic_interfaces/validations/validator_helpers.py +++ b/dbt_semantic_interfaces/validations/validator_helpers.py @@ -29,7 +29,7 @@ SemanticModelReference, ) from dbt_semantic_interfaces.type_enums import DimensionType -from pydantic_shim import BaseModel, Extra +from dsi_pydantic_shim import BaseModel, Extra VALIDATE_SAFELY_ERROR_STR_TMPLT = ". Issue occurred in method `{method_name}` called with {arguments_str}" ValidationContextJSON = Dict[str, Union[str, int, None]] diff --git a/pydantic_shim.py b/dsi_pydantic_shim.py similarity index 100% rename from pydantic_shim.py rename to dsi_pydantic_shim.py From 3797c551eae73c22aec95f6b7b50932324e6b6a2 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Thu, 4 Jan 2024 11:57:31 -0800 Subject: [PATCH 2/2] Update pyproject.toml to include pydantic shim in wheel distribution building Previously we weren't specifying what was to be included in the wheel build, thus the wheel distribution was going through the default paths, which were as documented [here](https://hatch.pypa.io/1.9/plugins/builder/wheel/#default-file-selection) * /__init__.py * src//__init__.py * .py * //__init__.py This meant that our pydantic shim was being excluded. This commit alters the pyproject.toml to now begin specifying the packages to be included in the wheel distribution, and notably adds our pydantic shim to it. --- .changes/unreleased/Under the Hood-20240104-120817.yaml | 6 ++++++ pyproject.toml | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 .changes/unreleased/Under the Hood-20240104-120817.yaml diff --git a/.changes/unreleased/Under the Hood-20240104-120817.yaml b/.changes/unreleased/Under the Hood-20240104-120817.yaml new file mode 100644 index 00000000..ef93ed2f --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240104-120817.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Ensure the pydantic shim is included in the wheel distribution +time: 2024-01-04T12:08:17.850576-08:00 +custom: + Author: QMalcolm + Issue: "241" diff --git a/pyproject.toml b/pyproject.toml index aa6611c6..f83c87ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,9 @@ exclude = [ "/tests", ] +[tool.hatch.build.targets.wheel] +packages = ["dbt_semantic_interfaces", "dsi_pydantic_shim.py"] + [tool.hatch.envs.dev-env.scripts] all = ["pre-commit run --all-files"]