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

Add --graphml option to the nix-store --query command #2479

Merged
merged 2 commits into from Oct 23, 2018

Conversation

nlewo
Copy link
Member

@nlewo nlewo commented Oct 16, 2018

This prints the references graph of the store paths in the graphML
format [1]. The graphML format is supported by several graph tools
such as the Python Networkx library or the Apache Thinkerpop project.

I also wonder if this could replace the --xml output since the GraphML format is well known and easy to manually parse.

[1] http://graphml.graphdrawing.org

Copy link
Member

@dtzWill dtzWill left a comment

Choose a reason for hiding this comment

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

Neat! Look forward to trying it out :). Made a pass with some suggestions/comments.


static string makeEdge(const string & src, const string & dst)
{
format f = format(" <edge source=\"%1%\" target=\"%2%\"/>\n")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe return fmt(..., xmlQuote(src), xmlQuote(dst));? Saves the need for calling f.str().

workList.erase(path);

if (doneSet.find(path) != doneSet.end()) continue;
doneSet.insert(path);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe check the return value of insert instead (.second)? Shorter and saves searching again for the insert.


for (auto & p : store->queryPathInfo(path)->references) {
if (p != path) {
workList.insert(p);
Copy link
Member

Choose a reason for hiding this comment

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

Using a std::set for the worklist might not be the best, and seems like would have an unusual ordering, niether BFS nor DFS but ... alphabetically (of the current worklist)? If so, I imagine it doesn't matter to tools reading it but might annoy or confuse someone inspecting it by hand.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure it's really useful to make the code more complex to have a more xml human readable file (the goal of this PR is to generate a file that can be easily parsed by several tools).

I wonder why the set of paths is ordered while there is an unordered_set container in the std lib (I have a patch that uses an unordered_set in this file that I could include if it is pertinent).

@edolstra
Copy link
Member

Yeah I think it's fine to replace --xml, since I doubt anybody is using it at the moment.

@nlewo
Copy link
Member Author

nlewo commented Oct 18, 2018

I'll add docs and remove --xml in the next days.

@nlewo nlewo changed the title Add --graphml option to the nix-store --query command wip: Add --graphml option to the nix-store --query command Oct 18, 2018
This prints the references graph of the store paths in the graphML
format [1]. The graphML format is supported by several graph tools
such as the Python Networkx library or the Apache Thinkerpop project.

[1] http://graphml.graphdrawing.org
The `--graphml` option can be used instead.
@nlewo nlewo changed the title wip: Add --graphml option to the nix-store --query command Add --graphml option to the nix-store --query command Oct 20, 2018
@nlewo
Copy link
Member Author

nlewo commented Oct 20, 2018

I've added docs and removed --xml option. So, it should be good for reviews:/

@dtzWill FYI, I'm using this option with https://github.com/nlewo/gremnix :)

@edolstra edolstra merged commit 1a08ad7 into NixOS:master Oct 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants