Skip to content

Commit 1195a66

Browse files
d4l3kfacebook-github-bot
authored andcommitted
3.7 support (#86)
Summary: Pull Request resolved: #86 This adds python 3.7 support Pull Request resolved: #85 Test Plan: create a python 3.7 venv ``` python setup.py test ``` Reviewed By: tierex Differential Revision: D29321212 Pulled By: kiukchung fbshipit-source-id: 71ddaeefa1baa81841e90dc34158b5710969a891
1 parent ccfe332 commit 1195a66

File tree

10 files changed

+68
-28
lines changed

10 files changed

+68
-28
lines changed

.github/workflows/python-unittests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-18.04
1212
strategy:
1313
matrix:
14-
python-version: [3.8, 3.9]
14+
python-version: [3.7, 3.8, 3.9]
1515
steps:
1616
- name: Setup Python ${{ matrix.python-version }}
1717
uses: actions/setup-python@v2

dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ flake8==3.9.0
1616
ts>=0.5.1
1717
torchserve>=0.4.0
1818
captum>=0.3.1
19+
importlib-metadata

setup.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def get_version():
2323

2424

2525
if __name__ == "__main__":
26-
if sys.version_info < (3, 8):
27-
sys.exit("python >= 3.8 required for torchx-sdk")
26+
if sys.version_info < (3, 7):
27+
sys.exit("python >= 3.7 required for torchx-sdk")
2828

2929
with open("README.md", encoding="utf8") as f:
3030
readme = f.read()
@@ -50,7 +50,7 @@ def get_version():
5050
url="https://github.com/pytorch/torchx",
5151
license="BSD-3",
5252
keywords=["pytorch", "machine learning"],
53-
python_requires=">=3.8",
53+
python_requires=">=3.7",
5454
install_requires=reqs.strip().split("\n"),
5555
include_package_data=True,
5656
packages=find_packages(exclude=("examples", "*.test", "aws*", "*.fb")),
@@ -63,6 +63,9 @@ def get_version():
6363
extras_require={
6464
"kfp": ["kfp==1.6.2"],
6565
"dev": dev_reqs,
66+
':python_version < "3.8"': [
67+
"importlib-metadata",
68+
],
6669
},
6770
# PyPI package information.
6871
classifiers=[

torchx/components/base/test/lib_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
# LICENSE file in the root directory of this source tree.
77

88
import unittest
9-
from importlib import metadata
9+
10+
try:
11+
from importlib import metadata
12+
except ImportError:
13+
import importlib_metadata as metadata
14+
1015
from unittest.mock import patch
1116

1217
from torchx.components.base import torch_dist_role

torchx/pipelines/kfp/adapter.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
import os.path
1111
import shlex
12-
from typing import Protocol, Tuple, Optional, Mapping
12+
from typing import Tuple, Optional, Mapping
1313

1414
import yaml
1515
from kfp import components, dsl
@@ -23,6 +23,7 @@
2323
V1EmptyDirVolumeSource,
2424
)
2525
from torchx.specs import api
26+
from typing_extensions import Protocol
2627

2728
from .version import __version__ as __version__ # noqa F401
2829

@@ -153,15 +154,18 @@ def factory_wrapper(*args: object, **kwargs: object) -> dsl.ContainerOp:
153154
c.output_artifact_paths["mlpipeline-ui-metadata"] = METADATA_FILE
154155
c.add_sidecar(_ui_metadata_sidecar(ui_metadata))
155156

156-
if (cpu := resources.cpu) >= 0:
157+
cpu = resources.cpu
158+
if cpu >= 0:
157159
cpu_str = f"{int(cpu*1000)}m"
158160
container.set_cpu_request(cpu_str)
159161
container.set_cpu_limit(cpu_str)
160-
if (mem := resources.memMB) >= 0:
162+
mem = resources.memMB
163+
if mem >= 0:
161164
mem_str = f"{int(mem)}M"
162165
container.set_memory_request(mem_str)
163166
container.set_memory_limit(mem_str)
164-
if (gpu := resources.gpu) > 0:
167+
gpu = resources.gpu
168+
if gpu > 0:
165169
container.set_gpu_limit(str(gpu))
166170

167171
for name, port in role_spec.port_map.items():

torchx/runtime/plugins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def init_plugins_from_config(config: Dict[str, object]) -> None:
7676
"""
7777
init_plugins_from_config imports all of the plugins listed in provided config.
7878
"""
79-
if plugins := config.get("plugins"):
79+
plugins = config.get("plugins")
80+
if plugins:
8081
if not isinstance(plugins, dict):
8182
raise TypeError(f"plugins must be a dict: {plugins}")
8283

torchx/specs/file_linter.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,14 @@ def _get_return_annotation(
184184
return_def = app_specs_func_def.returns
185185
if not return_def:
186186
return None
187-
if type(return_def) == ast.Attribute:
188-
return_def_attr = cast(ast.Attribute, return_def)
189-
return return_def_attr.attr
190-
elif type(return_def) == ast.Name:
191-
return_def_name = cast(ast.Name, return_def)
192-
return return_def_name.id
193-
elif type(return_def) == ast.Constant:
194-
return_def_constant = cast(ast.Constant, return_def)
195-
return return_def_constant.value
187+
if isinstance(return_def, ast.Attribute):
188+
return return_def.attr
189+
elif isinstance(return_def, ast.Name):
190+
return return_def.id
191+
elif isinstance(return_def, ast.Str):
192+
return return_def.s
193+
elif isinstance(return_def, ast.Constant):
194+
return return_def.value
196195
else:
197196
return None
198197

torchx/specs/test/file_linter_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def test_validate_args_no_type_defs(self) -> None:
193193
linter_errors = validate(
194194
self._file_content, self._path, torchx_function="_test_args_no_type_defs"
195195
)
196+
print(linter_errors)
196197
self.assertEqual(2, len(linter_errors))
197198
self.assertEqual(
198199
"Arg arg0 missing type annotation", linter_errors[0].description

torchx/util/entrypoints.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
# LICENSE file in the root directory of this source tree.
66

77
import warnings
8-
from importlib import metadata
9-
from importlib.metadata import EntryPoint
8+
9+
try:
10+
from importlib import metadata
11+
from importlib.metadata import EntryPoint
12+
except ImportError:
13+
import importlib_metadata as metadata
14+
from importlib_metadata import EntryPoint
1015
from typing import Any, Dict, Optional
1116

1217

torchx/util/test/entrypoints_test.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,35 @@
55
# LICENSE file in the root directory of this source tree.
66

77
import unittest
8-
from importlib.metadata import EntryPoint
8+
9+
try:
10+
from importlib.metadata import EntryPoint
11+
except ImportError:
12+
from importlib_metadata import EntryPoint
13+
from configparser import ConfigParser
914
from typing import Dict
15+
from typing import List
1016
from unittest.mock import MagicMock, patch
1117

1218
from torchx.util.entrypoints import load, load_group
1319

1420

21+
def EntryPoint_from_config(config: ConfigParser) -> List[EntryPoint]:
22+
# from stdlib, Copyright (c) Python Authors
23+
return [
24+
EntryPoint(name, value, group)
25+
for group in config.sections()
26+
for name, value in config.items(group)
27+
]
28+
29+
30+
def EntryPoint_from_text(text: str) -> List[EntryPoint]:
31+
# from stdlib, Copyright (c) Python Authors
32+
config = ConfigParser(delimiters="=")
33+
config.read_string(text)
34+
return EntryPoint_from_config(config)
35+
36+
1537
def foobar() -> str:
1638
return "foobar"
1739

@@ -40,12 +62,11 @@ def barbaz() -> str:
4062
[ep.grp.missing.mod.test]
4163
baz = torchx.util.test.entrypoints_test.missing_module
4264
"""
43-
_ENTRY_POINTS: Dict[str, EntryPoint] = {
44-
# pyre-ignore[16]
45-
"entrypoints.test": EntryPoint._from_text(_EP_TXT),
46-
"ep.grp.test": EntryPoint._from_text(_EP_GRP_TXT),
47-
"ep.grp.missing.attr.test": EntryPoint._from_text(_EP_GRP_IGN_ATTR_TXT),
48-
"ep.grp.missing.mod.test": EntryPoint._from_text(_EP_GRP_IGN_MOD_TXT),
65+
_ENTRY_POINTS: Dict[str, List[EntryPoint]] = {
66+
"entrypoints.test": EntryPoint_from_text(_EP_TXT),
67+
"ep.grp.test": EntryPoint_from_text(_EP_GRP_TXT),
68+
"ep.grp.missing.attr.test": EntryPoint_from_text(_EP_GRP_IGN_ATTR_TXT),
69+
"ep.grp.missing.mod.test": EntryPoint_from_text(_EP_GRP_IGN_MOD_TXT),
4970
}
5071

5172
_METADATA_EPS: str = "torchx.util.entrypoints.metadata.entry_points"

0 commit comments

Comments
 (0)