georgiesamaha / configBuilder-nf

Nextflow config builder scripts for supported HPC infrastructures.
7 stars 1 forks source link

Fix AttributeError in create_custom.py #14

Closed georgiesamaha closed 11 months ago

georgiesamaha commented 11 months ago

While running the configBuilder, encountered an AttributeError when the tool attempted to access the get() method on the module_results variable. Error trace indicated that module_results was treated as a boolean instead of a dictionary. Executed with:

python3 configBuilder

When no module detected, throws:

Traceback (most recent call last):
  File "/home/james/git/jfy133/configBuilder-nf/configBuilder", line 39, in <module>
    custom_pipeline()
  File "/home/james/git/jfy133/configBuilder-nf/modules/create_custom.py", line 48, in custom_pipeline
    write_config(executor=scheduler_name, module_results=module_results)
  File "/home/james/git/jfy133/configBuilder-nf/modules/write_config.py", line 20, in write_config
    if module_results.get("singularity"):
       ^^^^^^^^^^^^^^^^^^
AttributeError: 'bool' object has no attribute 'get'

To fix, I've initialised module_results=None variable in the custom_pipeline() function in create_custom.py to prevent the AttributeError.

@jfy133 could you test this resolves your issue?

jfy133 commented 11 months ago

I'm still getting this unfortunately :\

$ python3 configBuilder
/home/james/git/jfy133/configBuilder-nf/configBuilder:12: SyntaxWarning: invalid escape sequence '\|'
  print(f"{Fore.CYAN}| |   / _ \| '_ \| |_| |/ _` |  _ \| | | | | |/ _` |/ _ \ '__|")
/home/james/git/jfy133/configBuilder-nf/configBuilder:14: SyntaxWarning: invalid escape sequence '\_'
  print(f"{Fore.CYAN} \____\___/|_| |_|_| |_|\__, |____/ \__,_|_|_|\__,_|\___|_|   ")
  ____             __ _       ____        _ _     _           
 / ___|___  _ __  / _(_) __ _| __ ) _   _(_) | __| | ___ _ __ 
| |   / _ \| '_ \| |_| |/ _` |  _ \| | | | | |/ _` |/ _ \ '__|
| |__| (_) | | | |  _| | (_| | |_) | |_| | | | (_| |  __/ |   
 \____\___/|_| |_|_| |_|\__, |____/ \__,_|_|_|\__,_|\___|_|   
                        |___/                                 

This tool helps you to build a custom Nextflow config file for your HPC 
based on your specified job scheduler and resources. Follow the prompts 
to specify your settings.

[?] What type of configuration file would you like to build?: custom
 > custom
   nf-core institutional

[?] What type of execution environment are you working in?: hpc
 > hpc
   local
   cloud

No modules system detected.
You selected: hpc
[?] What do you want your custom config file to be called?: custom_nextflow.config
Traceback (most recent call last):
  File "/home/james/git/jfy133/configBuilder-nf/configBuilder", line 34, in <module>
    custom_pipeline()
  File "/home/james/git/jfy133/configBuilder-nf/modules/create_custom.py", line 49, in custom_pipeline
    write_config(executor=scheduler_name, module_results=module_results)
  File "/home/james/git/jfy133/configBuilder-nf/modules/write_config.py", line 20, in write_config
    if module_results.get("singularity"):
       ^^^^^^^^^^^^^^^^^^
AttributeError: 'bool' object has no attribute 'get'
jfy133 commented 11 months ago

@georgiesamaha your inference is right, just in the wrong place

https://github.com/georgiesamaha/configBuilder-nf/blob/9506bf941e27d06e014bc3361f36a2a43cbc654c/modules/create_hpc_env.py#L68-L70

The Booelan is passed out here as false. When I replaced it with e.g. return {"not_detected": True} then ti stopped erroring

georgiesamaha commented 11 months ago

@georgiesamaha your inference is right, just in the wrong place

https://github.com/georgiesamaha/configBuilder-nf/blob/9506bf941e27d06e014bc3361f36a2a43cbc654c/modules/create_hpc_env.py#L68-L70

The Booelan is passed out here as false. When I replaced it with e.g. return {"not_detected": True} then ti stopped erroring

Oopsies! Ok have implemented your fix. Sorry about that!

georgiesamaha commented 11 months ago

Definitely, I don't want to slow you down :) Plus this is an us thing not a me thing!

jfy133 commented 11 months ago

Noted!