-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor wheel_resolver to allow for non-PyPI downloads (#167)
* Refactor wheel_resolver to download from non-PyPI URLs * improve logging and error handling * Improve logging * Test new exit points of refactored main
- Loading branch information
1 parent
2a70346
commit 01767c8
Showing
5 changed files
with
125 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,37 @@ | ||
import os | ||
import sys | ||
import urllib.request | ||
import logging | ||
import typing | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class OutputNotSetError(RuntimeError): | ||
pass | ||
|
||
def try_download(url): | ||
""" | ||
Try to download url to $OUTS. Returns false if | ||
it failed. | ||
""" | ||
|
||
def get() -> str: | ||
output = os.environ.get("OUTS") | ||
if output is None: | ||
raise OutputNotSetError() | ||
|
||
try: | ||
urllib.request.urlretrieve(url, output) | ||
except urllib.error.HTTPError: | ||
return False | ||
|
||
return True | ||
return output | ||
|
||
|
||
def download( | ||
package_name: str, | ||
package_version: typing.Optional[str], | ||
url: typing.Tuple[str], | ||
download_output: str, | ||
) -> bool: | ||
"""Download url to $OUTS.""" | ||
for u in url: | ||
try: | ||
urllib.request.urlretrieve(u, download_output) | ||
except urllib.error.HTTPError as error: | ||
_LOGGER.warning( | ||
f"download {package_name}-{package_version} from {u}: {error}", | ||
) | ||
else: | ||
_LOGGER.info(f"downloaded {package_name}-{package_version} from {u}") | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import typing | ||
import distlib.locators | ||
import logging | ||
import itertools | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|