torchx-nightly 2025.4.21__py3-none-any.whl → 2025.4.23__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.
Potentially problematic release.
This version of torchx-nightly might be problematic. Click here for more details.
- torchx/util/modules.py +34 -4
- {torchx_nightly-2025.4.21.dist-info → torchx_nightly-2025.4.23.dist-info}/METADATA +1 -1
- {torchx_nightly-2025.4.21.dist-info → torchx_nightly-2025.4.23.dist-info}/RECORD +7 -7
- {torchx_nightly-2025.4.21.dist-info → torchx_nightly-2025.4.23.dist-info}/LICENSE +0 -0
- {torchx_nightly-2025.4.21.dist-info → torchx_nightly-2025.4.23.dist-info}/WHEEL +0 -0
- {torchx_nightly-2025.4.21.dist-info → torchx_nightly-2025.4.23.dist-info}/entry_points.txt +0 -0
- {torchx_nightly-2025.4.21.dist-info → torchx_nightly-2025.4.23.dist-info}/top_level.txt +0 -0
torchx/util/modules.py
CHANGED
|
@@ -8,16 +8,13 @@
|
|
|
8
8
|
|
|
9
9
|
import importlib
|
|
10
10
|
from types import ModuleType
|
|
11
|
-
from typing import Callable, Optional, Union
|
|
11
|
+
from typing import Callable, Optional, TypeVar, Union
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def load_module(path: str) -> Union[ModuleType, Optional[Callable[..., object]]]:
|
|
15
15
|
"""
|
|
16
16
|
Loads and returns the module/module attr represented by the ``path``: ``full.module.path:optional_attr``
|
|
17
17
|
|
|
18
|
-
::
|
|
19
|
-
|
|
20
|
-
|
|
21
18
|
1. ``load_module("this.is.a_module:fn")`` -> equivalent to ``this.is.a_module.fn``
|
|
22
19
|
1. ``load_module("this.is.a_module")`` -> equivalent to ``this.is.a_module``
|
|
23
20
|
"""
|
|
@@ -33,3 +30,36 @@ def load_module(path: str) -> Union[ModuleType, Optional[Callable[..., object]]]
|
|
|
33
30
|
return getattr(module, method) if method else module
|
|
34
31
|
except Exception:
|
|
35
32
|
return None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
T = TypeVar("T")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def import_attr(name: str, attr: str, default: T) -> T:
|
|
39
|
+
"""
|
|
40
|
+
Imports ``name.attr`` and returns it if the module is found.
|
|
41
|
+
Otherwise, returns the specified ``default``.
|
|
42
|
+
Useful when getting an attribute from an optional dependency.
|
|
43
|
+
|
|
44
|
+
Note that the ``default`` parameter is intentionally not an optional
|
|
45
|
+
since this function is intended to be used with modules that may not be
|
|
46
|
+
installed as a dependency. Therefore the caller must ALWAYS provide a
|
|
47
|
+
sensible default.
|
|
48
|
+
|
|
49
|
+
Usage:
|
|
50
|
+
|
|
51
|
+
.. code-block:: python
|
|
52
|
+
|
|
53
|
+
aws_resources = import_attr("torchx.specs.named_resources_aws", "NAMED_RESOURCES", default={})
|
|
54
|
+
all_resources.update(aws_resources)
|
|
55
|
+
|
|
56
|
+
Raises:
|
|
57
|
+
AttributeError: If the module exists (e.g. can be imported)
|
|
58
|
+
but does not have an attribute with name ``attr``.
|
|
59
|
+
"""
|
|
60
|
+
try:
|
|
61
|
+
mod = importlib.import_module(name)
|
|
62
|
+
except ModuleNotFoundError:
|
|
63
|
+
return default
|
|
64
|
+
else:
|
|
65
|
+
return getattr(mod, attr)
|
|
@@ -106,7 +106,7 @@ torchx/util/datetime.py,sha256=hV6Sg0u5KTBe68yrmy_RGCC5su0i4Tb_mAYphWamiXI,405
|
|
|
106
106
|
torchx/util/entrypoints.py,sha256=J5WSFtCFVZ7ZjlAvzYcdWgVSUKC3aVo1eVmJAbWhpx8,2894
|
|
107
107
|
torchx/util/io.py,sha256=HNpWLcFUX0WTAP3CsdamHz--FR5A4kSdLCPfNqa2UkA,1807
|
|
108
108
|
torchx/util/log_tee_helpers.py,sha256=wPyozmh9BOt_2d3Gxa0iNogwnjzwFitIIMBJOJ1arIw,6330
|
|
109
|
-
torchx/util/modules.py,sha256=
|
|
109
|
+
torchx/util/modules.py,sha256=o4y_d07gTpJ4nIVBcoUVJ0JtXIHEsEC5kbgBM6NGpgA,2135
|
|
110
110
|
torchx/util/session.py,sha256=r6M_nyzXgcbk1GgYGZ324F_ehRGCqjjdVk4YgKxMj8M,1214
|
|
111
111
|
torchx/util/shlex.py,sha256=eXEKu8KC3zIcd8tEy9_s8Ds5oma8BORr-0VGWNpG2dk,463
|
|
112
112
|
torchx/util/strings.py,sha256=GkLWCmYS89Uv6bWc5hH0XwvHy7oQmprv2U7axC4A2e8,678
|
|
@@ -115,9 +115,9 @@ torchx/workspace/__init__.py,sha256=FqN8AN4VhR1C_SBY10MggQvNZmyanbbuPuE-JCjkyUY,
|
|
|
115
115
|
torchx/workspace/api.py,sha256=PtDkGTC5lX03pRoYpuMz2KCmM1ZOycRP1UknqvNb97Y,6341
|
|
116
116
|
torchx/workspace/dir_workspace.py,sha256=npNW_IjUZm_yS5r-8hrRkH46ndDd9a_eApT64m1S1T4,2268
|
|
117
117
|
torchx/workspace/docker_workspace.py,sha256=PFu2KQNVC-0p2aKJ-W_BKA9ZOmXdCY2ABEkCExp3udQ,10269
|
|
118
|
-
torchx_nightly-2025.4.
|
|
119
|
-
torchx_nightly-2025.4.
|
|
120
|
-
torchx_nightly-2025.4.
|
|
121
|
-
torchx_nightly-2025.4.
|
|
122
|
-
torchx_nightly-2025.4.
|
|
123
|
-
torchx_nightly-2025.4.
|
|
118
|
+
torchx_nightly-2025.4.23.dist-info/LICENSE,sha256=WVHfXhFC0Ia8LTKt_nJVYobdqTJVg_4J3Crrfm2A8KQ,1721
|
|
119
|
+
torchx_nightly-2025.4.23.dist-info/METADATA,sha256=AE_Do6UCAowNTsooP6aVdf2QCAQ4ARzo9dWIQ2K_1Bw,6167
|
|
120
|
+
torchx_nightly-2025.4.23.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
121
|
+
torchx_nightly-2025.4.23.dist-info/entry_points.txt,sha256=T328AMXeKI3JZnnxfkEew2ZcMN1oQDtkXjMz7lkV-P4,169
|
|
122
|
+
torchx_nightly-2025.4.23.dist-info/top_level.txt,sha256=pxew3bc2gsiViS0zADs0jb6kC5v8o_Yy_85fhHj_J1A,7
|
|
123
|
+
torchx_nightly-2025.4.23.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|