Skip to content

Commit e685a37

Browse files
jcarey03pfifer
authored andcommitted
Raise exception when Maven artifacts fail download in setup.py (#80)
1 parent 82c2f6e commit e685a37

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

setup.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616
import sys
1717

1818
import os
19+
import shutil
1920
from setuptools import Command
2021
from setuptools import setup
2122
from setuptools.command.install import install
2223

2324
if sys.version_info[0] >= 3:
2425
# Python 3
25-
from urllib.request import urlretrieve
26+
from urllib.request import urlopen
2627
else:
2728
# Python 2
28-
from urllib import urlretrieve
29+
from urllib2 import urlopen
2930

3031
#
3132
# This script modifies the basic setuptools by adding some functionality to the standard
@@ -113,7 +114,7 @@ def download_and_check(self):
113114
self.on_completion()
114115
missing_jars = self.missing_jars()
115116
if len(missing_jars) > 0:
116-
print(self.warning_string(missing_jars))
117+
raise RuntimeError(self.warning_string(missing_jars))
117118

118119
def package_destination(self, artifcat_id, version):
119120
return '{artifcat_id}-{version}.jar'.format(artifcat_id=artifcat_id, version=version)
@@ -141,10 +142,12 @@ def download_file(self, url, dest):
141142
"""
142143
print('Attempting to retrieve remote jar {url}'.format(url=url))
143144
try:
144-
urlretrieve(url, dest)
145+
response = urlopen(url)
146+
with open(dest, 'wb') as dest_file:
147+
shutil.copyfileobj(response, dest_file)
145148
print('Saving {url} -> {dest}'.format(url=url, dest=dest))
146-
except:
147-
print('Failed to retrieve {url}'.format(url=url))
149+
except Exception as e:
150+
print('Failed to retrieve {url}: {e}'.format(url=url, e=e))
148151
return
149152

150153
def download_files(self):

0 commit comments

Comments
 (0)