Closed fnordahl closed 1 year ago
The code in charmcraft 2.0 looks like this:
output = self._execute("charm version").strip() _, tools_version = output.split("\n")
And our current compatibility code look like this: https://github.com/juju/charm-tools/blob/e1c7ee0b994e12660257e4021bef487d6dbf01a9/charmtools/version.py#L70-L75
Due to charmcraft's use of strip as opposed to rstrip, this does not work.
Example:
>>> s = subprocess.run(["/bin/bash", "-c", "charm version"], check=True, capture_output=True, universal_newlines=True) >>> s CompletedProcess(args=['/bin/bash', '-c', 'charm version'], returncode=0, stdout='\ncharm-tools 3.0.0+snap-661+git-1-b7025b2\n', stderr='') >>> s.stdout.strip() 'charm-tools 3.0.0+snap-661+git-1-b7025b2'
Now if we fudge the output by adding something on the first line:
>>> s = subprocess.run(["/bin/bash", "-c", "charm version"], check=True, capture_output=True, universal_newlines=True) >>> s CompletedProcess(args=['/bin/bash', '-c', 'charm version'], returncode=0, stdout='-\ncharm-tools 3.0.0+snap-x1+git-3-e1c7ee0\n', stderr='') >>> s.stdout.strip() '-\ncharm-tools 3.0.0+snap-x1+git-3-e1c7ee0' >>> _, tools_version = s.stdout.strip().split('\n') >>> tools_version 'charm-tools 3.0.0+snap-x1+git-3-e1c7ee0'
The code in charmcraft 2.0 looks like this:
And our current compatibility code look like this: https://github.com/juju/charm-tools/blob/e1c7ee0b994e12660257e4021bef487d6dbf01a9/charmtools/version.py#L70-L75
Due to charmcraft's use of strip as opposed to rstrip, this does not work.
Example:
Now if we fudge the output by adding something on the first line: