8383
8484class MavenJarDownloader :
8585
86- def __init__ (self , destdir = JAR_DIRECTORY , packages = REMOTE_MAVEN_PACKAGES ):
86+ def __init__ (self , on_completion , destdir = JAR_DIRECTORY , packages = REMOTE_MAVEN_PACKAGES ):
87+ self .on_completion = on_completion
8788 self .destdir = destdir
8889 self .packages = packages
8990
91+ def warning_string (self , missing_jars = []):
92+ s = '''The following jars were not installed because they were not
93+ present in this package at the time of installation:'''
94+ for jar in missing_jars :
95+ s += '\n {jar}' .format (jar = jar )
96+ s += '''
97+ This doesn't affect the rest of the installation, but may make it more
98+ difficult for you to run the sample app and get started.
99+
100+ You should consider running:
101+
102+ python setup.py download_jars
103+ python setup.py install
104+
105+ Which will download the required jars and rerun the install.
106+ '''
107+ return s
108+
109+ def download_and_check (self ):
110+ self .download_files ()
111+ self .on_completion ()
112+ missing_jars = self .missing_jars ()
113+ if len (missing_jars ) > 0 :
114+ print (self .warning_string (missing_jars ))
115+
90116 def package_destination (self , artifcat_id , version ):
91117 return '{artifcat_id}-{version}.jar' .format (artifcat_id = artifcat_id , version = version )
92118
@@ -156,23 +182,8 @@ def run(self):
156182
157183class InstallThenCheckForJars (install ):
158184
159- def warning_string (self , missing_jars = []):
160- s = '''The following jars were not installed because they were not
161- present in this package at the time of installation:'''
162- for jar in missing_jars :
163- s += '\n {jar}' .format (jar = jar )
164- s += '''
165- This doesn't affect the rest of the installation, but may make it more
166- difficult for you to run the sample app and get started.
167-
168- You should consider running:
169-
170- python setup.py download_jars
171- python setup.py install
172-
173- Which will download the required jars and rerun the install.
174- '''
175- return s
185+ def do_install (self ):
186+ install .run (self )
176187
177188 def run (self ):
178189 """
@@ -181,14 +192,48 @@ def run(self):
181192 in this package. If they aren't present we warn the user and give
182193 them some advice on how to retry getting the jars.
183194 """
184- downloader = MavenJarDownloader ()
185- downloader .download_files ()
186- install .run (self )
187- missing_jars = downloader .missing_jars ()
188- if len (missing_jars ) > 0 :
189- print (self .warning_string (missing_jars ))
195+ downloader = MavenJarDownloader (self .do_install )
196+ downloader .download_and_check ()
197+
198+
199+ try :
200+ from wheel .bdist_wheel import bdist_wheel
201+
202+
203+ class BdistWheelWithJars (bdist_wheel ):
204+ """
205+ This overrides the bdist_wheel command, that handles building a binary wheel of the package.
206+ Currently, as far as I can tell, binary wheel creation only occurs during the virtual environment creation.
207+ The package that bdist_wheel comes from isn't a modeled dependency of this package, but is required for virtual
208+ environment creation.
209+ """
210+
211+ def do_run (self ):
212+ bdist_wheel .run (self )
213+
214+ def run (self ):
215+ downloader = MavenJarDownloader (self .do_run )
216+ downloader .download_and_check ()
217+
218+ except ImportError :
219+ pass
190220
191221if __name__ == '__main__' :
222+ commands = {
223+ 'download_jars' : DownloadJarsCommand ,
224+ 'install' : InstallThenCheckForJars ,
225+ }
226+ try :
227+ #
228+ # BdistWheelWithJars will only be present if the wheel package is present, and that is present during
229+ # virtual environment creation.
230+ # It's important to note this is a hack. There doesn't appear to be a way to execute hooks around wheel
231+ # creation by design. See https://github.com/pypa/packaging-problems/issues/64 for more information.
232+ #
233+ commands ['bdist_wheel' ] = BdistWheelWithJars
234+ except NameError :
235+ pass
236+
192237 setup (
193238 name = PACKAGE_NAME ,
194239 version = PACKAGE_VERSION ,
@@ -202,10 +247,7 @@ def run(self):
202247 'samples' : ['sample.properties' ],
203248 },
204249 install_requires = PYTHON_REQUIREMENTS ,
205- cmdclass = {
206- 'download_jars' : DownloadJarsCommand ,
207- 'install' : InstallThenCheckForJars ,
208- },
250+ cmdclass = commands ,
209251 url = "https://github.com/awslabs/amazon-kinesis-client-python" ,
210252 keywords = "amazon kinesis client library python" ,
211253 zip_safe = False ,
0 commit comments