conan
conan copied to clipboard
[feature] Support conan __version__ under conan namespace
When users need to show, or even compare which Conan client is running, from the recipe, they can usually import __version__:
from conans import __version__ as conan_version
print(f"Conan version: {conan_version}")
However, it's not possible to do same with the new namespace conan. It would be great having the same feature available, since some methods from Conan 2.0 are not compatible with Conan 1.0 and to keep a recipe working for both during the transition, it's important to detect which Conan version is running.
The real case comes from self.requires() which is incompatible and breaks according to the version:
https://docs.conan.io/en/1.51/reference/conanfile/methods.html#requirements vs https://docs.conan.io/en/2.0/reference/conanfile/methods.html#requires
The version 2.0 offers transitive_headers, which is not optional on 1.x
As workaround, needed to create:
requires = lambda ref: self.requires(ref, transitive_headers=True) if Version(conan_version) >= "2.0.0-beta" else self.requires(ref)
- [x] I've read the CONTRIBUTING guide.
Apart from making available the version I wonder if we should add a **kwargs or a similar trick to the self.requires of the Conan 1.x. The traits don't exist in Conan 1.X but up to my knowledge the transitive_headers and transitive_libs are always True in Conan 1.x.
To discuss (look into): Should we allow these arguments in Conan 1.X and raise if they are specified but False?
The traits don't exist in Conan 1.X but up to my knowledge the transitive_headers and transitive_libs are always True in Conan 1.x.
It could work also.
I think it deserver some better looking identifier than __version__.
- Use a better identifier:
conan_version - It is a comparable
Versionobject
Lets create a new issue for the traits args.