Skip to content

Errors when parsing singularity definitions with comments before bootstrap line #180

@StopMotionCuber

Description

@StopMotionCuber

Expected Behavior

When parsing a singularity definition with comments before the bootstrap line, the file should be successfully parsed

Actual Behavior

The parsing throws an UnboundLocalError: local variable 'comments' referenced before assignment

Steps to Reproduce

  1. Create a definition file with the following content:
# Minimal Example - This comment line is important for reproduction purposes

Bootstrap: docker
From: ubuntu:16.04
  1. Start a python interpreter in that directory, with spython installed
  2. Execute
from spython.main.parse.parsers import SingularityParser
SingularityParser("minimal.def")

in that directory

Context

  • Operating System: Arch Linux
  • singularity version: not installed
  • spython version: 0.1.15
  • python version: 3.9.7

Failure Logs

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[redacted]/venv/lib/python3.9/site-packages/spython/main/parse/parsers/singularity.py", line 30, in __init__
    super(SingularityParser, self).__init__(filename, load)
  File "[redacted]/venv/lib/python3.9/site-packages/spython/main/parse/parsers/base.py", line 56, in __init__
    self.parse()
  File "[redacted]/venv/lib/python3.9/site-packages/spython/main/parse/parsers/singularity.py", line 41, in parse
    self.load_recipe()
  File "[redacted]/venv/lib/python3.9/site-packages/spython/main/parse/parsers/singularity.py", line 333, in load_recipe
    elif stripped.startswith("#") and stripped not in comments:
UnboundLocalError: local variable 'comments' referenced before assignment

Possible Fix

https://github.com/singularityhub/singularity-cli/blob/master/spython/main/parse/parsers/singularity.py#L318
That comments definition could to be repeated somewhere above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions