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] allow hooks to extend conan command line interface #7085
Comments
I wouldn't mind to provide this functionality, and we should at least design the Conan 2.0 api and command line (cc/ @czoido) to consider this possibility. Probably it should be called "hooks", but "porcelain" or "command alias" or something like that, I think this is a different concept. |
alias is also nice thing, but I suppose it's a little bit different. it's for providing shortcuts for long, but frequently used commands. e.g. similarly, we may allow such thing for conan as well, e.g. alias but here the suggestion is to provide brand new commands, which aren't represented but the currently available conan commands. e.g. allow hook author to write his own logic to print package_id, or print whatever (e.g. run |
just in case, breakdown to the 3 smaller things here to avoid misunderstanding:
|
Just wanted to link here some valuable comments when we started to talk about plugins (not hooks, but there are things to keep in mind): #3778 |
Here's how docker implemented the same concept... to be used as prior art: docker/cli#1534 |
I've just started using an initial implementation of this and have several pieces of feedback i'll be posting shortly. |
We'll definitely need some distinguishing prefix for all user commands to avoid any possibility of conflict with future commands Conan decides to add. Possible mechanism include
|
Some of the most generic features I'm looking forward to as advantages over just writing my own scripts which invoke
|
linking #7170 as it's a bit related |
Additional feedback, it will be common for commands to be combinations or "customizations" of other commands. For example, in my very first experimental command, I wanted to replace a script which had been written before, with a new custom command.
To get the paths of the package folder in the local conan. From inside a custom command, I can do this to easily invoke the
However, that only works because I don't care about the output of that command. For the next command: Unfortunately, this common situation lands me in an unfortunate place between just calling another command and calling the API function for that command. If I call the command the same way I did with Ideally, for Conan 2.0, I suggest we implement a change to these two lines at the end of the
In theory, we could just change all these command-level functions to always return the result so that they could all be called programmatically the way I want to do for this case. Then each could have a wrapper function which does the post-processing of the result for the normal case. |
After #7170 which should introduce a new CLI interface, we need to refactor all the |
I'll continue experimenting on the future user experience side and capturing my feedback in this ticket since it's the most appropriate place at the moment. I'll continue to provide detailed user stories like this one from those experiments. They can be reviewed during the implementation process whenever that reaches a suitable point. |
Just like native conan commands, one of the first things I need is a proper configuration file strategy to define defaults for all my custom commands for my organization. Obviously, we don't want to involve So, for custom command This one-config-file-per-command strategy has a nice quality of modularity and consistency, in that each config file and command are nice and isolated. It's easy to understand and use for the first time. However, it has a scalability quality which is not-so-nice. If an organization has 20 custom commands, managing 20 config files feels real bad. Thus, we should offer an alternative strategy for this case. In addition to searching for |
We like to think in terms of pains to solve, issues to address, instead of features to implement. It would be good to illustrate it with some real world examples. The truth is that so far in the conan.conf there are practically no command-specific configuration. There are things like So I would say that this is too early to be considered for implementation, and not necessary to include this in the first iterations of the "user commands" feature. |
Another item which came up immediately was how to handle additional third-party python package dependencies users may wish to use in their custom commands. Initially, it seems to be just like with So, in summary, this comment is a no-op, but will be good here for future readers to know that it was considered. |
I have just published the first POC here based on a recent commit of @czoido 's conan fork (CLIV2 branch). WRT the purpose of the command: It's a very straightforward and common workflow to want to run Conan inside a docker container. In particular, developers often do development work inside their local environment, and then just need to do a sanity test in at least one docker container before pushing to let CI do a more comprehensive test, Conan package tools provides similar wrapping logic and can theoretically achieve something similar, however that project completely different architecture, priorities, and many different implications which make it less desirable for this case. WRT some of my previous comments about the experience of creating this command: I implemented a fairly robust configuration file management strategy, which took about 60 lines. In this case, about 50 of those are boilerplate and 10 actually declare the configuration items and their types/defaults/etc. If argparse had first-class support for env vars and configuration files, none of that would have been necessary. I implemented generic subprocess wrappers because the Conan "runner" wasn't exactly what I needed, so that added another 25 lines of boilerplate. About 75 lines were spent orchestrating the cross-platform docker logic and command composition which is more or less the core purpose of the command. About 30 lines are the command-line arguments parsing. |
A new mechanism is already in place "modular user custom commands" for Conan 2.0, already merged to develop2, so this feature can be considered done. |
Hello together, we are trying at the moment to find the best way to get the RREV from a conanfile in a machine-readable form (e.g. on stdout or json file). It seems conan does not provide it via commands like export or info. Could we use (conan 1.x) the above mentioned CONAN_V2_CLI=1 to create the mentioned "modular user custom commands" to have a nice interface to get the RREV? |
Hi @SzBosch
A Using an actual
I am afraid that these only exist in Conan 2.0, it depends on 2.0 new architecture, it is also impossible to backport them to Conan 1.X |
it would be nice to allow conan hooks to extend conan command line interface to provide user-specified commands. this would bring more level to conan extensibility.
for instance, user may want to write custom command to display a
package_id
for the given recipe and settings. he may write his own hook, like:and then use it like:
as a reference, right now Git offers similar thing - it will automatically pick up
git-xxx
executable and use it asgit xxx
sub-command (source).few examples of using such extensibility:
git flow
git annex
git ftw
I've read the CONTRIBUTING guide.
The text was updated successfully, but these errors were encountered: