Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise exception when Maven artifacts fail download in setup.py #80

Merged
merged 2 commits into from
Jun 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
import sys

import os
import shutil
from setuptools import Command
from setuptools import setup
from setuptools.command.install import install

if sys.version_info[0] >= 3:
# Python 3
from urllib.request import urlretrieve
from urllib.request import urlopen
else:
# Python 2
from urllib import urlretrieve
from urllib2 import urlopen

#
# This script modifies the basic setuptools by adding some functionality to the standard
Expand Down Expand Up @@ -113,7 +114,7 @@ def download_and_check(self):
self.on_completion()
missing_jars = self.missing_jars()
if len(missing_jars) > 0:
print(self.warning_string(missing_jars))
raise RuntimeError(self.warning_string(missing_jars))

def package_destination(self, artifcat_id, version):
return '{artifcat_id}-{version}.jar'.format(artifcat_id=artifcat_id, version=version)
Expand Down Expand Up @@ -141,10 +142,12 @@ def download_file(self, url, dest):
"""
print('Attempting to retrieve remote jar {url}'.format(url=url))
try:
urlretrieve(url, dest)
response = urlopen(url)
with open(dest, 'wb') as dest_file:
shutil.copyfileobj(response, dest_file)
print('Saving {url} -> {dest}'.format(url=url, dest=dest))
except:
print('Failed to retrieve {url}'.format(url=url))
except Exception as e:
print('Failed to retrieve {url}: {e}'.format(url=url, e=e))
return

def download_files(self):
Expand Down