AttributeError on parse error for layer.yaml with req.txt version of ruamel.yaml #233

Open
johnsca opened this Issue Jul 12, 2016 · 0 comments

Comments

Projects
None yet
1 participant
Member

johnsca commented Jul 12, 2016

Checklist

  • Confirmed this is an issue with charm-tools, not charmstore-client
  • Provide versions of tools used
  • Described the feature or ways to replicate the issue

What version am I running?

I ran the following command: charm version and got the following ouput:

charm error
charm-tools 2.1.3

I am using: Ubuntu trusty

Issue/Feature

I expect/expected the following

With the version of ruamel.yaml that is pinned in requirements.txt (0.10.23) if there is a YAML syntax error in layer.yaml the error handler designed to catch it instead fails with an AttributeError due to ruamel.yaml.parser having been temporarily renamed to ruamel.yaml.parser_. This has been resolved in newer versions of ruamel.yaml.

Additionally, we don't have ruamel.yaml pinned in setup.py so most people won't hit this. However, #229 shows that breaking changes get introduced to ruamel.yaml frequently enough that we should pin it.

I propose that we update requirements.txt to the current, working version (0.11.14) and pin it to that in setup.py. We should probably also report the parsing error in a more friendly way, although the current error does provide a sufficiently useful message (if not with the prettiest presentation).

What I got

[ubuntu@murdoch:~/layers/ghost] $ pip freeze | grep yaml
ruamel.yaml==0.10.23
[ubuntu@murdoch:~/layers/ghost] $ cat layer.yaml
includes: ['layer:basic', 'layer:nodejs', 'layer:nginx', 'interface:mysql']
foo
repo: https://github.com/battlemidget/charm-layer-ghost
[ubuntu@murdoch:~/layers/ghost] $ charm build
build: Composing into /home/ubuntu
build: Destination charm directory: /home/ubuntu/builds/ghost
Traceback (most recent call last):
  File "/usr/local/bin/charm-build", line 9, in <module>
    load_entry_point('charm-tools==2.1.3', 'console_scripts', 'charm-build')()
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 675, in main
    build()
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 517, in __call__
    self.validate()
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 473, in validate
    self._validate_charm_repo()
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 502, in _validate_charm_repo
    if 'repo' not in self.top_layer.config:
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 136, in top_layer
    self._top_layer = Layer(self.charm, self.deps).fetch()
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 99, in fetch
    self._name = self.config.name
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 43, in config
    self._config.configure(self.config_file)
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/config.py", line 59, in configure
    except yaml.parser.ParserError:
AttributeError: 'module' object has no attribute 'parser'

[ubuntu@murdoch:~/layers/ghost] $ sudo pip install -U ruamel.yaml
Collecting ruamel.yaml
  Downloading ruamel.yaml-0.11.14-cp27-cp27mu-manylinux1_x86_64.whl (503kB)
    100% |################################| 512kB 2.4MB/s 
Requirement already up-to-date: ruamel.ordereddict in /usr/lib/python2.7/dist-packages (from ruamel.yaml)
Installing collected packages: ruamel.yaml
  Found existing installation: ruamel.yaml 0.10.23
    Uninstalling ruamel.yaml-0.10.23:
      Successfully uninstalled ruamel.yaml-0.10.23
Successfully installed ruamel.yaml-0.11.14
[ubuntu@murdoch:~/layers/ghost] $ charm build
build: Composing into /home/ubuntu
build: Destination charm directory: /home/ubuntu/builds/ghost
Traceback (most recent call last):
  File "/usr/local/bin/charm-build", line 9, in <module>
    load_entry_point('charm-tools==2.1.3', 'console_scripts', 'charm-build')()
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 675, in main
    build()
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 517, in __call__
    self.validate()
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 473, in validate
    self._validate_charm_repo()
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 502, in _validate_charm_repo
    if 'repo' not in self.top_layer.config:
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 136, in top_layer
    self._top_layer = Layer(self.charm, self.deps).fetch()
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 99, in fetch
    self._name = self.config.name
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/builder.py", line 43, in config
    self._config.configure(self.config_file)
  File "/usr/local/lib/python2.7/dist-packages/charmtools/build/config.py", line 57, in configure
    data = yaml.load(config_file.open())
  File "/usr/local/lib/python2.7/dist-packages/ruamel/yaml/main.py", line 75, in load
    return loader.get_single_data()
  File "/usr/local/lib/python2.7/dist-packages/ruamel/yaml/constructor.py", line 60, in get_single_data
    node = self.get_single_node()
  File "/usr/local/lib/python2.7/dist-packages/ruamel/yaml/composer.py", line 53, in get_single_node
    document = self.compose_document()
  File "/usr/local/lib/python2.7/dist-packages/ruamel/yaml/composer.py", line 73, in compose_document
    node = self.compose_node(None, None)
  File "/usr/local/lib/python2.7/dist-packages/ruamel/yaml/composer.py", line 104, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/local/lib/python2.7/dist-packages/ruamel/yaml/composer.py", line 156, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/usr/local/lib/python2.7/dist-packages/ruamel/yaml/parser.py", line 116, in check_event
    self.current_event = self.state()
  File "/usr/local/lib/python2.7/dist-packages/ruamel/yaml/parser.py", line 491, in parse_block_mapping_key
    if self.check_token(KeyToken):
  File "/usr/local/lib/python2.7/dist-packages/ruamel/yaml/scanner.py", line 131, in check_token
    while self.need_more_tokens():
  File "/usr/local/lib/python2.7/dist-packages/ruamel/yaml/scanner.py", line 165, in need_more_tokens
    self.stale_possible_simple_keys()
  File "/usr/local/lib/python2.7/dist-packages/ruamel/yaml/scanner.py", line 309, in stale_possible_simple_keys
    "could not find expected ':'", self.get_mark())
ruamel.yaml.scanner.ScannerError: while scanning a simple key
  in "/home/ubuntu/layers/ghost/layer.yaml", line 2, column 1
could not find expected ':'
  in "/home/ubuntu/layers/ghost/layer.yaml", line 3, column 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment