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

[feature] Provide an api for conan graph info #17488

Open
1 task done
fredizzimo opened this issue Dec 17, 2024 · 0 comments
Open
1 task done

[feature] Provide an api for conan graph info #17488

fredizzimo opened this issue Dec 17, 2024 · 0 comments

Comments

@fredizzimo
Copy link
Contributor

fredizzimo commented Dec 17, 2024

What is your suggestion?

We currently use the following code for automatically writing the conan graph to files when compiling

def write_graph_info(filename, result, formatter):
    # The formatters write to stdout, so change it to redirect to a file temporarily
    with open(filename, "w", encoding="utf-8") as f:
        with redirect_stdout(f):
            with redirect_stderr(f):
                try:
                    formatter(result)
                except GraphError:
                    # The formatters can raise a GraphError after the graph is written
                    # Let's ignore that, since we deal with the errors after this
                    pass
    logging.info(filename)


def write_graph_infos(proj, graph):
    delete_html_graph_template(proj.conan)

    result = {
        "graph": graph,
        "field_filter": None,
        "package_filter": None,
        "conan_api": proj.conan.api,
    }

    build_dir = proj.build_dir

    logging.info("\n****** More details can be found in the following files: ******")
    write_graph_info(build_dir / "packages.txt", result, format_graph_info)
    write_graph_info(build_dir / "packages.html", result, format_graph_html)
    write_graph_info(build_dir / "packages.dot", result, format_graph_dot)
    logging.info("\n***************************************************************\n")

This relies on some internal functionality, which is not ideal, but worse with Conan 2.10.0 caused the above code to stop working.

The workaround for the colorama crash here #17259, changes the stdout and stderr, which causes our own redirects to fail. But rather than fixing that, I think a proper API function that allows to write to files would be better.

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants