apache-hamilton 1.90.0.dev0__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.
- apache_hamilton-1.90.0.dev0.dist-info/METADATA +407 -0
- apache_hamilton-1.90.0.dev0.dist-info/RECORD +151 -0
- apache_hamilton-1.90.0.dev0.dist-info/WHEEL +4 -0
- apache_hamilton-1.90.0.dev0.dist-info/entry_points.txt +9 -0
- apache_hamilton-1.90.0.dev0.dist-info/licenses/DISCLAIMER +10 -0
- apache_hamilton-1.90.0.dev0.dist-info/licenses/LICENSE +228 -0
- apache_hamilton-1.90.0.dev0.dist-info/licenses/NOTICE +5 -0
- hamilton/__init__.py +24 -0
- hamilton/ad_hoc_utils.py +132 -0
- hamilton/async_driver.py +465 -0
- hamilton/base.py +466 -0
- hamilton/caching/__init__.py +16 -0
- hamilton/caching/adapter.py +1475 -0
- hamilton/caching/cache_key.py +70 -0
- hamilton/caching/fingerprinting.py +287 -0
- hamilton/caching/stores/__init__.py +16 -0
- hamilton/caching/stores/base.py +242 -0
- hamilton/caching/stores/file.py +140 -0
- hamilton/caching/stores/memory.py +297 -0
- hamilton/caching/stores/sqlite.py +282 -0
- hamilton/caching/stores/utils.py +40 -0
- hamilton/cli/__init__.py +16 -0
- hamilton/cli/__main__.py +328 -0
- hamilton/cli/commands.py +126 -0
- hamilton/cli/logic.py +338 -0
- hamilton/common/__init__.py +76 -0
- hamilton/contrib/__init__.py +41 -0
- hamilton/data_quality/__init__.py +16 -0
- hamilton/data_quality/base.py +198 -0
- hamilton/data_quality/default_validators.py +560 -0
- hamilton/data_quality/pandera_validators.py +121 -0
- hamilton/dataflows/__init__.py +726 -0
- hamilton/dataflows/template/README.md +25 -0
- hamilton/dataflows/template/__init__.py +54 -0
- hamilton/dataflows/template/author.md +28 -0
- hamilton/dataflows/template/requirements.txt +0 -0
- hamilton/dataflows/template/tags.json +7 -0
- hamilton/dataflows/template/valid_configs.jsonl +1 -0
- hamilton/dev_utils/__init__.py +16 -0
- hamilton/dev_utils/deprecation.py +204 -0
- hamilton/driver.py +2112 -0
- hamilton/execution/__init__.py +16 -0
- hamilton/execution/debugging_utils.py +56 -0
- hamilton/execution/executors.py +502 -0
- hamilton/execution/graph_functions.py +421 -0
- hamilton/execution/grouping.py +430 -0
- hamilton/execution/state.py +539 -0
- hamilton/experimental/__init__.py +27 -0
- hamilton/experimental/databackend.py +61 -0
- hamilton/experimental/decorators/__init__.py +16 -0
- hamilton/experimental/decorators/parameterize_frame.py +233 -0
- hamilton/experimental/h_async.py +29 -0
- hamilton/experimental/h_cache.py +413 -0
- hamilton/experimental/h_dask.py +28 -0
- hamilton/experimental/h_databackends.py +174 -0
- hamilton/experimental/h_ray.py +28 -0
- hamilton/experimental/h_spark.py +32 -0
- hamilton/function_modifiers/README +40 -0
- hamilton/function_modifiers/__init__.py +121 -0
- hamilton/function_modifiers/adapters.py +900 -0
- hamilton/function_modifiers/base.py +859 -0
- hamilton/function_modifiers/configuration.py +310 -0
- hamilton/function_modifiers/delayed.py +202 -0
- hamilton/function_modifiers/dependencies.py +246 -0
- hamilton/function_modifiers/expanders.py +1230 -0
- hamilton/function_modifiers/macros.py +1634 -0
- hamilton/function_modifiers/metadata.py +434 -0
- hamilton/function_modifiers/recursive.py +908 -0
- hamilton/function_modifiers/validation.py +289 -0
- hamilton/function_modifiers_base.py +31 -0
- hamilton/graph.py +1153 -0
- hamilton/graph_types.py +264 -0
- hamilton/graph_utils.py +41 -0
- hamilton/htypes.py +450 -0
- hamilton/io/__init__.py +32 -0
- hamilton/io/data_adapters.py +216 -0
- hamilton/io/default_data_loaders.py +224 -0
- hamilton/io/materialization.py +500 -0
- hamilton/io/utils.py +158 -0
- hamilton/lifecycle/__init__.py +67 -0
- hamilton/lifecycle/api.py +833 -0
- hamilton/lifecycle/base.py +1130 -0
- hamilton/lifecycle/default.py +802 -0
- hamilton/log_setup.py +47 -0
- hamilton/models.py +92 -0
- hamilton/node.py +449 -0
- hamilton/plugins/README.md +48 -0
- hamilton/plugins/__init__.py +16 -0
- hamilton/plugins/dask_extensions.py +47 -0
- hamilton/plugins/dlt_extensions.py +161 -0
- hamilton/plugins/geopandas_extensions.py +49 -0
- hamilton/plugins/h_dask.py +331 -0
- hamilton/plugins/h_ddog.py +522 -0
- hamilton/plugins/h_diskcache.py +163 -0
- hamilton/plugins/h_experiments/__init__.py +22 -0
- hamilton/plugins/h_experiments/__main__.py +62 -0
- hamilton/plugins/h_experiments/cache.py +39 -0
- hamilton/plugins/h_experiments/data_model.py +68 -0
- hamilton/plugins/h_experiments/hook.py +219 -0
- hamilton/plugins/h_experiments/server.py +375 -0
- hamilton/plugins/h_kedro.py +152 -0
- hamilton/plugins/h_logging.py +454 -0
- hamilton/plugins/h_mcp/__init__.py +28 -0
- hamilton/plugins/h_mcp/__main__.py +33 -0
- hamilton/plugins/h_mcp/_helpers.py +129 -0
- hamilton/plugins/h_mcp/_templates.py +417 -0
- hamilton/plugins/h_mcp/server.py +328 -0
- hamilton/plugins/h_mlflow.py +335 -0
- hamilton/plugins/h_narwhals.py +134 -0
- hamilton/plugins/h_openlineage.py +400 -0
- hamilton/plugins/h_opentelemetry.py +167 -0
- hamilton/plugins/h_pandas.py +257 -0
- hamilton/plugins/h_pandera.py +117 -0
- hamilton/plugins/h_polars.py +304 -0
- hamilton/plugins/h_polars_lazyframe.py +282 -0
- hamilton/plugins/h_pyarrow.py +56 -0
- hamilton/plugins/h_pydantic.py +127 -0
- hamilton/plugins/h_ray.py +242 -0
- hamilton/plugins/h_rich.py +142 -0
- hamilton/plugins/h_schema.py +493 -0
- hamilton/plugins/h_slack.py +100 -0
- hamilton/plugins/h_spark.py +1380 -0
- hamilton/plugins/h_threadpool.py +125 -0
- hamilton/plugins/h_tqdm.py +122 -0
- hamilton/plugins/h_vaex.py +129 -0
- hamilton/plugins/huggingface_extensions.py +236 -0
- hamilton/plugins/ibis_extensions.py +93 -0
- hamilton/plugins/jupyter_magic.py +622 -0
- hamilton/plugins/kedro_extensions.py +117 -0
- hamilton/plugins/lightgbm_extensions.py +99 -0
- hamilton/plugins/matplotlib_extensions.py +108 -0
- hamilton/plugins/mlflow_extensions.py +216 -0
- hamilton/plugins/numpy_extensions.py +105 -0
- hamilton/plugins/pandas_extensions.py +1763 -0
- hamilton/plugins/plotly_extensions.py +150 -0
- hamilton/plugins/polars_extensions.py +71 -0
- hamilton/plugins/polars_implementations.py +25 -0
- hamilton/plugins/polars_lazyframe_extensions.py +302 -0
- hamilton/plugins/polars_post_1_0_0_extensions.py +877 -0
- hamilton/plugins/polars_pre_1_0_0_extension.py +836 -0
- hamilton/plugins/pydantic_extensions.py +98 -0
- hamilton/plugins/pyspark_pandas_extensions.py +47 -0
- hamilton/plugins/sklearn_plot_extensions.py +129 -0
- hamilton/plugins/spark_extensions.py +105 -0
- hamilton/plugins/vaex_extensions.py +51 -0
- hamilton/plugins/xgboost_extensions.py +91 -0
- hamilton/plugins/yaml_extensions.py +89 -0
- hamilton/registry.py +254 -0
- hamilton/settings.py +18 -0
- hamilton/telemetry.py +50 -0
- hamilton/version.py +18 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
|
4
|
+
distributed with this work for additional information
|
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
|
7
|
+
"License"); you may not use this file except in compliance
|
|
8
|
+
with the License. You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
|
13
|
+
software distributed under the License is distributed on an
|
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
KIND, either express or implied. See the License for the
|
|
16
|
+
specific language governing permissions and limitations
|
|
17
|
+
under the License.
|
|
18
|
+
-->
|
|
19
|
+
# Purpose of this module
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# Configuration Options
|
|
23
|
+
This module can be configured with the following options:
|
|
24
|
+
|
|
25
|
+
# Limitations
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
18
|
+
# --- START LICENSE (optional)
|
|
19
|
+
# --- END LICENSE
|
|
20
|
+
# --- START IMPORT SECTION
|
|
21
|
+
import logging
|
|
22
|
+
|
|
23
|
+
from hamilton import contrib
|
|
24
|
+
|
|
25
|
+
logger = logging.getLogger(__name__)
|
|
26
|
+
|
|
27
|
+
with contrib.catch_import_errors(__name__, __file__, logger):
|
|
28
|
+
# non-hamilton imports go here
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
# hamilton imports go here; check for required version if need be.
|
|
32
|
+
|
|
33
|
+
# --- END IMPORT SECTION
|
|
34
|
+
|
|
35
|
+
# --- START HAMILTON DATAFLOW
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# --- END HAMILTON DATAFLOW
|
|
39
|
+
# --- START MAIN CODE
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
# Code to create an imaging showing on DAG workflow.
|
|
42
|
+
# run as a script to test Hamilton's execution
|
|
43
|
+
import __init__ as MODULE_NAME
|
|
44
|
+
|
|
45
|
+
from hamilton import base, driver
|
|
46
|
+
|
|
47
|
+
dr = driver.Driver(
|
|
48
|
+
{}, # CONFIG: fill as appropriate
|
|
49
|
+
MODULE_NAME,
|
|
50
|
+
adapter=base.DefaultAdapter(),
|
|
51
|
+
)
|
|
52
|
+
# saves to current working directory creating dag.png.
|
|
53
|
+
dr.display_all_functions("dag", {"format": "png", "view": False})
|
|
54
|
+
# --- END MAIN CODE
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
|
4
|
+
distributed with this work for additional information
|
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
|
7
|
+
"License"); you may not use this file except in compliance
|
|
8
|
+
with the License. You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
|
13
|
+
software distributed under the License is distributed on an
|
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
KIND, either express or implied. See the License for the
|
|
16
|
+
specific language governing permissions and limitations
|
|
17
|
+
under the License.
|
|
18
|
+
-->
|
|
19
|
+
|
|
20
|
+
# {github_username}
|
|
21
|
+
|
|
22
|
+
Hi I'm ...
|
|
23
|
+
|
|
24
|
+
# Github
|
|
25
|
+
https://github.com/{github_username}
|
|
26
|
+
# Linkedin
|
|
27
|
+
|
|
28
|
+
# X (Twitter)
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
18
|
+
import dataclasses
|
|
19
|
+
import functools
|
|
20
|
+
import logging
|
|
21
|
+
import types
|
|
22
|
+
from collections.abc import Callable
|
|
23
|
+
|
|
24
|
+
from hamilton import version
|
|
25
|
+
|
|
26
|
+
logger = logging.getLogger(__name__)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclasses.dataclass
|
|
30
|
+
class Version:
|
|
31
|
+
major: int
|
|
32
|
+
minor: int
|
|
33
|
+
patch: int
|
|
34
|
+
|
|
35
|
+
def __gt__(self, other: "Version"):
|
|
36
|
+
return (self.major, self.minor, self.patch) > (other.major, other.minor, other.patch)
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def from_version_tuple(version_tuple: tuple[int | str, ...]) -> "Version":
|
|
40
|
+
version_ = version_tuple
|
|
41
|
+
if len(version_) > 3: # This means we have an RC
|
|
42
|
+
version_ = version_tuple[0:3] # Then let's ignore it
|
|
43
|
+
return Version(*version_) # TODO, add some validation
|
|
44
|
+
|
|
45
|
+
@staticmethod
|
|
46
|
+
def current() -> "Version":
|
|
47
|
+
current_version = version.VERSION
|
|
48
|
+
return Version.from_version_tuple(current_version)
|
|
49
|
+
|
|
50
|
+
def __repr__(self):
|
|
51
|
+
return ".".join(map(str, [self.major, self.minor, self.patch]))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
CURRENT_VERSION = Version.current()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class DeprecationError(Exception):
|
|
58
|
+
def raise_(self):
|
|
59
|
+
raise self
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclasses.dataclass
|
|
63
|
+
class deprecated:
|
|
64
|
+
"""Deprecation decorator -- use judiciously! For example:
|
|
65
|
+
@deprecate(
|
|
66
|
+
warn_starting=(1,10,0)
|
|
67
|
+
fail_starting=(2,0,0),
|
|
68
|
+
use_this=parameterize_values,
|
|
69
|
+
explanation='We have redefined the parameterization decorators to consist of `parametrize`, `parametrize_inputs`, and `parametrize_values`
|
|
70
|
+
migration_guide="https://github.com/apache/hamilton/..."
|
|
71
|
+
)
|
|
72
|
+
class parameterized(...):
|
|
73
|
+
...
|
|
74
|
+
Note this locks into a future contract (although it *can* be changed), so if you promise to deprecate something by X.0, then do it!
|
|
75
|
+
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
warn_starting: tuple[int, int, int] | Version
|
|
79
|
+
fail_starting: tuple[int, int, int] | Version
|
|
80
|
+
use_this: (
|
|
81
|
+
Callable | None
|
|
82
|
+
) # If this is None, it means this functionality is no longer supported.
|
|
83
|
+
explanation: str
|
|
84
|
+
migration_guide: (
|
|
85
|
+
str | None
|
|
86
|
+
) # If this is None, this means that the use_this is a drop in replacement
|
|
87
|
+
current_version: tuple[int, int, int] | Version = dataclasses.field(
|
|
88
|
+
default_factory=lambda: CURRENT_VERSION
|
|
89
|
+
)
|
|
90
|
+
warn_action: Callable[[str], None] = dataclasses.field(default=logger.warning)
|
|
91
|
+
fail_action: Callable[[str], None] = dataclasses.field(
|
|
92
|
+
default=lambda message: DeprecationError(message).raise_()
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
@staticmethod
|
|
96
|
+
def _raise_failure(message: str):
|
|
97
|
+
raise DeprecationError(message)
|
|
98
|
+
|
|
99
|
+
@staticmethod
|
|
100
|
+
def _ensure_version_type(version_spec: tuple[int, int, int] | Version) -> Version:
|
|
101
|
+
if isinstance(version_spec, tuple):
|
|
102
|
+
return Version(*version_spec)
|
|
103
|
+
return version_spec
|
|
104
|
+
|
|
105
|
+
def __post_init__(self):
|
|
106
|
+
if self.use_this is None:
|
|
107
|
+
if self.migration_guide is None:
|
|
108
|
+
raise ValueError(
|
|
109
|
+
"@deprecate must include a migration guide if there is no replacement."
|
|
110
|
+
)
|
|
111
|
+
self.warn_starting = deprecated._ensure_version_type(self.warn_starting)
|
|
112
|
+
self.fail_starting = deprecated._ensure_version_type(self.fail_starting)
|
|
113
|
+
self.current_version = deprecated._ensure_version_type(self.current_version)
|
|
114
|
+
self._validate_fail_starting()
|
|
115
|
+
|
|
116
|
+
def _validate_fail_starting(self):
|
|
117
|
+
if self.fail_starting.major > 0: # This means we're past alpha. We are, but nice to have...
|
|
118
|
+
if self.fail_starting.minor != 0 or self.fail_starting.patch != 0:
|
|
119
|
+
raise ValueError(
|
|
120
|
+
f"Can only deprecate starting on major version releases. {self.fail_starting} is not valid."
|
|
121
|
+
)
|
|
122
|
+
if self.warn_starting > self.fail_starting:
|
|
123
|
+
raise ValueError(
|
|
124
|
+
f"warn_starting must come before fail_starting. {self.fail_starting} < {self.warn_starting}"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
def _do_deprecation_action(self, fn: Callable):
|
|
128
|
+
if self._should_fail():
|
|
129
|
+
failure_message = " ".join(
|
|
130
|
+
[
|
|
131
|
+
f"{fn.__qualname__} has been deprecated, as of hamilton version: {self.fail_starting}.",
|
|
132
|
+
f"{self.explanation}",
|
|
133
|
+
]
|
|
134
|
+
+ (
|
|
135
|
+
[f"Instead, you should be using: {self.use_this.__qualname__}."]
|
|
136
|
+
if self.use_this is not None
|
|
137
|
+
else []
|
|
138
|
+
)
|
|
139
|
+
+ (
|
|
140
|
+
[f"For migration, see: {self.migration_guide}."]
|
|
141
|
+
if self.migration_guide is not None
|
|
142
|
+
else ["This is a drop-in replacement."]
|
|
143
|
+
)
|
|
144
|
+
)
|
|
145
|
+
self.fail_action(failure_message)
|
|
146
|
+
elif self._should_warn():
|
|
147
|
+
warn_message = " ".join(
|
|
148
|
+
[
|
|
149
|
+
f"{fn.__qualname__} will be deprecated by hamilton version: {self.fail_starting}.",
|
|
150
|
+
f"{self.explanation}",
|
|
151
|
+
]
|
|
152
|
+
+ (
|
|
153
|
+
[f"Instead, you should be using: {self.use_this.__qualname__}."]
|
|
154
|
+
if self.use_this is not None
|
|
155
|
+
else []
|
|
156
|
+
)
|
|
157
|
+
+ (
|
|
158
|
+
[f"For migration, see: {self.migration_guide}."]
|
|
159
|
+
if self.migration_guide is not None
|
|
160
|
+
else ["This is a drop-in replacement."]
|
|
161
|
+
)
|
|
162
|
+
)
|
|
163
|
+
self.warn_action(warn_message)
|
|
164
|
+
|
|
165
|
+
def _should_warn(self) -> bool:
|
|
166
|
+
return self.current_version > self.warn_starting
|
|
167
|
+
|
|
168
|
+
def _should_fail(self) -> bool:
|
|
169
|
+
return self.current_version > self.fail_starting
|
|
170
|
+
|
|
171
|
+
def __call__(self, fn: Callable):
|
|
172
|
+
"""Decorates the function with the deprecated decorator.
|
|
173
|
+
Note that this has different implementations for functions and
|
|
174
|
+
objects that masquerade as functions (E.G. by implementing __call__.
|
|
175
|
+
|
|
176
|
+
TODO -- use @singledispatchmethod -- this was written before that was available
|
|
177
|
+
https://docs.python.org/3/library/functools.html#functools.singledispatchmethod
|
|
178
|
+
|
|
179
|
+
:param fn: function (or class) to decorate
|
|
180
|
+
:return: The decorated function.
|
|
181
|
+
"""
|
|
182
|
+
# In this case we just do a standard decorator
|
|
183
|
+
if isinstance(fn, types.FunctionType):
|
|
184
|
+
|
|
185
|
+
@functools.wraps(fn)
|
|
186
|
+
def new_fn(*args, **kwargs):
|
|
187
|
+
self._do_deprecation_action(fn)
|
|
188
|
+
return fn(*args, **kwargs)
|
|
189
|
+
|
|
190
|
+
return new_fn
|
|
191
|
+
|
|
192
|
+
# Otherwise we assume that this is a class object
|
|
193
|
+
# We have to store the former __call__
|
|
194
|
+
fn.__old_call__ = fn.__call__
|
|
195
|
+
|
|
196
|
+
def new__call__(self, *args, deprecator=self, fn=fn, **kwargs):
|
|
197
|
+
deprecator._do_deprecation_action(fn)
|
|
198
|
+
return fn.__old_call__(self, *args, **kwargs)
|
|
199
|
+
|
|
200
|
+
# This works as we're assigning it to the entire class...
|
|
201
|
+
# This also means we can't decorate it with 2 deprecation functions, but, hey,
|
|
202
|
+
# its on you if you try to deprecate something twice
|
|
203
|
+
fn.__call__ = new__call__
|
|
204
|
+
return fn
|