Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local variable 'docker_image_name' referenced before assignment #2390

Closed
anoronh4 opened this issue Aug 7, 2023 · 1 comment
Closed

local variable 'docker_image_name' referenced before assignment #2390

anoronh4 opened this issue Aug 7, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@anoronh4
Copy link
Contributor

anoronh4 commented Aug 7, 2023

Description of the bug

When i try to create a new module using nf-core tools i get an error. It doesn't happen when i try to create modules with other names such as bcftools/fakemodule or cell/phone. Looks like it can find a docker image but not a singularity image, and the evaluation of the following line:

common_keys = list(all_docker.keys() & all_singularity.keys())

leads to a set size of 0. so a few lines down the loop is never executed because the set it's looping on is empty and docker_image_name is never instantiated and singularity_image is not updated (instantiated as None earlier in the function).

I can see that the csvtk singularity image can't be found because i run the following commands in python:

package = "csvtk"
version = "0.26.0"
biocontainers_api_url = f"https://api.biocontainers.pro/ga4gh/trs/v2/tools/{package}/versions/{package}-{version}"
response = requests.get(biocontainers_api_url)
images = response.json()["images"]
[ i['image_type'] for i in images]
# ['Conda', 'Docker']

(others show ['Conda', 'Docker', 'Singularity']

Command used and terminal output

$ nf-core modules create -d . csvtk/join

                                          ,--./,-.
          ___     __   __   __   ___     /,-._.--~\
    |\ | |__  __ /  ` /  \ |__) |__         }  {
    | \| |       \__, \__/ |  \ |___     \`-._,-`-,
                                          `._,._,'

    nf-core/tools version 2.9 - https://nf-co.re


INFO     Repository type: modules                                                                                       
INFO     Press enter to use default values (shown in brackets) or type your own responses. ctrl+click underlined text to
         open links.                                                                                                    
INFO     Using Bioconda package: 'bioconda::csvtk=0.26.0'                                                               
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/noronhaa/anaconda3/envs/nf-core/bin/nf-core:8 in <module>                                  │
│                                                                                                  │
│   5 from nf_core.__main__ import run_nf_core                                                     │
│   6 if __name__ == '__main__':                                                                   │
│   7 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                         │
│ ❱ 8 │   sys.exit(run_nf_core())                                                                  │
│   9                                                                                              │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/nf_core/__main__.py:110 in    │
│ run_nf_core                                                                                      │
│                                                                                                  │
│    107 │   │   │   log.debug(f"Could not check latest version: {e}")                             │
│    108 │   │   stderr.print("\n")                                                                │
│    109 │   # Launch the click cli                                                                │
│ ❱  110 │   nf_core_cli(auto_envvar_prefix="NFCORE")                                              │
│    111                                                                                           │
│    112                                                                                           │
│    113 @click.group(context_settings=dict(help_option_names=["-h", "--help"]))                   │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/click/core.py:1130 in         │
│ __call__                                                                                         │
│                                                                                                  │
│   1127 │                                                                                         │
│   1128 │   def __call__(self, *args: t.Any, **kwargs: t.Any) -> t.Any:                           │
│   1129 │   │   """Alias for :meth:`main`."""                                                     │
│ ❱ 1130 │   │   return self.main(*args, **kwargs)                                                 │
│   1131                                                                                           │
│   1132                                                                                           │
│   1133 class Command(BaseCommand):                                                               │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/rich_click/rich_group.py:21   │
│ in main                                                                                          │
│                                                                                                  │
│   18 │                                                                                           │
│   19 │   def main(self, *args, standalone_mode: bool = True, **kwargs):                          │
│   20 │   │   try:                                                                                │
│ ❱ 21 │   │   │   rv = super().main(*args, standalone_mode=False, **kwargs)                       │
│   22 │   │   │   if not standalone_mode:                                                         │
│   23 │   │   │   │   return rv                                                                   │
│   24 │   │   except click.ClickException as e:                                                   │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/click/core.py:1055 in main    │
│                                                                                                  │
│   1052 │   │   try:                                                                              │
│   1053 │   │   │   try:                                                                          │
│   1054 │   │   │   │   with self.make_context(prog_name, args, **extra) as ctx:                  │
│ ❱ 1055 │   │   │   │   │   rv = self.invoke(ctx)                                                 │
│   1056 │   │   │   │   │   if not standalone_mode:                                               │
│   1057 │   │   │   │   │   │   return rv                                                         │
│   1058 │   │   │   │   │   # it's not safe to `ctx.exit(rv)` here!                               │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/click/core.py:1657 in invoke  │
│                                                                                                  │
│   1654 │   │   │   │   super().invoke(ctx)                                                       │
│   1655 │   │   │   │   sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)                    │
│   1656 │   │   │   │   with sub_ctx:                                                             │
│ ❱ 1657 │   │   │   │   │   return _process_result(sub_ctx.command.invoke(sub_ctx))               │
│   1658 │   │                                                                                     │
│   1659 │   │   # In chain mode we create the contexts step by step, but after the                │
│   1660 │   │   # base command has been invoked.  Because at that point we do not                 │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/click/core.py:1657 in invoke  │
│                                                                                                  │
│   1654 │   │   │   │   super().invoke(ctx)                                                       │
│   1655 │   │   │   │   sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)                    │
│   1656 │   │   │   │   with sub_ctx:                                                             │
│ ❱ 1657 │   │   │   │   │   return _process_result(sub_ctx.command.invoke(sub_ctx))               │
│   1658 │   │                                                                                     │
│   1659 │   │   # In chain mode we create the contexts step by step, but after the                │
│   1660 │   │   # base command has been invoked.  Because at that point we do not                 │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/click/core.py:1404 in invoke  │
│                                                                                                  │
│   1401 │   │   │   echo(style(message, fg="red"), err=True)                                      │
│   1402 │   │                                                                                     │
│   1403 │   │   if self.callback is not None:                                                     │
│ ❱ 1404 │   │   │   return ctx.invoke(self.callback, **ctx.params)                                │
│   1405 │                                                                                         │
│   1406 │   def shell_complete(self, ctx: Context, incomplete: str) -> t.List["CompletionItem"]:  │
│   1407 │   │   """Return a list of completions for the incomplete value. Looks                   │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/click/core.py:760 in invoke   │
│                                                                                                  │
│    757 │   │                                                                                     │
│    758 │   │   with augment_usage_errors(__self):                                                │
│    759 │   │   │   with ctx:                                                                     │
│ ❱  760 │   │   │   │   return __callback(*args, **kwargs)                                        │
│    761 │                                                                                         │
│    762 │   def forward(                                                                          │
│    763 │   │   __self, __cmd: "Command", *args: t.Any, **kwargs: t.Any  # noqa: B902             │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/click/decorators.py:26 in     │
│ new_func                                                                                         │
│                                                                                                  │
│    23 │   """                                                                                    │
│    24 │                                                                                          │
│    25 │   def new_func(*args, **kwargs):  # type: ignore                                         │
│ ❱  26 │   │   return f(get_current_context(), *args, **kwargs)                                   │
│    27 │                                                                                          │
│    28 │   return update_wrapper(t.cast(F, new_func), f)                                          │
│    29                                                                                            │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/nf_core/__main__.py:800 in    │
│ create_module                                                                                    │
│                                                                                                  │
│    797 │   │   module_create = ModuleCreate(                                                     │
│    798 │   │   │   dir, tool, author, label, has_meta, force, conda_name, conda_package_version  │
│    799 │   │   )                                                                                 │
│ ❱  800 │   │   module_create.create()                                                            │
│    801 │   except UserWarning as e:                                                              │
│    802 │   │   log.critical(e)                                                                   │
│    803 │   │   sys.exit(1)                                                                       │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/nf_core/components/create.py: │
│ 139 in create                                                                                    │
│                                                                                                  │
│   136 │   │                                                                                      │
│   137 │   │   if self.component_type == "modules":                                               │
│   138 │   │   │   # Try to find a bioconda package for 'component'                               │
│ ❱ 139 │   │   │   self._get_bioconda_tool()                                                      │
│   140 │   │                                                                                      │
│   141 │   │   # Prompt for GitHub username                                                       │
│   142 │   │   self._get_username()                                                               │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/nf_core/components/create.py: │
│ 227 in _get_bioconda_tool                                                                        │
│                                                                                                  │
│   224 │   │   │   │   │   │   self.tool_conda_name, version                                      │
│   225 │   │   │   │   │   )                                                                      │
│   226 │   │   │   │   else:                                                                      │
│ ❱ 227 │   │   │   │   │   self.docker_container, self.singularity_container = nf_core.utils.ge   │
│   228 │   │   │   │   │   │   self.component, version                                            │
│   229 │   │   │   │   │   )                                                                      │
│   230 │   │   │   │   log.info(f"Using Docker container: '{self.docker_container}'")             │
│                                                                                                  │
│ /home/noronhaa/anaconda3/envs/nf-core/lib/python3.10/site-packages/nf_core/utils.py:744 in       │
│ get_biocontainer_tag                                                                             │
│                                                                                                  │
│    741 │   │   │   │   │   │   singularity_image = all_singularity[k]["image"]                   │
│    742 │   │   │   │   │   │   current_date = date                                               │
│    743 │   │   │   │   │   │   docker_image_name = docker_image["image_name"].lstrip("quay.io/"  │
│ ❱  744 │   │   │   │   return docker_image_name, singularity_image["image_name"]                 │
│    745 │   │   │   except TypeError:                                                             │
│    746 │   │   │   │   raise LookupError(f"Could not find docker or singularity container for {  │
│    747 │   │   elif response.status_code != 404:                                                 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
UnboundLocalError: local variable 'docker_image_name' referenced before assignment

System information

CentOSLinux, Python 3.10, nf-core version 2.9

@anoronh4 anoronh4 added the bug Something isn't working label Aug 7, 2023
@mirpedrol
Copy link
Member

Hello @anoronh4, thanks for the detailed issue. This was fixed in the dev version by #2374
You can install the dev version of tools following these instructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants