-
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 download from non-PyPI URLs
- Loading branch information
1 parent
9b87a83
commit c7df563
Showing
2 changed files
with
49 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,33 @@ | ||
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: str, url: typing.List[str], download_output: str | ||
) -> typing.Optional[str]: | ||
"""Download url to $OUTS.""" | ||
for u in url: | ||
try: | ||
urllib.request.urlretrieve(u, download_output) | ||
except urllib.error.HTTPError: | ||
_LOGGER.warning( | ||
"%s-%s is not available in %s", package_name, package_version, u | ||
) | ||
else: | ||
return u | ||
return None |