13
13
import urllib .request
14
14
from typing import List , Union
15
15
16
- WORK_DIR = os .path .join (
17
- os .path .realpath (os .path .dirname (__file__ )),
18
- "pythonmonkey"
19
- )
20
-
21
16
@dataclass
22
17
class PackageItem :
23
18
installation_path : str
@@ -47,8 +42,8 @@ def download_package(tarball_url: str) -> bytes:
47
42
tarball_data : bytes = response .read ()
48
43
return tarball_data
49
44
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 )
52
47
shutil .rmtree (installation_path , ignore_errors = True )
53
48
54
49
with tempfile .TemporaryDirectory (prefix = "pmpm_cache-" ) as tmpdir :
@@ -60,13 +55,13 @@ def unpack_package(installation_path: str, tarball_data: bytes):
60
55
installation_path
61
56
)
62
57
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 :
65
60
items = parse_package_lock_json (f .read ())
66
61
for i in items :
67
62
print ("Installing " + i .installation_path )
68
63
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 )
70
65
71
66
if __name__ == "__main__" :
72
- main ()
67
+ main (os . getcwd () )
0 commit comments