Skip to content

Commit

Permalink
adapt version() for development version format in Graphviz 2.44.2
Browse files Browse the repository at this point in the history
  • Loading branch information
xflr6 committed Oct 7, 2020
1 parent 8a4401d commit 374e6b8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
Version 0.14.2 (in development)
-------------------------------

Adapt `graphviz.version()` to support the Graphviz Release version entry format
introduced with `2.44.2` (`version()` is needed to run the tests).

Drop Python 3.5 support.


Expand Down
20 changes: 18 additions & 2 deletions graphviz/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,33 @@ def version():
graphviz.ExecutableNotFound: If the Graphviz executable is not found.
subprocess.CalledProcessError: If the exit status is non-zero.
RuntimmeError: If the output cannot be parsed into a version number.
Note:
Ignores the ``~dev.<YYYYmmdd.HHMM>`` portion of development versions.
See also Graphviz Release version entry format:
https://gitlab.com/graphviz/graphviz/-/blob/f94e91ba819cef51a4b9dcb2d76153684d06a913/gen_version.py#L17-20
"""
cmd = ['dot', '-V']
out, _ = run(cmd, check=True, encoding='ascii',
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)

ma = re.search(r'graphviz version (\d+\.\d+(?:\.\d+){,2})', out)
ma = re.search(r'graphviz version'
r' '
r'(\d+)\.(\d+)'
r'(?:\.(\d+)'
r'(?:'
r'~dev\.\d{8}\.\d{4}'
r'|'
r'\.(\d+)'
r')?'
r')?'
r' ', out)
if ma is None:
raise RuntimeError('cannot parse %r output: %r' % (cmd, out))

return tuple(int(d) for d in ma.group(1).split('.'))
return tuple(int(d) for d in ma.groups() if d is not None)


def view(filepath, quiet=False):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ def test_version_parsefail_mocked(mocker, Popen): # noqa: N803
(b'dot - graphviz version 1.2.3 (mocked)', (1, 2, 3)),
(b'dot - graphviz version 2.43.20190912.0211 (20190912.0211)\n', (2, 43, 20190912, 211)),
(b'dot - graphviz version 2.44.2~dev.20200927.0217 (20200927.0217)\n', (2, 44, 2)),
(b'dot - graphviz version 2.44.1 (mocked)\n', (2, 44, 1)),
(b'dot - graphviz version 2.44.2~dev.20200704.1652 (mocked)\n', (2, 44, 2)),
])
def test_version_mocked(mocker, Popen, stdout, expected): # noqa: N803
proc = Popen.return_value
Expand Down

0 comments on commit 374e6b8

Please sign in to comment.