1616
1717
1818class Plough (interface .External ):
19- """Interface provider ."""
19+ """Interface to download grids directly from ploughshare ."""
2020
2121 def __init__ (self , pinecard , theorycard , * args , ** kwargs ):
22- super ().__init__ (pinecard , theorycard , * args , ** kwargs )
22+ super ().__init__ (
23+ pinecard ,
24+ theorycard ,
25+ * args ,
26+ print_comparison = False ,
27+ postrun_without_grids = True ,
28+ ** kwargs ,
29+ )
2330 self .ps_link = self .source / PLOUGHSHARE_LINK_FILENAME
2431 self .link = self .ps_link .read_text ()
2532
2633 self .filename = self .link .rsplit ("/" )[- 1 ]
2734 self .dir_name = self .filename .rsplit ("." , 1 )[0 ]
2835 self .tarball = self .dest / self .filename
29- self ._print_comparison = False
30- self ._run_without_grids = True
3136
3237 def run (self ):
3338 """Download and extract the .tgz file."""
3439 print ("Downloading from ploughshare..." )
35- try :
36- self .download_to_dest ()
37- if self .tarball .exists ():
38- print (f"Grids successfully downloaded to { self .tarball } " )
39- else :
40- raise FileNotFoundError (
41- f"{ self .tarball } not found but the download didn't seem to fail?"
42- )
43- except Exception as e :
44- raise FileNotFoundError (f"{ self .tarball } could not be downloaded!" ) from e
40+ self .download_to_dest ()
4541 print ("Extracting files..." )
4642 self .extract_tarball ()
4743 print (f"Grids successfully extracted to { self .dest } " )
4844
4945 def results (self ):
50- """Results are collected and compared at the pineappl (script) level ."""
46+ """Do nothing ."""
5147 pass
5248
5349 def collect_versions (self ):
@@ -60,16 +56,26 @@ def generate_pineappl(self):
6056
6157 def download_to_dest (self ):
6258 """Download the file to the output folder."""
63- urllib .request .urlretrieve (self .link , self .dest / self .filename )
59+ try :
60+ urllib .request .urlretrieve (self .link , self .dest / self .filename )
61+ if self .tarball .exists ():
62+ print (f"Grids successfully downloaded to { self .tarball } " )
63+ else :
64+ raise FileNotFoundError (
65+ f"{ self .tarball } not found but the download didn't seem to fail?"
66+ )
67+ except Exception as e :
68+ raise FileNotFoundError (f"{ self .tarball } could not be downloaded!" ) from e
6469
6570 def extract_tarball (self ):
6671 """Extract the contents."""
6772 with tarfile .open (self .tarball , "r:*" ) as tf :
6873 tf .extractall (self .dest )
6974 self .grids_dir = self .dest / self .dir_name / GRIDS_TMP
7075 grids_list = sorted (os .listdir (self .grids_dir ))
71- for i , grid in enumerate (grids_list ):
72- extension = grid .split ("." , 2 )[2 ]
73- os .rename (self .grids_dir / grid , self .dest / f"grid_{ i } .{ extension } " )
76+ for grid in grids_list :
77+ grid_num , extension = grid .split ("." , 2 )[1 :]
78+ grid_num = grid_num [- 3 :]
79+ os .rename (self .grids_dir / grid , self .dest / f"grid_{ grid_num } .{ extension } " )
7480 shutil .rmtree (self .dest / self .dir_name )
7581 self .tarball .unlink ()
0 commit comments