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

Fix pydot regression #668

Merged
merged 4 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Change Log

## [2.37.1](https://github.com/nerdvegas/rez/tree/2.37.1) (2019-07-19)
[Full Changelog](https://github.com/nerdvegas/rez/compare/2.37.0...2.37.1)

**Notes**

This fixes a regression introduced in `2.34.0`, which causes `rez-context -g` to
fail. The pydot vendor package was updated, and the newer version includes a
breaking change. Where `pydot.graph_from_dot_data` used to return a single graph
object, it now returns a list of graph objects.

**Merged pull requests:**

- Fix pydot regression [\#XXX](https://github.com/nerdvegas/rez/pull/XXX) ([nerdvegas](https://github.com/nerdvegas))

## [2.37.0](https://github.com/nerdvegas/rez/tree/2.37.0) (2019-07-19)
[Full Changelog](https://github.com/nerdvegas/rez/compare/2.36.2...2.37.0)

Expand Down
7 changes: 4 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Here is an example changelog entry:

**Notes**

Fixed error in foo rex command on Windows.
Describe the fixes the PR addresses here. It's ok if this is a summary of a longer
description found in the PR itself, in fact that should be common.

**Backwards Compatibility Issues**

Expand All @@ -49,11 +50,11 @@ reason.

**Merged pull requests:**

- Fix foo command [\#101](https://github.com/nerdvegas/rez/pull/101) ([jbloggs](https://github.com/jbloggs))
- PR_TITLE_HERE [\#XXX](https://github.com/nerdvegas/rez/pull/XXX) ([USER](https://github.com/USER))

**Closed issues:**

- rex foo command broken [\#102](https://github.com/nerdvegas/rez/issues/102)
- ISSUE_TITLE_HERE [\#YYY](https://github.com/nerdvegas/rez/issues/YYY)
```

Please include the relevant issues that your PR closes, matching the syntax shown above. When the PR is merged to master, the PR info will be added to the same changelog entry by the maintainer. Don't be too concerned with the date and 'full changelog' line, this will also be patched by the maintainer.
2 changes: 1 addition & 1 deletion src/rez/utils/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


# Update this value to version up Rez. Do not place anything else in this file.
_rez_version = "2.37.0"
_rez_version = "2.37.1"

try:
from rez.vendor.version.version import Version
Expand Down
37 changes: 35 additions & 2 deletions src/rez/utils/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,48 @@ def save_graph(graph_str, dest_file, fmt=None, image_ratio=None):
Returns:
String representing format that was written, such as 'png'.
"""
g = pydot.graph_from_dot_data(graph_str)

# Disconnected edges can result in multiple graphs. We should never see
# this - it's a bug in graph generation if we do.
#
graphs = pydot.graph_from_dot_data(graph_str)

if not graphs:
raise RuntimeError("No graph generated")

if len(graphs) > 1:
path, ext = os.path.splitext(dest_file)
dest_files = []

for i, g in enumerate(graphs):
try:
dest_file_ = "%s.%d%s" % (path, i + 1, ext)
save_graph_object(g, dest_file_, fmt, image_ratio)
dest_files.append(dest_file_)
except:
pass

raise RuntimeError(
"More than one graph was generated; this probably indicates a bug "
"in graph generation. Graphs were written to %r" % dest_files
)

# write the graph
return save_graph_object(graphs[0], dest_file, fmt, image_ratio)


def save_graph_object(g, dest_file, fmt=None, image_ratio=None):
"""Like `save_graph`, but takes a pydot Dot object.
"""

# determine the dest format
if fmt is None:
fmt = os.path.splitext(dest_file)[1].lower().strip('.') or "png"

if hasattr(g, "write_" + fmt):
write_fn = getattr(g, "write_" + fmt)
else:
raise Exception("Unsupported graph format: '%s'" % fmt)
raise RuntimeError("Unsupported graph format: '%s'" % fmt)

if image_ratio:
g.set_ratio(str(image_ratio))
Expand Down