Skip to content

Commit c868ff4

Browse files
committed
refactor(pmpm): support any abstract working directory
1 parent de2e7f6 commit c868ff4

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

python/pminit/pmpm.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
import urllib.request
1414
from 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
2217
class 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

7166
if __name__ == "__main__":
72-
main()
67+
main(os.getcwd())

python/pminit/post-install-hook.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import os
12
from . import pmpm
23

4+
WORK_DIR = os.path.join(
5+
os.path.realpath(os.path.dirname(__file__)),
6+
"pythonmonkey"
7+
)
8+
39
def main():
4-
pmpm.main() # cd pythonmonkey && npm i
10+
pmpm.main(WORK_DIR) # cd pythonmonkey && npm i
511

612
if __name__ == "__main__":
713
main()

0 commit comments

Comments
 (0)