@@ -258,8 +258,6 @@ def find_release(wheel_cache_dir, wheel, wheel_data):
258258 break
259259
260260 if not wheel_release :
261- import pdb
262- pdb .set_trace ()
263261 raise click .ClickException (
264262 "Unable to find release for package {name} of version "
265263 "{version}" .format (** wheel ))
@@ -285,17 +283,20 @@ def find_release(wheel_cache_dir, wheel, wheel_data):
285283 return release
286284
287285
288- def process_wheel (wheel_cache_dir , wheel , sources , verbose , index = INDEX_URL ,
289- chunk_size = 2048 ):
286+ def process_wheel (wheel_cache_dir , wheel , sources , repo_types , verbose ,
287+ index = INDEX_URL , chunk_size = 2048 ):
290288 """
291289 """
292290
291+ repo_type = repo_types .get (wheel ['name' ], None )
293292 if wheel ['name' ] in sources :
294293 release = dict ()
295294 release ['url' ] = sources [wheel ['name' ]]
296295 release ['hash_type' ] = 'sha256'
297296
298- if release ['url' ].startswith ('http://' ) or release ['url' ].startswith ('https://' ):
297+ if repo_type is None and \
298+ (release ['url' ].startswith ('http://' ) or \
299+ release ['url' ].startswith ('https://' )):
299300
300301 release ['fetch_type' ] = 'fetchurl'
301302
@@ -309,16 +310,18 @@ def process_wheel(wheel_cache_dir, wheel, sources, verbose, index=INDEX_URL,
309310 hash = hashlib .sha256 (fd .read ())
310311
311312 release ['hash_value' ] = hash .hexdigest ()
312- elif release ['url' ].startswith ('git' ):
313+
314+ elif repo_type == 'git' :
313315 revision = ''
314316 if release ['url' ].startswith ('git+' ):
315317 release ['url' ] = release ['url' ][4 :]
316318 if '@' in release ['url' ]:
317319 release ['url' ], revision = release ['url' ].split ('@' )
320+
318321 release ['fetch_type' ] = 'fetchgit'
319322 command = 'nix-prefetch-git {url} {revision}' .format (
320323 url = release ['url' ],
321- revision = revision
324+ revision = revision ,
322325 )
323326 return_code , output = cmd (command , verbose != 0 )
324327 if return_code != 0 :
@@ -342,6 +345,43 @@ def process_wheel(wheel_cache_dir, wheel, sources, verbose, index=INDEX_URL,
342345 output = output
343346 ))
344347
348+ elif repo_type == 'hg' :
349+ revision = ''
350+ if release ['url' ].startswith ('hg+' ):
351+ release ['url' ] = release ['url' ][3 :]
352+ if '@' in release ['url' ]:
353+ release ['url' ], revision = release ['url' ].split ('@' )
354+
355+ release ['fetch_type' ] = 'fetchhg'
356+ command = 'nix-prefetch-hg {url} {revision}' .format (
357+ url = release ['url' ],
358+ revision = revision ,
359+ )
360+ return_code , output = cmd (command , verbose != 0 )
361+ if return_code != 0 :
362+ raise click .ClickException ("URL {url} for package {name} is not valid." .format (
363+ url = release ['url' ],
364+ name = wheel ['name' ]
365+ ))
366+ HASH_PREFIX = 'hash is '
367+ REV_PREFIX = 'hg revision is '
368+ for output_line in output .split ('\n ' ):
369+ print (output_line )
370+ output_line = output_line .strip ()
371+ if output_line .startswith (HASH_PREFIX ):
372+ release ['hash_value' ] = output_line [len (HASH_PREFIX ):].strip ()
373+ elif output_line .startswith (REV_PREFIX ):
374+ release ['rev' ] = output_line [len (REV_PREFIX ):].strip ()
375+
376+ if release .get ('hash_value' , None ) is None :
377+ raise click .ClickException ('Could not determine the hash from ouput:\n {output}' .format (
378+ output = output
379+ ))
380+ if release .get ('rev' , None ) is None :
381+ raise click .ClickException ('Could not determine the revision from ouput:\n {output}' .format (
382+ output = output
383+ ))
384+
345385 else :
346386 url = "{}/{}/json" .format (index , wheel ['name' ])
347387 r = requests .get (url , timeout = None )
@@ -366,6 +406,7 @@ def main(verbose, wheels, requirements_files, wheel_cache_dir, index=INDEX_URL):
366406
367407 # get url's from requirements_files
368408 sources = dict ()
409+ repo_types = dict ()
369410 for requirements_file in requirements_files :
370411 with open (requirements_file ) as f :
371412 lines = f .readlines ()
@@ -374,11 +415,15 @@ def main(verbose, wheels, requirements_files, wheel_cache_dir, index=INDEX_URL):
374415 if line .startswith ('-e ' ):
375416 line = line [3 :]
376417 if line .startswith ('http://' ) or line .startswith ('https://' ) or \
377- line .startswith ('git+' ):
418+ line .startswith ('git+' ) or line . startswith ( 'hg+' ) :
378419 try :
379420 url , egg = line .split ('#' )
380421 name = egg .split ('egg=' )[1 ]
381- sources [name ] = url
422+ sources [name ] = url .replace ('-e git+' ,'' ).replace ('-e hg+' ,'' )
423+ if line .startswith ('git+' ):
424+ repo_types [name ] = 'git'
425+ elif line .startswith ('hg+' ):
426+ repo_types [name ] = 'hg'
382427 except :
383428 raise click .ClickException (
384429 "Requirement starting with http:// or https:// "
@@ -416,7 +461,8 @@ def main(verbose, wheels, requirements_files, wheel_cache_dir, index=INDEX_URL):
416461 click .echo ("--------------------------------------------------------------------------" )
417462
418463 metadata .append (
419- process_wheel (wheel_cache_dir , wheel_metadata , sources , verbose , index ))
464+ process_wheel (wheel_cache_dir , wheel_metadata , sources ,
465+ repo_types , verbose , index ))
420466 except Exception as e :
421467 if verbose == 0 :
422468 click .echo (output )
0 commit comments