ob-metaflow 2.11.13.1__py2.py3-none-any.whl → 2.19.7.1rc0__py2.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.
- metaflow/R.py +10 -7
- metaflow/__init__.py +40 -25
- metaflow/_vendor/imghdr/__init__.py +186 -0
- metaflow/_vendor/importlib_metadata/__init__.py +1063 -0
- metaflow/_vendor/importlib_metadata/_adapters.py +68 -0
- metaflow/_vendor/importlib_metadata/_collections.py +30 -0
- metaflow/_vendor/importlib_metadata/_compat.py +71 -0
- metaflow/_vendor/importlib_metadata/_functools.py +104 -0
- metaflow/_vendor/importlib_metadata/_itertools.py +73 -0
- metaflow/_vendor/importlib_metadata/_meta.py +48 -0
- metaflow/_vendor/importlib_metadata/_text.py +99 -0
- metaflow/_vendor/importlib_metadata/py.typed +0 -0
- metaflow/_vendor/typeguard/__init__.py +48 -0
- metaflow/_vendor/typeguard/_checkers.py +1070 -0
- metaflow/_vendor/typeguard/_config.py +108 -0
- metaflow/_vendor/typeguard/_decorators.py +233 -0
- metaflow/_vendor/typeguard/_exceptions.py +42 -0
- metaflow/_vendor/typeguard/_functions.py +308 -0
- metaflow/_vendor/typeguard/_importhook.py +213 -0
- metaflow/_vendor/typeguard/_memo.py +48 -0
- metaflow/_vendor/typeguard/_pytest_plugin.py +127 -0
- metaflow/_vendor/typeguard/_suppression.py +86 -0
- metaflow/_vendor/typeguard/_transformer.py +1229 -0
- metaflow/_vendor/typeguard/_union_transformer.py +55 -0
- metaflow/_vendor/typeguard/_utils.py +173 -0
- metaflow/_vendor/typeguard/py.typed +0 -0
- metaflow/_vendor/typing_extensions.py +3641 -0
- metaflow/_vendor/v3_7/importlib_metadata/__init__.py +1063 -0
- metaflow/_vendor/v3_7/importlib_metadata/_adapters.py +68 -0
- metaflow/_vendor/v3_7/importlib_metadata/_collections.py +30 -0
- metaflow/_vendor/v3_7/importlib_metadata/_compat.py +71 -0
- metaflow/_vendor/v3_7/importlib_metadata/_functools.py +104 -0
- metaflow/_vendor/v3_7/importlib_metadata/_itertools.py +73 -0
- metaflow/_vendor/v3_7/importlib_metadata/_meta.py +48 -0
- metaflow/_vendor/v3_7/importlib_metadata/_text.py +99 -0
- metaflow/_vendor/v3_7/importlib_metadata/py.typed +0 -0
- metaflow/_vendor/v3_7/typeguard/__init__.py +48 -0
- metaflow/_vendor/v3_7/typeguard/_checkers.py +906 -0
- metaflow/_vendor/v3_7/typeguard/_config.py +108 -0
- metaflow/_vendor/v3_7/typeguard/_decorators.py +237 -0
- metaflow/_vendor/v3_7/typeguard/_exceptions.py +42 -0
- metaflow/_vendor/v3_7/typeguard/_functions.py +310 -0
- metaflow/_vendor/v3_7/typeguard/_importhook.py +213 -0
- metaflow/_vendor/v3_7/typeguard/_memo.py +48 -0
- metaflow/_vendor/v3_7/typeguard/_pytest_plugin.py +100 -0
- metaflow/_vendor/v3_7/typeguard/_suppression.py +88 -0
- metaflow/_vendor/v3_7/typeguard/_transformer.py +1207 -0
- metaflow/_vendor/v3_7/typeguard/_union_transformer.py +54 -0
- metaflow/_vendor/v3_7/typeguard/_utils.py +169 -0
- metaflow/_vendor/v3_7/typeguard/py.typed +0 -0
- metaflow/_vendor/v3_7/typing_extensions.py +3072 -0
- metaflow/_vendor/yaml/__init__.py +427 -0
- metaflow/_vendor/yaml/composer.py +139 -0
- metaflow/_vendor/yaml/constructor.py +748 -0
- metaflow/_vendor/yaml/cyaml.py +101 -0
- metaflow/_vendor/yaml/dumper.py +62 -0
- metaflow/_vendor/yaml/emitter.py +1137 -0
- metaflow/_vendor/yaml/error.py +75 -0
- metaflow/_vendor/yaml/events.py +86 -0
- metaflow/_vendor/yaml/loader.py +63 -0
- metaflow/_vendor/yaml/nodes.py +49 -0
- metaflow/_vendor/yaml/parser.py +589 -0
- metaflow/_vendor/yaml/reader.py +185 -0
- metaflow/_vendor/yaml/representer.py +389 -0
- metaflow/_vendor/yaml/resolver.py +227 -0
- metaflow/_vendor/yaml/scanner.py +1435 -0
- metaflow/_vendor/yaml/serializer.py +111 -0
- metaflow/_vendor/yaml/tokens.py +104 -0
- metaflow/cards.py +5 -0
- metaflow/cli.py +331 -785
- metaflow/cli_args.py +17 -0
- metaflow/cli_components/__init__.py +0 -0
- metaflow/cli_components/dump_cmd.py +96 -0
- metaflow/cli_components/init_cmd.py +52 -0
- metaflow/cli_components/run_cmds.py +546 -0
- metaflow/cli_components/step_cmd.py +334 -0
- metaflow/cli_components/utils.py +140 -0
- metaflow/client/__init__.py +1 -0
- metaflow/client/core.py +467 -73
- metaflow/client/filecache.py +75 -35
- metaflow/clone_util.py +7 -1
- metaflow/cmd/code/__init__.py +231 -0
- metaflow/cmd/develop/stub_generator.py +756 -288
- metaflow/cmd/develop/stubs.py +12 -28
- metaflow/cmd/main_cli.py +6 -4
- metaflow/cmd/make_wrapper.py +78 -0
- metaflow/datastore/__init__.py +1 -0
- metaflow/datastore/content_addressed_store.py +41 -10
- metaflow/datastore/datastore_set.py +11 -2
- metaflow/datastore/flow_datastore.py +156 -10
- metaflow/datastore/spin_datastore.py +91 -0
- metaflow/datastore/task_datastore.py +154 -39
- metaflow/debug.py +5 -0
- metaflow/decorators.py +404 -78
- metaflow/exception.py +8 -2
- metaflow/extension_support/__init__.py +527 -376
- metaflow/extension_support/_empty_file.py +2 -2
- metaflow/extension_support/plugins.py +49 -31
- metaflow/flowspec.py +482 -33
- metaflow/graph.py +210 -42
- metaflow/includefile.py +84 -40
- metaflow/lint.py +141 -22
- metaflow/meta_files.py +13 -0
- metaflow/{metadata → metadata_provider}/heartbeat.py +24 -8
- metaflow/{metadata → metadata_provider}/metadata.py +86 -1
- metaflow/metaflow_config.py +175 -28
- metaflow/metaflow_config_funcs.py +51 -3
- metaflow/metaflow_current.py +4 -10
- metaflow/metaflow_environment.py +139 -53
- metaflow/metaflow_git.py +115 -0
- metaflow/metaflow_profile.py +18 -0
- metaflow/metaflow_version.py +150 -66
- metaflow/mflog/__init__.py +4 -3
- metaflow/mflog/save_logs.py +2 -2
- metaflow/multicore_utils.py +31 -14
- metaflow/package/__init__.py +673 -0
- metaflow/packaging_sys/__init__.py +880 -0
- metaflow/packaging_sys/backend.py +128 -0
- metaflow/packaging_sys/distribution_support.py +153 -0
- metaflow/packaging_sys/tar_backend.py +99 -0
- metaflow/packaging_sys/utils.py +54 -0
- metaflow/packaging_sys/v1.py +527 -0
- metaflow/parameters.py +149 -28
- metaflow/plugins/__init__.py +74 -5
- metaflow/plugins/airflow/airflow.py +40 -25
- metaflow/plugins/airflow/airflow_cli.py +22 -5
- metaflow/plugins/airflow/airflow_decorator.py +1 -1
- metaflow/plugins/airflow/airflow_utils.py +5 -3
- metaflow/plugins/airflow/sensors/base_sensor.py +4 -4
- metaflow/plugins/airflow/sensors/external_task_sensor.py +2 -2
- metaflow/plugins/airflow/sensors/s3_sensor.py +2 -2
- metaflow/plugins/argo/argo_client.py +78 -33
- metaflow/plugins/argo/argo_events.py +6 -6
- metaflow/plugins/argo/argo_workflows.py +2410 -527
- metaflow/plugins/argo/argo_workflows_cli.py +571 -121
- metaflow/plugins/argo/argo_workflows_decorator.py +43 -12
- metaflow/plugins/argo/argo_workflows_deployer.py +106 -0
- metaflow/plugins/argo/argo_workflows_deployer_objects.py +453 -0
- metaflow/plugins/argo/capture_error.py +73 -0
- metaflow/plugins/argo/conditional_input_paths.py +35 -0
- metaflow/plugins/argo/exit_hooks.py +209 -0
- metaflow/plugins/argo/jobset_input_paths.py +15 -0
- metaflow/plugins/argo/param_val.py +19 -0
- metaflow/plugins/aws/aws_client.py +10 -3
- metaflow/plugins/aws/aws_utils.py +55 -2
- metaflow/plugins/aws/batch/batch.py +72 -5
- metaflow/plugins/aws/batch/batch_cli.py +33 -10
- metaflow/plugins/aws/batch/batch_client.py +4 -3
- metaflow/plugins/aws/batch/batch_decorator.py +102 -35
- metaflow/plugins/aws/secrets_manager/aws_secrets_manager_secrets_provider.py +13 -10
- metaflow/plugins/aws/step_functions/dynamo_db_client.py +0 -3
- metaflow/plugins/aws/step_functions/production_token.py +1 -1
- metaflow/plugins/aws/step_functions/step_functions.py +65 -8
- metaflow/plugins/aws/step_functions/step_functions_cli.py +101 -7
- metaflow/plugins/aws/step_functions/step_functions_decorator.py +1 -2
- metaflow/plugins/aws/step_functions/step_functions_deployer.py +97 -0
- metaflow/plugins/aws/step_functions/step_functions_deployer_objects.py +264 -0
- metaflow/plugins/azure/azure_exceptions.py +1 -1
- metaflow/plugins/azure/azure_secret_manager_secrets_provider.py +240 -0
- metaflow/plugins/azure/azure_tail.py +1 -1
- metaflow/plugins/azure/includefile_support.py +2 -0
- metaflow/plugins/cards/card_cli.py +66 -30
- metaflow/plugins/cards/card_creator.py +25 -1
- metaflow/plugins/cards/card_datastore.py +21 -49
- metaflow/plugins/cards/card_decorator.py +132 -8
- metaflow/plugins/cards/card_modules/basic.py +112 -17
- metaflow/plugins/cards/card_modules/bundle.css +1 -1
- metaflow/plugins/cards/card_modules/card.py +16 -1
- metaflow/plugins/cards/card_modules/chevron/renderer.py +1 -1
- metaflow/plugins/cards/card_modules/components.py +665 -28
- metaflow/plugins/cards/card_modules/convert_to_native_type.py +36 -7
- metaflow/plugins/cards/card_modules/json_viewer.py +232 -0
- metaflow/plugins/cards/card_modules/main.css +1 -0
- metaflow/plugins/cards/card_modules/main.js +68 -49
- metaflow/plugins/cards/card_modules/renderer_tools.py +1 -0
- metaflow/plugins/cards/card_modules/test_cards.py +26 -12
- metaflow/plugins/cards/card_server.py +39 -14
- metaflow/plugins/cards/component_serializer.py +2 -9
- metaflow/plugins/cards/metadata.py +22 -0
- metaflow/plugins/catch_decorator.py +9 -0
- metaflow/plugins/datastores/azure_storage.py +10 -1
- metaflow/plugins/datastores/gs_storage.py +6 -2
- metaflow/plugins/datastores/local_storage.py +12 -6
- metaflow/plugins/datastores/spin_storage.py +12 -0
- metaflow/plugins/datatools/local.py +2 -0
- metaflow/plugins/datatools/s3/s3.py +126 -75
- metaflow/plugins/datatools/s3/s3op.py +254 -121
- metaflow/plugins/env_escape/__init__.py +3 -3
- metaflow/plugins/env_escape/client_modules.py +102 -72
- metaflow/plugins/env_escape/server.py +7 -0
- metaflow/plugins/env_escape/stub.py +24 -5
- metaflow/plugins/events_decorator.py +343 -185
- metaflow/plugins/exit_hook/__init__.py +0 -0
- metaflow/plugins/exit_hook/exit_hook_decorator.py +46 -0
- metaflow/plugins/exit_hook/exit_hook_script.py +52 -0
- metaflow/plugins/gcp/__init__.py +1 -1
- metaflow/plugins/gcp/gcp_secret_manager_secrets_provider.py +11 -6
- metaflow/plugins/gcp/gs_tail.py +10 -6
- metaflow/plugins/gcp/includefile_support.py +3 -0
- metaflow/plugins/kubernetes/kube_utils.py +108 -0
- metaflow/plugins/kubernetes/kubernetes.py +411 -130
- metaflow/plugins/kubernetes/kubernetes_cli.py +168 -36
- metaflow/plugins/kubernetes/kubernetes_client.py +104 -2
- metaflow/plugins/kubernetes/kubernetes_decorator.py +246 -88
- metaflow/plugins/kubernetes/kubernetes_job.py +253 -581
- metaflow/plugins/kubernetes/kubernetes_jobsets.py +1071 -0
- metaflow/plugins/kubernetes/spot_metadata_cli.py +69 -0
- metaflow/plugins/kubernetes/spot_monitor_sidecar.py +109 -0
- metaflow/plugins/logs_cli.py +359 -0
- metaflow/plugins/{metadata → metadata_providers}/local.py +144 -84
- metaflow/plugins/{metadata → metadata_providers}/service.py +103 -26
- metaflow/plugins/metadata_providers/spin.py +16 -0
- metaflow/plugins/package_cli.py +36 -24
- metaflow/plugins/parallel_decorator.py +128 -11
- metaflow/plugins/parsers.py +16 -0
- metaflow/plugins/project_decorator.py +51 -5
- metaflow/plugins/pypi/bootstrap.py +357 -105
- metaflow/plugins/pypi/conda_decorator.py +82 -81
- metaflow/plugins/pypi/conda_environment.py +187 -52
- metaflow/plugins/pypi/micromamba.py +157 -47
- metaflow/plugins/pypi/parsers.py +268 -0
- metaflow/plugins/pypi/pip.py +88 -13
- metaflow/plugins/pypi/pypi_decorator.py +37 -1
- metaflow/plugins/pypi/utils.py +48 -2
- metaflow/plugins/resources_decorator.py +2 -2
- metaflow/plugins/secrets/__init__.py +3 -0
- metaflow/plugins/secrets/secrets_decorator.py +26 -181
- metaflow/plugins/secrets/secrets_func.py +49 -0
- metaflow/plugins/secrets/secrets_spec.py +101 -0
- metaflow/plugins/secrets/utils.py +74 -0
- metaflow/plugins/tag_cli.py +4 -7
- metaflow/plugins/test_unbounded_foreach_decorator.py +41 -6
- metaflow/plugins/timeout_decorator.py +3 -3
- metaflow/plugins/uv/__init__.py +0 -0
- metaflow/plugins/uv/bootstrap.py +128 -0
- metaflow/plugins/uv/uv_environment.py +72 -0
- metaflow/procpoll.py +1 -1
- metaflow/pylint_wrapper.py +5 -1
- metaflow/runner/__init__.py +0 -0
- metaflow/runner/click_api.py +717 -0
- metaflow/runner/deployer.py +470 -0
- metaflow/runner/deployer_impl.py +201 -0
- metaflow/runner/metaflow_runner.py +714 -0
- metaflow/runner/nbdeploy.py +132 -0
- metaflow/runner/nbrun.py +225 -0
- metaflow/runner/subprocess_manager.py +650 -0
- metaflow/runner/utils.py +335 -0
- metaflow/runtime.py +1078 -260
- metaflow/sidecar/sidecar_worker.py +1 -1
- metaflow/system/__init__.py +5 -0
- metaflow/system/system_logger.py +85 -0
- metaflow/system/system_monitor.py +108 -0
- metaflow/system/system_utils.py +19 -0
- metaflow/task.py +521 -225
- metaflow/tracing/__init__.py +7 -7
- metaflow/tracing/span_exporter.py +31 -38
- metaflow/tracing/tracing_modules.py +38 -43
- metaflow/tuple_util.py +27 -0
- metaflow/user_configs/__init__.py +0 -0
- metaflow/user_configs/config_options.py +563 -0
- metaflow/user_configs/config_parameters.py +598 -0
- metaflow/user_decorators/__init__.py +0 -0
- metaflow/user_decorators/common.py +144 -0
- metaflow/user_decorators/mutable_flow.py +512 -0
- metaflow/user_decorators/mutable_step.py +424 -0
- metaflow/user_decorators/user_flow_decorator.py +264 -0
- metaflow/user_decorators/user_step_decorator.py +749 -0
- metaflow/util.py +243 -27
- metaflow/vendor.py +23 -7
- metaflow/version.py +1 -1
- ob_metaflow-2.19.7.1rc0.data/data/share/metaflow/devtools/Makefile +355 -0
- ob_metaflow-2.19.7.1rc0.data/data/share/metaflow/devtools/Tiltfile +726 -0
- ob_metaflow-2.19.7.1rc0.data/data/share/metaflow/devtools/pick_services.sh +105 -0
- ob_metaflow-2.19.7.1rc0.dist-info/METADATA +87 -0
- ob_metaflow-2.19.7.1rc0.dist-info/RECORD +445 -0
- {ob_metaflow-2.11.13.1.dist-info → ob_metaflow-2.19.7.1rc0.dist-info}/WHEEL +1 -1
- {ob_metaflow-2.11.13.1.dist-info → ob_metaflow-2.19.7.1rc0.dist-info}/entry_points.txt +1 -0
- metaflow/_vendor/v3_5/__init__.py +0 -1
- metaflow/_vendor/v3_5/importlib_metadata/__init__.py +0 -644
- metaflow/_vendor/v3_5/importlib_metadata/_compat.py +0 -152
- metaflow/package.py +0 -188
- ob_metaflow-2.11.13.1.dist-info/METADATA +0 -85
- ob_metaflow-2.11.13.1.dist-info/RECORD +0 -308
- /metaflow/_vendor/{v3_5/zipp.py → zipp.py} +0 -0
- /metaflow/{metadata → metadata_provider}/__init__.py +0 -0
- /metaflow/{metadata → metadata_provider}/util.py +0 -0
- /metaflow/plugins/{metadata → metadata_providers}/__init__.py +0 -0
- {ob_metaflow-2.11.13.1.dist-info → ob_metaflow-2.19.7.1rc0.dist-info/licenses}/LICENSE +0 -0
- {ob_metaflow-2.11.13.1.dist-info → ob_metaflow-2.19.7.1rc0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Transforms lazily evaluated PEP 604 unions into typing.Unions, for compatibility with
|
|
3
|
+
Python versions older than 3.10.
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from ast import (
|
|
8
|
+
BinOp,
|
|
9
|
+
BitOr,
|
|
10
|
+
Index,
|
|
11
|
+
Load,
|
|
12
|
+
Name,
|
|
13
|
+
NodeTransformer,
|
|
14
|
+
Subscript,
|
|
15
|
+
fix_missing_locations,
|
|
16
|
+
parse,
|
|
17
|
+
)
|
|
18
|
+
from ast import Tuple as ASTTuple
|
|
19
|
+
from types import CodeType
|
|
20
|
+
from typing import Any, Dict, FrozenSet, List, Set, Tuple, Union
|
|
21
|
+
|
|
22
|
+
type_substitutions = {
|
|
23
|
+
"dict": Dict,
|
|
24
|
+
"list": List,
|
|
25
|
+
"tuple": Tuple,
|
|
26
|
+
"set": Set,
|
|
27
|
+
"frozenset": FrozenSet,
|
|
28
|
+
"Union": Union,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class UnionTransformer(NodeTransformer):
|
|
33
|
+
def __init__(self, union_name: Name | None = None):
|
|
34
|
+
self.union_name = union_name or Name(id="Union", ctx=Load())
|
|
35
|
+
|
|
36
|
+
def visit_BinOp(self, node: BinOp) -> Any:
|
|
37
|
+
self.generic_visit(node)
|
|
38
|
+
if isinstance(node.op, BitOr):
|
|
39
|
+
return Subscript(
|
|
40
|
+
value=self.union_name,
|
|
41
|
+
slice=Index(
|
|
42
|
+
ASTTuple(elts=[node.left, node.right], ctx=Load()), ctx=Load()
|
|
43
|
+
),
|
|
44
|
+
ctx=Load(),
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
return node
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def compile_type_hint(hint: str) -> CodeType:
|
|
51
|
+
parsed = parse(hint, "<string>", "eval")
|
|
52
|
+
UnionTransformer().visit(parsed)
|
|
53
|
+
fix_missing_locations(parsed)
|
|
54
|
+
return compile(parsed, "<string>", "eval", flags=0)
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import inspect
|
|
4
|
+
import sys
|
|
5
|
+
from importlib import import_module
|
|
6
|
+
from inspect import currentframe
|
|
7
|
+
from types import CodeType, FrameType, FunctionType
|
|
8
|
+
from typing import TYPE_CHECKING, Any, Callable, ForwardRef, Union, cast
|
|
9
|
+
from weakref import WeakValueDictionary
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from ._memo import TypeCheckMemo
|
|
13
|
+
|
|
14
|
+
if sys.version_info >= (3, 10):
|
|
15
|
+
from typing import get_args, get_origin
|
|
16
|
+
|
|
17
|
+
def evaluate_forwardref(forwardref: ForwardRef, memo: TypeCheckMemo) -> Any:
|
|
18
|
+
return forwardref._evaluate(memo.globals, memo.locals, frozenset())
|
|
19
|
+
|
|
20
|
+
else:
|
|
21
|
+
from metaflow._vendor.v3_7.typing_extensions import get_args, get_origin
|
|
22
|
+
|
|
23
|
+
evaluate_extra_args: tuple[frozenset[Any], ...] = (
|
|
24
|
+
(frozenset(),) if sys.version_info >= (3, 9) else ()
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
def evaluate_forwardref(forwardref: ForwardRef, memo: TypeCheckMemo) -> Any:
|
|
28
|
+
from ._union_transformer import compile_type_hint, type_substitutions
|
|
29
|
+
|
|
30
|
+
if not forwardref.__forward_evaluated__:
|
|
31
|
+
forwardref.__forward_code__ = compile_type_hint(forwardref.__forward_arg__)
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
return forwardref._evaluate(memo.globals, memo.locals, *evaluate_extra_args)
|
|
35
|
+
except NameError:
|
|
36
|
+
if sys.version_info < (3, 10):
|
|
37
|
+
# Try again, with the type substitutions (list -> List etc.) in place
|
|
38
|
+
new_globals = memo.globals.copy()
|
|
39
|
+
new_globals.setdefault("Union", Union)
|
|
40
|
+
if sys.version_info < (3, 9):
|
|
41
|
+
new_globals.update(type_substitutions)
|
|
42
|
+
|
|
43
|
+
return forwardref._evaluate(
|
|
44
|
+
new_globals, memo.locals or new_globals, *evaluate_extra_args
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
raise
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if sys.version_info >= (3, 8):
|
|
51
|
+
from typing import final
|
|
52
|
+
else:
|
|
53
|
+
from metaflow._vendor.v3_7.typing_extensions import final
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
_functions_map: WeakValueDictionary[CodeType, FunctionType] = WeakValueDictionary()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def get_type_name(type_: Any) -> str:
|
|
60
|
+
name: str
|
|
61
|
+
for attrname in "__name__", "_name", "__forward_arg__":
|
|
62
|
+
candidate = getattr(type_, attrname, None)
|
|
63
|
+
if isinstance(candidate, str):
|
|
64
|
+
name = candidate
|
|
65
|
+
break
|
|
66
|
+
else:
|
|
67
|
+
origin = get_origin(type_)
|
|
68
|
+
candidate = getattr(origin, "_name", None)
|
|
69
|
+
if candidate is None:
|
|
70
|
+
candidate = type_.__class__.__name__.strip("_")
|
|
71
|
+
|
|
72
|
+
if isinstance(candidate, str):
|
|
73
|
+
name = candidate
|
|
74
|
+
else:
|
|
75
|
+
return "(unknown)"
|
|
76
|
+
|
|
77
|
+
args = get_args(type_)
|
|
78
|
+
if args:
|
|
79
|
+
if name == "Literal":
|
|
80
|
+
formatted_args = ", ".join(repr(arg) for arg in args)
|
|
81
|
+
else:
|
|
82
|
+
formatted_args = ", ".join(get_type_name(arg) for arg in args)
|
|
83
|
+
|
|
84
|
+
name += f"[{formatted_args}]"
|
|
85
|
+
|
|
86
|
+
module = getattr(type_, "__module__", None)
|
|
87
|
+
if module and module not in (None, "typing", "typing_extensions", "builtins"):
|
|
88
|
+
name = module + "." + name
|
|
89
|
+
|
|
90
|
+
return name
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def qualified_name(obj: Any, *, add_class_prefix: bool = False) -> str:
|
|
94
|
+
"""
|
|
95
|
+
Return the qualified name (e.g. package.module.Type) for the given object.
|
|
96
|
+
|
|
97
|
+
Builtins and types from the :mod:`typing` package get special treatment by having
|
|
98
|
+
the module name stripped from the generated name.
|
|
99
|
+
|
|
100
|
+
"""
|
|
101
|
+
if obj is None:
|
|
102
|
+
return "None"
|
|
103
|
+
elif inspect.isclass(obj):
|
|
104
|
+
prefix = "class " if add_class_prefix else ""
|
|
105
|
+
type_ = obj
|
|
106
|
+
else:
|
|
107
|
+
prefix = ""
|
|
108
|
+
type_ = type(obj)
|
|
109
|
+
|
|
110
|
+
module = type_.__module__
|
|
111
|
+
qualname = type_.__qualname__
|
|
112
|
+
name = qualname if module in ("typing", "builtins") else f"{module}.{qualname}"
|
|
113
|
+
return prefix + name
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def function_name(func: Callable[..., Any]) -> str:
|
|
117
|
+
"""
|
|
118
|
+
Return the qualified name of the given function.
|
|
119
|
+
|
|
120
|
+
Builtins and types from the :mod:`typing` package get special treatment by having
|
|
121
|
+
the module name stripped from the generated name.
|
|
122
|
+
|
|
123
|
+
"""
|
|
124
|
+
# For partial functions and objects with __call__ defined, __qualname__ does not
|
|
125
|
+
# exist
|
|
126
|
+
module = getattr(func, "__module__", "")
|
|
127
|
+
qualname = (module + ".") if module not in ("builtins", "") else ""
|
|
128
|
+
return qualname + getattr(func, "__qualname__", repr(func))
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def resolve_reference(reference: str) -> Any:
|
|
132
|
+
modulename, varname = reference.partition(":")[::2]
|
|
133
|
+
if not modulename or not varname:
|
|
134
|
+
raise ValueError(f"{reference!r} is not a module:varname reference")
|
|
135
|
+
|
|
136
|
+
obj = import_module(modulename)
|
|
137
|
+
for attr in varname.split("."):
|
|
138
|
+
obj = getattr(obj, attr)
|
|
139
|
+
|
|
140
|
+
return obj
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def is_method_of(obj: object, cls: type) -> bool:
|
|
144
|
+
return (
|
|
145
|
+
inspect.isfunction(obj)
|
|
146
|
+
and obj.__module__ == cls.__module__
|
|
147
|
+
and obj.__qualname__.startswith(cls.__qualname__ + ".")
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def get_stacklevel() -> int:
|
|
152
|
+
level = 1
|
|
153
|
+
frame = cast(FrameType, currentframe()).f_back
|
|
154
|
+
while frame and frame.f_globals.get("__name__", "").startswith("typeguard."):
|
|
155
|
+
level += 1
|
|
156
|
+
frame = frame.f_back
|
|
157
|
+
|
|
158
|
+
return level
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@final
|
|
162
|
+
class Unset:
|
|
163
|
+
__slots__ = ()
|
|
164
|
+
|
|
165
|
+
def __repr__(self) -> str:
|
|
166
|
+
return "<unset>"
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
unset = Unset()
|
|
File without changes
|