46
46
BUILDDEPS_SCRIPT_NAME = "pip_find_builddeps.py"
47
47
48
48
49
- def shell (command , directory ) :
49
+ def shell (command : str , directory : str ) -> bytes :
50
50
"""Run command via shell inside specified directory."""
51
51
return subprocess .check_output (command , cwd = directory , shell = True ) # noqa: S602
52
52
53
53
54
- def copy_project_stub (directory ) :
54
+ def copy_project_stub (directory : str ) -> None :
55
55
"""Copy all files that represent project stub into specified directory."""
56
56
for project_file in PROJECT_FILES :
57
57
shutil .copy (project_file , directory )
58
58
59
59
60
- def remove_torch_dependency (directory ) :
60
+ def remove_torch_dependency (directory : str ) -> None :
61
61
"""Remove torch (specifically torch+cpu) dependency from the project.toml file."""
62
62
shell ("pdm remove torch" , directory )
63
63
64
64
65
- def generate_requirements_file (work_directory ) :
65
+ def generate_requirements_file (work_directory : str ) -> None :
66
66
"""Generate file requirements.txt that contains hashes for all packages."""
67
67
shell ("pip-compile -vv pyproject.toml --generate-hashes" , work_directory )
68
68
69
69
70
- def remove_package (directory , source , target , package_prefix ):
70
+ def remove_package (
71
+ directory : str , source : str , target : str , package_prefix : str
72
+ ) -> None :
71
73
"""Remove package or packages with specified prefix from the requirements file."""
72
74
package_block = False
73
75
@@ -86,7 +88,7 @@ def remove_package(directory, source, target, package_prefix):
86
88
fout .write (line )
87
89
88
90
89
- def remove_unwanted_dependencies (directory ) :
91
+ def remove_unwanted_dependencies (directory : str ) -> None :
90
92
"""Remove all unwanted dependencies from requirements file, creating in-between files."""
91
93
# the torch itself
92
94
remove_package (directory , "requirements.txt" , "step1.txt" , "torch" )
@@ -95,19 +97,19 @@ def remove_unwanted_dependencies(directory):
95
97
remove_package (directory , "step1.txt" , "step2.txt" , "nvidia" )
96
98
97
99
98
- def wheel_url (registry , wheel ) :
100
+ def wheel_url (registry : str , wheel : str ) -> str :
99
101
"""Construct full URL to wheel."""
100
102
return f"{ registry } /{ wheel } "
101
103
102
104
103
- def download_wheel (directory , registry , wheel ) :
105
+ def download_wheel (directory : str , registry : str , wheel : str ) -> None :
104
106
"""Download selected wheel from registry."""
105
107
url = wheel_url (registry , wheel )
106
108
into = join (directory , wheel )
107
109
urlretrieve (url , into ) # noqa: S310
108
110
109
111
110
- def generate_hash (directory , registry , wheel , target ) :
112
+ def generate_hash (directory : str , registry : str , wheel : str , target : str ) -> None :
111
113
"""Generate hash entry for given wheel."""
112
114
output = shell (f"pip hash { wheel } " , directory )
113
115
hash_line = output .decode ("ascii" ).splitlines ()[1 ]
@@ -117,7 +119,7 @@ def generate_hash(directory, registry, wheel, target):
117
119
fout .write (f" { hash_line } \n " )
118
120
119
121
120
- def generate_list_of_packages (work_directory ) :
122
+ def generate_list_of_packages (work_directory : str ) -> None :
121
123
"""Generate list of packages, take care of unwanted packages and wheel with Torch package."""
122
124
copy_project_stub (work_directory )
123
125
if PROCESS_SPECIAL_PACKAGES :
@@ -135,7 +137,7 @@ def generate_list_of_packages(work_directory):
135
137
shutil .copy (join (work_directory , "requirements.txt" ), "requirements.txt" )
136
138
137
139
138
- def generate_packages_to_be_build (work_directory ) :
140
+ def generate_packages_to_be_build (work_directory : str ) -> None :
139
141
"""Generate list of packages that will need to be build."""
140
142
# download helper script to generate list of packages
141
143
url = f"{ CACHITO_URL } /{ BUILDDEPS_SCRIPT_PATH } /{ BUILDDEPS_SCRIPT_NAME } "
0 commit comments