Skip to content

Commit 8a3ccf4

Browse files
committed
support and deprecate legacy installations
1 parent 9fb6c68 commit 8a3ccf4

File tree

4 files changed

+125
-27
lines changed

4 files changed

+125
-27
lines changed

MANIFEST.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
recursive-include src/sagemaker *.py
2+
3+
include src/sagemaker/image_uri_config/*.json
4+
include src/sagemaker/serve/schema/*.json
5+
include src/sagemaker/serve/requirements.txt
6+
recursive-include requirements *
7+
8+
include VERSION
9+
include LICENSE.txt
10+
include README.rst
11+
12+
prune tests
13+
14+
recursive-exclude * __pycache__
15+
recursive-exclude * *.py[co]

hatch_build.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
1+
import os
12
import sys
23

34
from hatchling.metadata.plugin.interface import MetadataHookInterface
45

56

67
class CustomMetadataHook(MetadataHookInterface):
78
def update(self, metadata):
8-
optional_dependencies = metadata["optional-dependencies"]
9-
optional_dependencies["all"] = [
10-
dependency
11-
for optional_dependencies in optional_dependencies.values()
12-
for dependency in optional_dependencies
13-
]
14-
optional_dependencies["test"].extend(optional_dependencies["all"])
15-
16-
# remove torch and torchvision if python version is not 3.10/3.11
17-
if sys.version_info.minor not in (10, 11):
18-
optional_dependencies["test"] = list(
19-
filter(
20-
lambda d: not d.startswith(
21-
("sentencepiece", "transformers", "torch", "torchvision")
22-
),
23-
optional_dependencies["test"],
24-
)
9+
metadata["optional-dependencies"] = get_optional_dependencies(self.root)
10+
11+
12+
def get_optional_dependencies(root):
13+
14+
def read_feature_deps(feature):
15+
req_file = os.path.join(root, "requirements", "extras", f"{feature}_requirements.txt")
16+
with open(req_file, encoding="utf-8") as f:
17+
return list(filter(lambda d: not d.startswith("#"), f.read().splitlines()))
18+
19+
optional_dependencies = {"all": []}
20+
21+
for feature in ("feature-processor", "huggingface", "local", "scipy"):
22+
dependencies = read_feature_deps(feature)
23+
optional_dependencies[feature] = dependencies
24+
optional_dependencies["all"].extend(dependencies)
25+
26+
# Test dependencies come last because we don't want them in `all`
27+
optional_dependencies["test"] = read_feature_deps("test")
28+
optional_dependencies["test"].extend(optional_dependencies["all"])
29+
30+
# remove torch and torchvision if python version is not 3.10/3.11
31+
if sys.version_info.minor not in (10, 11):
32+
optional_dependencies["test"] = list(
33+
filter(
34+
lambda d: not d.startswith(
35+
("sentencepiece", "transformers", "torch", "torchvision")
36+
),
37+
optional_dependencies["test"],
2538
)
39+
)
40+
41+
return optional_dependencies

pyproject.toml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["hatchling", "hatch-requirements-txt>=0.3.0"]
2+
requires = ["hatchling"]
33
build-backend = "hatchling.build"
44

55
[project]
@@ -65,15 +65,8 @@ Homepage = "https://github.com/aws/sagemaker-python-sdk"
6565
path = "VERSION"
6666
pattern = "(?P<version>.+)"
6767

68-
# Keep format of *_requirements.txt to be tracked by dependabot
69-
[tool.hatch.metadata.hooks.requirements_txt.optional-dependencies]
70-
feature-processor = ["requirements/extras/feature-processor_requirements.txt"]
71-
huggingface = ["requirements/extras/huggingface_requirements.txt"]
72-
local = ["requirements/extras/local_requirements.txt"]
73-
scipy = ["requirements/extras/scipy_requirements.txt"]
74-
test = ["requirements/extras/test_requirements.txt"]
75-
76-
# Then do some postprocessing of optional dependencies
68+
# Dynamically define optional dependencies from requirements.txt files so
69+
# they can be be tracked by Dependabot
7770
[tool.hatch.metadata.hooks.custom]
7871

7972
[tool.hatch.build.targets.wheel]

setup.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Placeholder docstring"""
14+
from __future__ import absolute_import
15+
16+
import os
17+
import re
18+
import sys
19+
from ast import literal_eval
20+
from glob import glob
21+
from pathlib import Path
22+
23+
from setuptools import find_packages, setup
24+
25+
sys.stderr.write(
26+
"""
27+
===============================
28+
Unsupported installation method
29+
===============================
30+
31+
This version of sagemaker no longer supports installation with `python setup.py install`.
32+
33+
Please use `python -m pip install .` instead.
34+
"""
35+
)
36+
37+
HERE = Path(__file__).parent.absolute()
38+
PYPROJECT = HERE.joinpath("pyproject.toml").read_text(encoding="utf-8")
39+
BUILD_SCRIPT = HERE.joinpath("hatch_build.py").read_text(encoding="utf-8")
40+
41+
42+
def get_dependencies():
43+
pattern = r"^dependencies = (\[.*?\])$"
44+
array = re.search(pattern, PYPROJECT, flags=re.MULTILINE | re.DOTALL).group(1)
45+
return literal_eval(array)
46+
47+
48+
def get_optional_dependencies():
49+
pattern = r"^def get_optional_dependencies.+"
50+
function = re.search(pattern, BUILD_SCRIPT, flags=re.MULTILINE | re.DOTALL).group(0)
51+
identifiers = {}
52+
exec(function, None, identifiers)
53+
return identifiers["get_optional_dependencies"](str(HERE))
54+
55+
56+
setup(
57+
name="sagemaker",
58+
version=HERE.joinpath("VERSION").read_text().strip(),
59+
packages=find_packages("src"),
60+
package_dir={"": "src"},
61+
package_data={"": ["*.whl"]},
62+
py_modules=[os.path.splitext(os.path.basename(path))[0] for path in glob("src/*.py")],
63+
include_package_data=True,
64+
install_requires=get_dependencies(),
65+
extras_require=get_optional_dependencies(),
66+
entry_points={
67+
"console_scripts": [
68+
"sagemaker-upgrade-v2=sagemaker.cli.compatibility.v2.sagemaker_upgrade_v2:main",
69+
]
70+
},
71+
scripts=[
72+
"src/sagemaker/serve/model_server/triton/pack_conda_env.sh",
73+
],
74+
)

0 commit comments

Comments
 (0)