|
11 | 11 |
|
12 | 12 |
|
13 | 13 | def fetch_dependency(module_name: str, specifier: str, install_path: str): |
14 | | - """ |
15 | | - Shells out to PIP in order to download and unzip the named package into the specified path. This method only runs |
16 | | - `pip download`, NOT `pip install`, so it's presumably safe. |
| 14 | + """Shells out to PIP in order to download and unzip the named package into |
| 15 | + the specified path. This method only runs `pip download`, NOT `pip |
| 16 | + install`, so it's presumably safe. |
| 17 | +
|
17 | 18 | :param module_name: the name of the package to download |
18 | 19 | :param specifier: the version specifier for the package |
19 | 20 | :param install_path: the path in which to install the downloaded package |
20 | 21 | """ |
21 | 22 | with tempfile.TemporaryDirectory() as download_folder: |
22 | | - log.info("Attempting to download package %s to %s", module_name, download_folder, exc_info=True) |
| 23 | + log.info("Attempting to download package %s to %s", |
| 24 | + module_name, download_folder, exc_info=True) |
23 | 25 | # TODO: check the result status |
24 | 26 |
|
25 | 27 | index_url = os.environ.get('INDEX_URL') |
26 | 28 | if index_url is not None: |
27 | | - result = pip.main(["download", "--no-deps", "-i", index_url, "-d", download_folder, module_name+specifier]) |
| 29 | + result = pip.main(["download", "--no-deps", "-i", index_url, |
| 30 | + "-d", download_folder, module_name + specifier]) |
28 | 31 | else: |
29 | | - result = pip.main(["download", "--no-deps", "-d", download_folder, module_name+specifier]) |
| 32 | + result = pip.main(["download", "--no-deps", "-d", |
| 33 | + download_folder, module_name + specifier]) |
30 | 34 | if result != pip.status_codes.SUCCESS: |
31 | 35 | log.error("Unable to fetch package %s", module_name) |
32 | 36 | return |
33 | 37 | for thing in os.listdir(download_folder): |
34 | 38 | thing_abs = os.path.join(download_folder, thing) |
35 | 39 | if os.path.isdir(thing_abs): |
36 | | - log.debug("Moving %s to %s", thing, install_path, exc_info=True) |
| 40 | + log.debug("Moving %s to %s", thing, |
| 41 | + install_path, exc_info=True) |
37 | 42 | shutil.move(thing_abs, install_path) |
38 | 43 | elif thing.endswith(".whl") or thing.endswith(".zip"): |
39 | | - log.debug("Unzipping %s to %s", thing, install_path, exc_info=True) |
40 | | - result = subprocess.run(["unzip", "-o", "-d", install_path, thing_abs]) |
| 44 | + log.debug("Unzipping %s to %s", thing, |
| 45 | + install_path, exc_info=True) |
| 46 | + result = subprocess.run( |
| 47 | + ["unzip", "-o", "-d", install_path, thing_abs]) |
41 | 48 | elif thing.endswith(".tar.gz"): |
42 | | - log.debug("Untarring %s to %s", thing, install_path, exc_info=True) |
43 | | - result = subprocess.run(["tar", "-C", install_path, "-xzf", thing_abs]) |
| 49 | + log.debug("Untarring %s to %s", thing, |
| 50 | + install_path, exc_info=True) |
| 51 | + result = subprocess.run( |
| 52 | + ["tar", "-C", install_path, "-xzf", thing_abs]) |
44 | 53 | elif thing.endswith(".tar.bz2"): |
45 | | - log.debug("Untarring %s to %s", thing, install_path, exc_info=True) |
46 | | - result = subprocess.run(["tar", "-C", install_path, "-xjf", thing_abs]) |
| 54 | + log.debug("Untarring %s to %s", thing, |
| 55 | + install_path, exc_info=True) |
| 56 | + result = subprocess.run( |
| 57 | + ["tar", "-C", install_path, "-xjf", thing_abs]) |
47 | 58 | else: |
48 | | - log.warning("Unrecognized package file: %s", thing, exc_info=True) |
49 | | - |
| 59 | + log.warning("Unrecognized package file: %s", |
| 60 | + thing, exc_info=True) |
0 commit comments