1- '''
2- Download grids + convert them to pineappl format
3- '''
1+ """Download grids + convert them to pineappl format."""
42
5- from . import interface
6- from .. import table
7- import requests
8- import urllib .request
3+ import os
94import shutil
10- import tarfile
115import subprocess
12- import os
6+ import tarfile
7+ import urllib .request
8+
139import pineappl
10+ import requests
11+
12+ from .. import table
13+ from . import interface
1414
1515PLOUGHSHARE_LINK_FILENAME = "ploughshare_link.txt"
1616GRIDS_PROCESSOR = "process_grids.sh"
1717GRIDS_TMP = "grids"
1818
1919
2020class Plough (interface .External ):
21+ """Interface provider."""
2122
2223 def __init__ (self , pinecard , theorycard , * args , ** kwargs ):
2324 super ().__init__ (pinecard , theorycard , * args , ** kwargs )
24- self .ps_link = self .source / PLOUGHSHARE_LINK_FILENAME
25+ self .ps_link = self .source / PLOUGHSHARE_LINK_FILENAME
2526 with open (self .ps_link ) as ps_link :
2627 self .link = ps_link .readline ()
27-
28- self .filename = self .link .rsplit ('/' )[- 1 ]
29- self .dir_name = self .filename .rsplit ('.' , 1 )[0 ]
30- self .tarball = self .dest / self .filename
31- self .processor = self .source / GRIDS_PROCESSOR
28+
29+ self .filename = self .link .rsplit ("/" )[- 1 ]
30+ self .dir_name = self .filename .rsplit ("." , 1 )[0 ]
31+ self .tarball = self .dest / self .filename
32+ self .processor = self .source / GRIDS_PROCESSOR
3233 self .run ()
3334 self .generate_pineappl ()
3435 self .timestamp = 0
35-
36+
3637 def run (self ):
37- '''
38- Download and extract the .tgz file
39- '''
38+ """Download and extract the .tgz file."""
4039 print ("Downloading from ploughshare..." )
4140 self .download_to_dest ()
4241 print (f"Grids successfully downloaded to { self .tarball } " )
@@ -45,12 +44,15 @@ def run(self):
4544 print (f"Grids successfully extracted to { self .dir_name } " )
4645
4746 def results (self ):
47+ """Results are collected and compared at the pineappl (script) level."""
4848 pass
4949
5050 def collect_versions (self ):
51+ """No additional programs involved."""
5152 return {}
52-
53+
5354 def generate_pineappl (self ):
55+ """Converts donwloaded grids into pineappl format."""
5456 print ("Grid conversion started..." )
5557 # the grids are converted and processed here
5658 os .environ ["PS_DIR" ] = str (self .grids_dir )
@@ -59,23 +61,21 @@ def generate_pineappl(self):
5961 if os .access (self .processor , os .X_OK ):
6062 shutil .copy2 (self .processor , self .dest )
6163 subprocess .run ("./process_grids.sh" , cwd = self .dest , check = True )
62- (self .dest / "process_grids.sh" ).unlink ()
64+ (self .dest / "process_grids.sh" ).unlink ()
6365 else :
64- raise ValueError (f"Grid conversion file present but not executable: { self .processor } " )
66+ raise ValueError (
67+ f"Grid conversion file present but not executable: { self .processor } "
68+ )
6569 self .grids = []
6670 for g in self .dest .glob ("*.pineappl.lz4" ):
6771 self .grids .append (g )
68-
72+
6973 def download_to_dest (self ):
70- '''
71- Download the file and move it to the output folder
72- '''
73- urllib .request .urlretrieve (self .link , self .dest / self .filename )
74+ """Download the file and move it to the output folder."""
75+ urllib .request .urlretrieve (self .link , self .dest / self .filename )
7476
7577 def extract_tarball (self ):
76- '''
77- extract the contents
78- '''
78+ """Extract the contents."""
7979 with tarfile .open (self .tarball , "r:*" ) as tf :
8080 tf .extractall (self .dest )
81- self .grids_dir = self .dest / self .dir_name / GRIDS_TMP
81+ self .grids_dir = self .dest / self .dir_name / GRIDS_TMP
0 commit comments