1313import urllib .request
1414from typing import List , Union
1515
16- WORK_DIR = os .path .join (
17- os .path .realpath (os .path .dirname (__file__ )),
18- "pythonmonkey"
19- )
20-
2116@dataclass
2217class PackageItem :
2318 installation_path : str
@@ -47,8 +42,8 @@ def download_package(tarball_url: str) -> bytes:
4742 tarball_data : bytes = response .read ()
4843 return tarball_data
4944
50- def unpack_package (installation_path : str , tarball_data : bytes ):
51- installation_path = os .path .join (WORK_DIR , installation_path )
45+ def unpack_package (work_dir : str , installation_path : str , tarball_data : bytes ):
46+ installation_path = os .path .join (work_dir , installation_path )
5247 shutil .rmtree (installation_path , ignore_errors = True )
5348
5449 with tempfile .TemporaryDirectory (prefix = "pmpm_cache-" ) as tmpdir :
@@ -60,13 +55,13 @@ def unpack_package(installation_path: str, tarball_data: bytes):
6055 installation_path
6156 )
6257
63- def main ():
64- with open (os .path .join (WORK_DIR , "package-lock.json" ), encoding = "utf-8" ) as f :
58+ def main (work_dir : str ):
59+ with open (os .path .join (work_dir , "package-lock.json" ), encoding = "utf-8" ) as f :
6560 items = parse_package_lock_json (f .read ())
6661 for i in items :
6762 print ("Installing " + i .installation_path )
6863 tarball_data = download_package (i .tarball_url )
69- unpack_package (i .installation_path , tarball_data )
64+ unpack_package (work_dir , i .installation_path , tarball_data )
7065
7166if __name__ == "__main__" :
72- main ()
67+ main (os . getcwd () )
0 commit comments