@@ -150,105 +150,167 @@ def get_rule_threads(rule_name):
150150# The final output is tabular, we might need to indent subsequent lines correctly.
151151indent = 24
152152
153- # Get a nicely formatted username and hostname
154- username = pwd .getpwuid (os .getuid ())[0 ]
155- hostname = socket .gethostname ()
156- hostname = hostname + ("; " + platform .node () if platform .node () != socket .gethostname () else "" )
157-
158153# Get some info on the platform and OS
159- pltfrm = platform .platform () + "\n " + (" " * indent ) + platform .version ()
160- try :
161- # Not available in all versions, so we need to catch this
162- ld = platform .linux_distribution ()
163- if len (ld ):
164- pltfrm += "\n " + (" " * indent ) + ld
165- del ld
166- except :
167- pass
168- try :
169- # Mac OS version comes back as a nested tuple?!
170- # Need to merge the tuples...
171- def merge_tuple (x , bases = (tuple , list )):
172- for e in x :
173- if type (e ) in bases :
174- for e in merge_tuple (e , bases ):
154+ def info_platform ():
155+ pltfrm = platform .platform () + "\n " + (" " * indent ) + platform .version ()
156+ try :
157+ # Not available in all versions, so we need to catch this
158+ ld = platform .linux_distribution ()
159+ if len (ld ):
160+ pltfrm += "\n " + (" " * indent ) + ld
161+ except :
162+ pass
163+ try :
164+ # Mac OS version comes back as a nested tuple?!
165+ # Need to merge the tuples...
166+ def merge_tuple (x , bases = (tuple , list )):
167+ for e in x :
168+ if type (e ) in bases :
169+ for e in merge_tuple (e , bases ):
170+ yield e
171+ else :
175172 yield e
176- else :
177- yield e
178-
179- mv = " " .join (merge_tuple (platform .mac_ver ()))
180- if not mv .isspace ():
181- pltfrm += "\n " + (" " * indent ) + mv
182- del mv , merge_tuple
183- except :
184- pass
185-
186- # Get the git commit hash of grenepipe, if available.
187- try :
188- process = subprocess .Popen (
189- ["git" , "rev-parse" , "--short" , "HEAD" ], stdout = subprocess .PIPE , stderr = subprocess .PIPE
190- )
191- out , err = process .communicate ()
192- out = out .decode ("ascii" )
193- grenepipe_git_hash = out .strip ()
194- if grenepipe_git_hash :
195- grenepipe_version += "-" + grenepipe_git_hash
196- del process , out , err , grenepipe_git_hash
197- except :
198- pass
173+
174+ mv = " " .join (merge_tuple (platform .mac_ver ()))
175+ if not mv .isspace ():
176+ pltfrm += "\n " + (" " * indent ) + mv
177+ except :
178+ pass
179+ return pltfrm
180+
181+ # Get a nicely formatted hostname
182+ def info_hostname ():
183+ hostname = socket .gethostname ()
184+ hostname = hostname + ("; " + platform .node () if platform .node () != socket .gethostname () else "" )
185+ return hostname
186+
187+ # Get a nicely formatted username
188+ def info_username ():
189+ return pwd .getpwuid (os .getuid ())[0 ]
199190
200191# Get the conda version, if available.
201- try :
202- process = subprocess .Popen (["conda" , "--version" ], stdout = subprocess .PIPE , stderr = subprocess .PIPE )
203- out , err = process .communicate ()
204- out = out .decode ("ascii" )
205- conda_ver = out [out .startswith ("conda" ) and len ("conda" ) :].strip ()
206- del process , out , err
207- if not conda_ver :
208- conda_ver = "n/a"
209- except :
192+ def info_conda_version ():
210193 conda_ver = "n/a"
194+ try :
195+ process = subprocess .Popen (
196+ ["conda" , "--version" ], stdout = subprocess .PIPE , stderr = subprocess .PIPE
197+ )
198+ out , err = process .communicate ()
199+ out = out .decode ("ascii" )
200+ conda_ver = out [out .startswith ("conda" ) and len ("conda" ) :].strip ()
201+ if not conda_ver :
202+ conda_ver = "n/a"
203+ except :
204+ pass
205+ return str (conda_ver )
211206
212207# Same for mamba. This somehow can also give a differing conda version.
213208# Who knows what that means. I'm sick of conda. Just reporting the version here,
214209# and have someone else deal with it.
215- try :
216- process = subprocess .Popen (["mamba" , "--version" ], stdout = subprocess .PIPE , stderr = subprocess .PIPE )
217- out , err = process .communicate ()
218- out = out .decode ("ascii" )
219- mamba_ver = re .findall ("mamba *(.*) *" , out )[0 ]
220- conda_ver_mamba = re .findall ("conda *(.*) *" , out )[0 ]
221- del process , out , err
210+ def info_mamba_version ():
211+ mamba_ver = ""
212+
213+ # Get normal mamba first, for the old mamba version output
214+ try :
215+ process = subprocess .Popen (
216+ ["mamba" , "--version" ], stdout = subprocess .PIPE , stderr = subprocess .PIPE
217+ )
218+ out , err = process .communicate ()
219+ out = out .decode ("ascii" )
220+ mamba_ver = re .findall ("mamba *(.*) *" , out )[0 ]
221+ conda_ver_mamba = re .findall ("conda *(.*) *" , out )[0 ]
222+ if not mamba_ver :
223+ mamba_ver = ""
224+ conda_ver_mamba = ""
225+ except :
226+ mamba_ver = ""
227+ conda_ver_mamba = ""
228+ if conda_ver_mamba and conda_ver_mamba != info_conda_version ():
229+ mamba_ver += ", with conda " + conda_ver_mamba
230+
231+ # If that did not work, try the new mamba version output
232+ if not mamba_ver :
233+ try :
234+ process = subprocess .Popen (
235+ ["mamba" , "--version" ], stdout = subprocess .PIPE , stderr = subprocess .PIPE
236+ )
237+ out , err = process .communicate ()
238+ mamba_ver = str (out .decode ("ascii" )).strip ()
239+ except :
240+ mamba_ver = ""
241+
242+ # Lastly, also check for micromamba, for full info
243+ try :
244+ process = subprocess .Popen (
245+ ["micromamba" , "--version" ], stdout = subprocess .PIPE , stderr = subprocess .PIPE
246+ )
247+ out , err = process .communicate ()
248+ micromamba_ver = str (out .decode ("ascii" )).strip ()
249+ except :
250+ micromamba_ver = ""
251+ if micromamba_ver :
252+ if mamba_ver :
253+ mamba_ver += "\n Micromamba: " + micromamba_ver
254+ else :
255+ mamba_ver = micromamba_ver + " (micromamba)"
256+
257+ # Finaly check: if we did not find any mamba, report n/a
222258 if not mamba_ver :
223259 mamba_ver = "n/a"
224- conda_ver_mamba = ""
225- except :
226- mamba_ver = "n/a"
227- conda_ver_mamba = ""
228- if conda_ver_mamba and conda_ver_mamba != conda_ver :
229- conda_ver += " (conda), " + conda_ver_mamba + " (mamba)"
260+ return str (mamba_ver )
261+
262+ # Get the grenepipe version including git commit hash of grenepipe, if available.
263+ def info_grenepipe_version ():
264+ gpv = grenepipe_version
265+ try :
266+ process = subprocess .Popen (
267+ ["git" , "rev-parse" , "--short" , "HEAD" ], stdout = subprocess .PIPE , stderr = subprocess .PIPE
268+ )
269+ out , err = process .communicate ()
270+ out = out .decode ("ascii" )
271+ grenepipe_git_hash = out .strip ()
272+ if grenepipe_git_hash :
273+ gpv += "-" + grenepipe_git_hash
274+ except :
275+ pass
276+ return str (gpv )
277+
278+ # Get the python version currently executing this script.
279+ # If this differs in sub-instances of snakemake, we have an issue.
280+ def info_python_version ():
281+ return str (sys .version .split (" " )[0 ])
282+
283+ # Get the snakemake version running this script.
284+ def info_snakemake_version ():
285+ return str (snakemake .__version__ )
230286
231287# Get the conda env name, if available.
232288# See https://stackoverflow.com/a/42660674/4184258
233- conda_env = os .environ ["CONDA_DEFAULT_ENV" ] + " (" + os .environ ["CONDA_PREFIX" ] + ")"
234- if conda_env == " ()" :
235- conda_env = "n/a"
289+ def info_conda_env ():
290+ conda_env = os .environ ["CONDA_DEFAULT_ENV" ] + " (" + os .environ ["CONDA_PREFIX" ] + ")"
291+ if conda_env == " ()" :
292+ conda_env = "n/a"
293+ return str (conda_env )
236294
237295# Get nicely wrapped command line
238- cmdline = sys .argv [0 ]
239- for i in range (1 , len (sys .argv )):
240- if sys .argv [i ].startswith ("--" ):
241- cmdline += "\n " + (" " * indent ) + sys .argv [i ]
242- else :
243- cmdline += " " + sys .argv [i ]
296+ def info_command_line ():
297+ cmdline = sys .argv [0 ]
298+ for i in range (1 , len (sys .argv )):
299+ if sys .argv [i ].startswith ("--" ):
300+ cmdline += "\n " + (" " * indent ) + sys .argv [i ]
301+ else :
302+ cmdline += " " + sys .argv [i ]
303+ return cmdline
244304
245305# Get abs paths of all config files
246- cfgfiles = []
247- for cfg in workflow .configfiles :
248- cfgfiles .append (os .path .abspath (cfg ))
249- if resources_file :
250- cfgfiles .append (os .path .abspath (resources_file ))
251- cfgfiles = "\n " .join (cfgfiles )
306+ def info_config_files ():
307+ cfgfiles = []
308+ for cfg in workflow .configfiles :
309+ cfgfiles .append (os .path .abspath (cfg ))
310+ if resources_file :
311+ cfgfiles .append (os .path .abspath (resources_file ))
312+ cfgfiles = "\n " .join (cfgfiles )
313+ return cfgfiles
252314
253315# Main grenepipe header, helping with debugging etc for user issues
254316fix_log_info ("=====================================================================================" )
@@ -260,28 +322,25 @@ fix_log_info(r" \ \__| | _ <| |____ | |\ || |____ | | | | | |
260322fix_log_info (r" \______/|_| \_\_______\/__| \__|\_______\|__| \___\|__| \_______\ " )
261323fix_log_info ("" )
262324fix_log_info (" Date: " + datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" ))
263- fix_log_info (" Platform: " + pltfrm )
264- fix_log_info (" Host: " + hostname )
265- fix_log_info (" User: " + username )
266- fix_log_info (" Conda: " + str ( conda_ver ))
267- fix_log_info (" Mamba: " + str ( mamba_ver ))
268- fix_log_info (" Python: " + str ( sys . version . split ( " " )[ 0 ] ))
269- fix_log_info (" Snakemake: " + str ( snakemake . __version__ ))
270- fix_log_info (" Grenepipe: " + str ( grenepipe_version ))
271- fix_log_info (" Conda env: " + str ( conda_env ))
272- fix_log_info (" Command: " + cmdline )
325+ fix_log_info (" Platform: " + info_platform () )
326+ fix_log_info (" Host: " + info_hostname () )
327+ fix_log_info (" User: " + info_username () )
328+ fix_log_info (" Conda: " + info_conda_version ( ))
329+ fix_log_info (" Mamba: " + info_mamba_version ( ))
330+ fix_log_info (" Python: " + info_python_version ( ))
331+ fix_log_info (" Snakemake: " + info_snakemake_version ( ))
332+ fix_log_info (" Grenepipe: " + info_grenepipe_version ( ))
333+ fix_log_info (" Conda env: " + info_conda_env ( ))
334+ fix_log_info (" Command: " + info_command_line () )
273335fix_log_info ("" )
274336fix_log_info (" Base directory: " + workflow .basedir )
275337fix_log_info (" Working directory: " + os .getcwd ())
276- fix_log_info (" Config file(s): " + cfgfiles )
338+ fix_log_info (" Config file(s): " + info_config_files () )
277339fix_log_info (" Samples: " + get_sample_units_print ())
278340fix_log_info ("" )
279341fix_log_info ("=====================================================================================" )
280342fix_log_info ("" )
281343
282344
283- # No need to have these output vars available in the rest of the snakefiles
284- del indent
285- del pltfrm , hostname , username
286- del conda_ver , conda_env
287- del cmdline , cfgfiles
345+ # No need to have these vars available in the rest of the snakefiles
346+ del indent
0 commit comments