Skip to content

Commit 9449660

Browse files
author
Bryannah Hernandez
committed
renaming functions
1 parent 1162751 commit 9449660

File tree

4 files changed

+25
-32
lines changed

4 files changed

+25
-32
lines changed

src/sagemaker/serve/builder/requirements_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class RequirementsManager:
2323
"""Manages dependency installation by detecting file types"""
2424

25-
def detect_file_exists(self, dependencies: str = None) -> str:
25+
def capture_and_install_dependencies(self, dependencies: str = None) -> str:
2626
"""Detects the type of file dependencies will be installed from
2727
2828
If a req.txt or conda.yml file is provided, it verifies their existence and
@@ -34,7 +34,7 @@ def detect_file_exists(self, dependencies: str = None) -> str:
3434
Returns:
3535
file path of the existing or generated dependencies file
3636
"""
37-
dependencies = self._capture_from_local_runtime()
37+
dependencies = self._detect_conda_env_and_local_dependencies()
3838

3939
# Dependencies specified as either req.txt or conda_env.yml
4040
if dependencies.endswith(".txt"):
@@ -47,7 +47,7 @@ def detect_file_exists(self, dependencies: str = None) -> str:
4747
def _install_requirements_txt(self):
4848
"""Install requirements.txt file using pip"""
4949
logger.info("Running command to pip install")
50-
subprocess.run("pip install -r requirements.txt", shell=True, check=True)
50+
subprocess.run("pip install -r in_process_requirements.txt", shell=True, check=True)
5151
logger.info("Command ran successfully")
5252

5353
def _update_conda_env_in_path(self):
@@ -64,7 +64,7 @@ def _get_active_conda_env_prefix(self) -> str:
6464
"""Returns the conda prefix from the set environment variable. None otherwise."""
6565
return os.getenv("CONDA_PREFIX")
6666

67-
def _capture_from_local_runtime(self) -> str:
67+
def _detect_conda_env_and_local_dependencies(self) -> str:
6868
"""Generates dependencies list from the user's local runtime.
6969
7070
Raises RuntimeEnvironmentError if not able to.

src/sagemaker/serve/builder/transformers_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,6 @@ def _create_conda_env(self):
387387
"""Creating conda environment by running commands"""
388388

389389
try:
390-
RequirementsManager().detect_file_exists(self)
390+
RequirementsManager().capture_and_install_dependencies(self)
391391
except subprocess.CalledProcessError:
392392
print("Failed to create and activate conda environment.")

src/sagemaker/serve/utils/in_process_requirements.txt

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
bzip2=1.0.8
2-
ca-certificates=2023.01.10
3-
libffi=3.4.2
4-
ncurses=6.4
5-
openssl=1.1.1t
6-
pip=23.0.1
7-
python=3.10.10
8-
readline=8.2
9-
setuptools=66.0.0
10-
sqlite=3.41.2
11-
tk=8.6.12
12-
wheel=0.38.4
13-
xz=5.2.10
14-
zlib=1.2.13
151
altair>=4.2.2
162
anyio>=3.6.2
173
awscli>=1.27.114
@@ -27,7 +13,7 @@ contextlib2>=21.6.0
2713
decorator>=5.1.1
2814
dill>=0.3.6
2915
docutils>=0.16
30-
entrypoints>=0.4
16+
entrypoints>=0.4
3117
filelock>=3.11.0
3218
gitdb>=4.0.10
3319
gitpython>=3.1.31
@@ -93,3 +79,7 @@ tzlocal>=4.3
9379
urllib3>=1.26.15
9480
validators>=0.20.0
9581
zipp>=3.15.0
82+
uvicorn>=0.30.1
83+
fastapi>=0.111.0
84+
nest-asyncio
85+
transformers

tests/unit/sagemaker/serve/builder/test_requirements_manager.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,34 @@ class TestRequirementsManager(unittest.TestCase):
2727
"sagemaker.serve.builder.requirements_manager.RequirementsManager._install_requirements_txt"
2828
)
2929
@patch(
30-
"sagemaker.serve.builder.requirements_manager.RequirementsManager._capture_from_local_runtime"
30+
"sagemaker.serve.builder.requirements_manager.RequirementsManager._detect_conda_env_and_local_dependencies"
3131
)
32-
def test_detect_file_exists(
32+
def test_capture_and_install_dependencies(
3333
self,
34-
mock_capture_from_local_runtime,
34+
mock_detect_conda_env_and_local_dependencies,
3535
mock_install_requirements_txt,
3636
mock_update_conda_env_in_path,
3737
) -> str:
3838

39-
mock_capture_from_local_runtime.side_effect = lambda: ".txt"
40-
RequirementsManager().detect_file_exists()
39+
mock_detect_conda_env_and_local_dependencies.side_effect = lambda: ".txt"
40+
RequirementsManager().capture_and_install_dependencies()
4141
mock_install_requirements_txt.assert_called_once()
4242

43-
mock_capture_from_local_runtime.side_effect = lambda: ".yml"
44-
RequirementsManager().detect_file_exists()
43+
mock_detect_conda_env_and_local_dependencies.side_effect = lambda: ".yml"
44+
RequirementsManager().capture_and_install_dependencies()
4545
mock_update_conda_env_in_path.assert_called_once()
4646

4747
@patch(
48-
"sagemaker.serve.builder.requirements_manager.RequirementsManager._capture_from_local_runtime"
48+
"sagemaker.serve.builder.requirements_manager.RequirementsManager._detect_conda_env_and_local_dependencies"
4949
)
50-
def test_detect_file_exists_fail(self, mock__capture_from_local_runtime) -> str:
50+
def test_capture_and_install_dependencies_fail(
51+
self, mock_detect_conda_env_and_local_dependencies
52+
) -> str:
5153
mock_dependencies = "mock.ini"
52-
mock__capture_from_local_runtime.side_effect = lambda: "invalid requirement"
54+
mock_detect_conda_env_and_local_dependencies.side_effect = lambda: "invalid requirement"
5355
self.assertRaises(
54-
ValueError, lambda: RequirementsManager().detect_file_exists(mock_dependencies)
56+
ValueError,
57+
lambda: RequirementsManager().capture_and_install_dependencies(mock_dependencies),
5558
)
5659

5760
@patch("sagemaker.serve.builder.requirements_manager.logger")
@@ -63,7 +66,7 @@ def test_install_requirements_txt(self, mock_subprocess, mock_logger):
6366
calls = [call("Running command to pip install"), call("Command ran successfully")]
6467
mock_logger.info.assert_has_calls(calls)
6568
mock_subprocess.run.assert_called_once_with(
66-
"pip install -r requirements.txt", shell=True, check=True
69+
"pip install -r in_process_requirements.txt", shell=True, check=True
6770
)
6871

6972
@patch("sagemaker.serve.builder.requirements_manager.logger")

0 commit comments

Comments
 (0)