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

Potential fix to the tooltip with special characters bug #1203

Merged
merged 25 commits into from
Jun 11, 2024

Conversation

anushkrishnav
Copy link
Contributor

@anushkrishnav anushkrishnav commented May 30, 2024

Fixes #750

Updated the fn attr_map_to_string function
I can add a separate function to handle the escape values if needed

fn escape_graphviz_value(value: &str) -> String {
    value
        .replace("\\", "\\\\")  // Escape backslashes first
        .replace("\"", "\\\"")  // Escape double quotes
        .replace("\n", "\\n")   // Escape newlines
        .replace(":", "\\:")    // Escape colons
}

Will finish up docs and tests once the solution is satisfactory

  • I ran rustfmt locally
  • I have added the tests to cover my changes.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

@CLAassistant
Copy link

CLAassistant commented May 30, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you push the correct branch in your PR? The code change here is adding a print statement (it looks like a debug print) and not fixing the bug.

@anushkrishnav
Copy link
Contributor Author

Did you push the correct branch in your PR? The code change here is adding a print statement (it looks like a debug print) and not fixing the bug.

ohh sorry Let me check whats happening,

@anushkrishnav
Copy link
Contributor Author

@mtreinish Sorry about the print statement , is this how the output must look like ?
image

it would be saved as a graph.svg ??

I am sorry looks like i forgot to push the update , Silly

Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea is good, but we definetely need to check if we covered all possible characters that need escaping. And add tests

src/dot_utils.rs Outdated Show resolved Hide resolved
@anushkrishnav
Copy link
Contributor Author

I think the idea is good, but we definitely need to check if we covered all possible characters that need escaping. And add tests

I belive using a package like serde json should be a better way to do it that building a dictionary of cases that we cant escaped

@anushkrishnav
Copy link
Contributor Author

anushkrishnav commented Jun 1, 2024

I think the idea is good, but we definetely need to check if we covered all possible characters that need escaping. And add tests

Yes We can add a custom test case that tests for combinations of escape sequences
@IvanIsCoding please check and let me know if its good to go

return {"label": label, "tooltip": tooltip}

# Draw the graph using graphviz_draw
image = graphviz_draw(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good will work on em

Copy link
Contributor Author

@anushkrishnav anushkrishnav Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IvanIsCoding Do you want me to run the code on the site or ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want you to avoid writing temporary files to the disk for the unit tests. For the GitHub CI, we found those tests very flaky on macOS. So I suggested that method as a way of testing the fix with only in-memory operations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, Update the code with the recommendation, let me know if it needs any changes

tests/visualization/test_graphviz.py Outdated Show resolved Hide resolved
tests/visualization/test_graphviz.py Outdated Show resolved Hide resolved
@IvanIsCoding
Copy link
Collaborator

Rust code is looking good, just two minor things and this will be good to go:

Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anushkrishnav I approved the CL but you need to fix the CI errors by running black, cargo clippy. I also recommend running nox -edocs to confirm that the documentation compiles too

@anushkrishnav
Copy link
Contributor Author

@anushkrishnav I approved the CL but you need to fix the CI errors by running black, cargo clippy. I also recommend running nox -edocs to confirm that the documentation compiles too

Will finish it today, thanks it was fun to work with !!

@coveralls
Copy link

coveralls commented Jun 10, 2024

Pull Request Test Coverage Report for Build 9449570809

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • 58 unchanged lines in 7 files lost coverage.
  • Overall coverage decreased (-0.2%) to 95.87%

Files with Coverage Reduction New Missed Lines %
src/generators.rs 1 99.04%
src/coloring.rs 1 98.9%
rustworkx-core/src/generators/mod.rs 1 0.0%
rustworkx-core/src/dag_algo.rs 1 99.52%
rustworkx-core/src/generators/random_graph.rs 4 85.04%
src/traversal/mod.rs 6 96.98%
rustworkx-core/src/coloring.rs 44 90.02%
Totals Coverage Status
Change from base Build 9259965164: -0.2%
Covered Lines: 17387
Relevant Lines: 18136

💛 - Coveralls

@IvanIsCoding
Copy link
Collaborator

the issue seems to stems from

'['git', 'describe', '--abbrev=0']'

Which ig gets the recent tag ?

That is an unrelated error. I think the real one is highlighted in the CI:

Error: <stdin>: syntax error in line 2 near '\'

Extension error:
Cell raised uncaught exception:
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
Cell In[3], line 4
      1 import rustworkx as rx
      2 from rustworkx.visualization import graphviz_draw
----> 4 graphviz_draw(
      5 rx.generators.path_graph(2),
      6 filename="graph.svg",
      7 image_type="svg",
      8 node_attr_fn=lambdax:{"label":"the\nlabel","tooltip":"the\ntooltip"},
      9 )

File ~/work/rustworkx/rustworkx/.nox/docs-3/lib/python3.8/site-packages/rustworkx/visualization/graphviz.py:212, in graphviz_draw(graph, node_attr_fn, edge_attr_fn, graph_attr, filename, image_type, method)
    210     return image
    211 else:
--> 212     subprocess.run(
    213 [prog,"-T",output_format,"-o",filename],
    214 input=dot_str,
    215 check=True,
    216 encoding="utf8",
    217 text=True,
    218 )
    219     return None

The release note drawing is throwing an exception when calling graphviz

@anushkrishnav
Copy link
Contributor Author

anushkrishnav commented Jun 10, 2024

Okay I see the problem is with the quotes , it helps with the '' issue, once i changed it back its back to normal, I will updated the expected to make it in line with using quotes. Can you try again ? @IvanIsCoding

src/dot_utils.rs Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Jun 11, 2024

Pull Request Test Coverage Report for Build 9466635439

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • 64 unchanged lines in 8 files lost coverage.
  • Overall coverage decreased (-0.2%) to 95.837%

Files with Coverage Reduction New Missed Lines %
src/generators.rs 1 99.04%
src/coloring.rs 1 98.9%
rustworkx-core/src/generators/mod.rs 1 0.0%
rustworkx-core/src/dag_algo.rs 1 99.52%
rustworkx-core/src/generators/random_graph.rs 4 85.04%
src/traversal/mod.rs 6 96.98%
src/shortest_path/all_pairs_bellman_ford.rs 6 95.53%
rustworkx-core/src/coloring.rs 44 90.02%
Totals Coverage Status
Change from base Build 9259965164: -0.2%
Covered Lines: 17379
Relevant Lines: 18134

💛 - Coveralls

Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving some minor change requests as unwrap() can panic the Rust code which is not very nice to handle from Python. If we return a result, though, it is much simpler

src/dot_utils.rs Outdated Show resolved Hide resolved
src/dot_utils.rs Outdated Show resolved Hide resolved
@IvanIsCoding IvanIsCoding added the automerge Queue a approved PR for merging label Jun 11, 2024
@coveralls
Copy link

coveralls commented Jun 11, 2024

Pull Request Test Coverage Report for Build 9473598112

Details

  • 7 of 8 (87.5%) changed or added relevant lines in 1 file are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.04%) to 95.832%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/dot_utils.rs 7 8 87.5%
Files with Coverage Reduction New Missed Lines %
src/shortest_path/all_pairs_bellman_ford.rs 6 95.53%
Totals Coverage Status
Change from base Build 9450395122: -0.04%
Covered Lines: 17382
Relevant Lines: 18138

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 11, 2024

Pull Request Test Coverage Report for Build 9473770325

Details

  • 7 of 8 (87.5%) changed or added relevant lines in 1 file are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.04%) to 95.832%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/dot_utils.rs 7 8 87.5%
Files with Coverage Reduction New Missed Lines %
src/shortest_path/all_pairs_bellman_ford.rs 6 95.53%
Totals Coverage Status
Change from base Build 9450395122: -0.04%
Covered Lines: 17382
Relevant Lines: 18138

💛 - Coveralls

@IvanIsCoding IvanIsCoding merged commit 70b7126 into Qiskit:main Jun 11, 2024
28 of 30 checks passed
@anushkrishnav
Copy link
Contributor Author

Awesome, thank you @IvanIsCoding I was fun working on this, Will work on more issue , I am learning rust for a the past 2 months and been exploring the code base to put my learning into practice thanks for the oppurtunity

mtreinish added a commit to mtreinish/retworkx that referenced this pull request Jun 28, 2024
This commit fixes a regression introduced in Qiskit#1203. That PR was
attempting to fix missing character escaping in some string fields
but it was doing so too eagerly. This would result in invalid dot
files being produced for users upgrading from rustworkx < 0.15.0 that
were wrapping strings in quotes as needed previously. For example if you
were setting `'color="#aaaaaa"'` previously before this would become
`color="\"#aaaaaa\""` after Qiskit#1203. In order to quickly release a 0.15.1
this commit reverts the dot generation component of Qiskit#1203 but updates
the code to wrap tooltip in addition to label which was what the
original bug reported. In 0.16.0 we should investigate adding a flag to
control the escaping behavior of the function to either decide to wrap
values in quotes or not.
mtreinish added a commit to mtreinish/retworkx that referenced this pull request Jun 28, 2024
This commit fixes a regression introduced in Qiskit#1203. That PR was
attempting to fix missing character escaping in some string fields
but it was doing so too eagerly. This would result in invalid dot
files being produced for users upgrading from rustworkx < 0.15.0 that
were wrapping strings in quotes as needed previously. For example if you
were setting `'color="#aaaaaa"'` previously before this would become
`color="\"#aaaaaa\""` after Qiskit#1203. In order to quickly release a 0.15.1
this commit reverts the dot generation component of Qiskit#1203 but updates
the code to wrap tooltip in addition to label which was what the
original bug reported. In 0.16.0 we should investigate adding a flag to
control the escaping behavior of the function to either decide to wrap
values in quotes or not.
mtreinish added a commit that referenced this pull request Jun 28, 2024
This commit fixes a regression introduced in #1203. That PR was
attempting to fix missing character escaping in some string fields
but it was doing so too eagerly. This would result in invalid dot
files being produced for users upgrading from rustworkx < 0.15.0 that
were wrapping strings in quotes as needed previously. For example if you
were setting `'color="#aaaaaa"'` previously before this would become
`color="\"#aaaaaa\""` after #1203. In order to quickly release a 0.15.1
this commit reverts the dot generation component of #1203 but updates
the code to wrap tooltip in addition to label which was what the
original bug reported. In 0.16.0 we should investigate adding a flag to
control the escaping behavior of the function to either decide to wrap
values in quotes or not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Queue a approved PR for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

graphviz draw tooltip with special characters
5 participants