conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.25k stars 980 forks source link

[question] JSON generator #16522

Closed huysentr closed 3 months ago

huysentr commented 4 months ago

What is your question?

In conan1 there used to be a json generator. This was very easy to parse the package paths of dependencies. I know I can do the same in conan2 with --format JSON. However I cannot figure out how to generate a file from this without also redirecting the output. In conan1 it would supplement an additional file and generate output to the terminal. Am I missing something?

Have you read the CONTRIBUTING guide?

memsharded commented 4 months ago

Hi @huysentr

Not sure what is the issue with conan install --format=json > mygraph.json. All the application messages in Conan 2 is directed to stderr, so they don't interfere with stdout and the above works fine.

huysentr commented 4 months ago

I'm working in someone elses python code, and I can only modify the command, but not redirect its output. If this is the only way I will have to modify the library, no problem, it might just interfere with the approval of my PR.

memsharded commented 4 months ago

But Conan recipes are the thing running others code, via self.run(), see https://docs.conan.io/2/reference/conanfile/running_and_output.html#running-commands.

The self.run() already by default sends the output to stderr, so this shouldn't be a problem either. Conan 2 even redirects the print() default to stderr.

In theory it shouldn't be necessary to modify others code.

huysentr commented 4 months ago

I'm not sure I'm following. The code I'm working on has an API to run a command, inside that the library of that API I see process= subprocess.Popen( cmd, stdout = None, stderr = None) I can pass the cmd to this API, but not modify those things, I'm passing a conan install command. (I can modify those things ofc, but that's a different step)

memsharded commented 4 months ago

Ok, I think I understand now, thanks for the explanations.

So there is a Python dependency (from pip install package or something similar, I guess?) and that library is internally doing a Popen without redirecting the streams.

Yes, I am afraid this is something that would need some provision inside that Python library code. The usual approach when some Python code is managing subprocess is to use some configurable redirection/pipe or passing stream handlers, so the library can operate without polluting the caller standard streams (for example if the caller wants for some reason to silently execute that functionality). Conan operates on the assumption that it is possible to redirect the output of the subprocesses that it is launching, directly or indirectly within recipes.

If the code is doing stdout = None, stderr = None then it seems there is little to do, so it would be necessary to adapt that code.

memsharded commented 4 months ago

Hi @huysentr

Did you manage to get it working updating the library? Any further question? Thanks for the feedback.

memsharded commented 3 months ago

Closing as resolved, feel free to re-open or create new tickets as necessary, thanks for the feedback.