Skip to content

Commit 1ccf27f

Browse files
kiukchungfacebook-github-bot
authored andcommitted
Create //torchx/specs:lib_core (#1048)
Summary: IMPORTANT: If you believe you are broken by this diff due to autodeps/codemod having removed a dep to `//torchx/specs:api` in favor of `//torchx/specs:lib_core` then try adding a manual (`# manual`) dep to `//torchx/specs/fb:api_extended` to fix forward. **Example:** ``` python_library|binary( name = "my-lib-or-bin", srcs = [...], deps = [ "//torchx/specs:lib_core", # <-- added by autodeps codemod "//torchx/specs/fb:api_extended", # manual <-- manually add api_extended ... ] ) ``` Milestone 1.1 of torchx-lite (see [doc](https://fburl.com/gdoc/4wxcoaoa) for details) Creates `//torchx/specs:lib_core` with only the source files of `torchx.specs` module and a minimal set of dependencies for a proper closure of this module. For BC, we keep `//torchx/specs:lib` and `//torchx/specs:api` as is by adding the existing bundled deps as `manual` so that autodeps doesn't remove them on future codemods. Switches over to `//torchx/specs:lib_core` for TorchX internal targets (e.g. within `//torchx/...`). Reviewed By: aay-gup Differential Revision: D73195094
1 parent 497c664 commit 1ccf27f

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

torchx/cli/test/cmd_run_test.py

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from torchx.cli.argparse_util import ArgOnceAction, torchxconfig
2424
from torchx.cli.cmd_run import _parse_component_name_and_args, CmdBuiltins, CmdRun
25+
from torchx.runner.config import ENV_TORCHXCONFIG
2526
from torchx.schedulers.local_scheduler import SignalException
2627

2728
from torchx.specs import AppDryRunInfo
@@ -40,11 +41,19 @@ def cwd(path: str) -> Generator[None, None, None]:
4041
class CmdRunTest(unittest.TestCase):
4142
def setUp(self) -> None:
4243
self.tmpdir = Path(tempfile.mkdtemp())
44+
45+
# create empty .torchxconfig so that user .torchxconfig is not picked up
46+
empty_config = self.tmpdir / ".torchxconfig"
47+
empty_config.touch()
48+
self.mock_env = patch.dict(os.environ, {ENV_TORCHXCONFIG: str(empty_config)})
49+
self.mock_env.start()
50+
4351
self.parser = argparse.ArgumentParser()
4452
self.cmd_run = CmdRun()
4553
self.cmd_run.add_arguments(self.parser)
4654

4755
def tearDown(self) -> None:
56+
self.mock_env.stop()
4857
shutil.rmtree(self.tmpdir, ignore_errors=True)
4958
ArgOnceAction.called_args = set()
5059
torchxconfig.called_args = set()

torchx/specs/__init__.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
scheduler or pipeline adapter.
1414
"""
1515
import difflib
16-
from typing import Callable, Dict, Optional
16+
from typing import Callable, Dict, Mapping, Optional
1717

1818
from torchx.specs.api import (
1919
ALL,
@@ -48,12 +48,17 @@
4848
)
4949
from torchx.specs.builders import make_app_handle, materialize_appdef, parse_mounts
5050

51-
from torchx.specs.named_resources_aws import NAMED_RESOURCES as AWS_NAMED_RESOURCES
52-
from torchx.specs.named_resources_generic import (
53-
NAMED_RESOURCES as GENERIC_NAMED_RESOURCES,
54-
)
5551
from torchx.util.entrypoints import load_group
5652

53+
from torchx.util.modules import import_attr
54+
55+
AWS_NAMED_RESOURCES: Mapping[str, Callable[[], Resource]] = import_attr(
56+
"torchx.specs.named_resources_aws", "NAMED_RESOURCES", default={}
57+
)
58+
GENERIC_NAMED_RESOURCES: Mapping[str, Callable[[], Resource]] = import_attr(
59+
"torchx.specs.named_resources_generic", "NAMED_RESOURCES", default={}
60+
)
61+
5762
GiB: int = 1024
5863

5964

torchx/specs/finder.py

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from types import ModuleType
1919
from typing import Any, Callable, Dict, Generator, List, Optional, Union
2020

21-
from torchx.specs import AppDef
2221
from torchx.specs.file_linter import get_fn_docstring, TorchxFunctionValidator, validate
2322
from torchx.util import entrypoints
2423
from torchx.util.io import read_conf_file

0 commit comments

Comments
 (0)