Skip to content

Remove main function entrypoint in ModelBuilder dependency manager. #5058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/sagemaker/serve/detector/dependency_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,34 @@ def capture_dependencies(dependencies: dict, work_dir: Path, capture_all: bool =
"""Placeholder docstring"""
path = work_dir.joinpath("requirements.txt")
if "auto" in dependencies and dependencies["auto"]:
import site

pkl_path = work_dir.joinpath(PKL_FILE_NAME)
dest_path = path
site_packages_dir = site.getsitepackages()[0]
pickle_command_dir = "/sagemaker/serve/detector"

command = [
sys.executable,
Path(__file__).parent.joinpath("pickle_dependencies.py"),
"--pkl_path",
work_dir.joinpath(PKL_FILE_NAME),
"--dest",
path,
"-c",
]

if capture_all:
command.append("--capture_all")
command.append(
f"from pickle_dependencies import get_all_requirements;"
f'get_all_requirements("{dest_path}")'
)
else:
command.append(
f"from pickle_dependencies import get_requirements_for_pkl_file;"
f'get_requirements_for_pkl_file("{pkl_path}", "{dest_path}")'
)

subprocess.run(
command,
env={"SETUPTOOLS_USE_DISTUTILS": "stdlib"},
check=True,
cwd=site_packages_dir + pickle_command_dir,
)

with open(path, "r") as f:
Expand Down
30 changes: 0 additions & 30 deletions src/sagemaker/serve/detector/pickle_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import absolute_import
from pathlib import Path
from typing import List
import argparse
import email.parser
import email.policy
import json
Expand Down Expand Up @@ -129,32 +128,3 @@ def get_all_requirements(dest: Path):
version = package_info.get("version")

out.write(f"{name}=={version}\n")


def parse_args():
"""Placeholder docstring"""
parser = argparse.ArgumentParser(
prog="pkl_requirements", description="Generates a requirements.txt for a cloudpickle file"
)
parser.add_argument("--pkl_path", required=True, help="path of the pkl file")
parser.add_argument("--dest", required=True, help="path of the destination requirements.txt")
parser.add_argument(
"--capture_all",
action="store_true",
help="capture all dependencies in current environment",
)
args = parser.parse_args()
return (Path(args.pkl_path), Path(args.dest), args.capture_all)


def main():
"""Placeholder docstring"""
pkl_path, dest, capture_all = parse_args()
if capture_all:
get_all_requirements(dest)
else:
get_requirements_for_pkl_file(pkl_path, dest)


if __name__ == "__main__":
main()