Description:
Ability to specify conan minimum version in conan recipe. This version would be checked before any other logic and will result in command invocation failure.
Example:
class PkgName(ConanFile):
# This should be hard-coded in recipe attribute
minimum_conan_version='1.99.0'
...
# Uses magic that's only available in conan 1.99.0+
...
> conan create @ .
Error: recipe requires conan 1.99.0 or newer.
Current version: 1.22.0.
Reasoning: mostly conan-center-index related. Some recipes are updated to use features from the latest conan. But if a user with an older conan will try to use them, they might see random and unintelligible errors, with no easy way to check if the problem is a bug in recipe/conan, or if it's a problem with their machine/configuration, or if it's just conan missing an update.
Part of the conversation from slack (in case someone has the same questions/points):
Question/problem:
I'm mostly trying to look into a restrospective of what could go wrong with using an explicit version in a recipe. It's obviously not a free thing, since it'll increase the cost of PRs, also I'm not sure how to verify that the manually put version is sound.
The is no a version specific mode in Conan (it'd be very costly to make one) so it can't fall back to some older scheme to verify that the version specified is good.
Proposed solution:
This could be mentioned in CCI PR template, something like "if you are updating a recipe using features from recently released conan versions, please update the ConanFile.minimum_conan_version correspondingly". Alternatively, it could be just a dumb rule of thumb: "if you edit a recipe, update the minimum_conan_version to the latest"
I think this feature could be really useful. CMake has the same.
What would also be very beneficial, if in general in the docs, you added when a certain feature was introduced (e.g. introduces with Conan 1.25), because Conan evolves so quickly that often I wonder if this particular feature described in the documentation is new, or if I just never saw it before.
But luckily, due to your stability commitment, it's (most of the time) easy to just upgrade Conan to the latest version.
Thanks for logging this issue. Besides the minimum version feature which I agree with, there should be tools and guidance so that recipe writers can write backwards compatible recipes. Recipes almost always assume that the consumer is running the latest and greatest version of Conan which isn't always the case. Ideally a recipe could check the version of Conan before using some new functionality and falling back to old behavior if not.
Ideally a recipe could check the version of Conan before using some new functionality and falling back to old behavior if not.
Yeah, but maybe a bit too much to ask for recipe open-source creators. The version has always been there to be checked (from conans import __version__), but the extra required maintenance, and the fact that ConanCenter for example will not test older versions code, makes it challenging.
We will agree that, in the best scenario, the result will be the same with or without this feature: Conan will raise and we will get some message associated with the recipe reference. So, why we want this feature? Because we want a meaningful error instead of some cryptic Python callstack (or unrelated ConanException and message).
With this feature, we will get a message like name/version Error: recipe requires conan 1.99.0 or newer. Which is meaningful, but says nothing about why is failing. Without this feature we get a dirty message but, if we know how to read the callstack, maybe we get some insights about the error.
Given the stability commitment, we don't need this feature because Conan changes the defaults in some version and we need to be sure that the recipe is used with the newer default... it is not that Conan will generate different binaries for one version and a different one. It's only about features not yet available and cryptic errors.
Said that, this feature can introduce new problems: recipes adding a minimum_conan_version just because it is was copy/pasted from another recipe... adding the latest Conan without actually checking the version required given the features used. Just write cmake_minimum_required(3.18) because it is the one I have installed...
If it is for companies, IMO sharing the configuration and using required_conan_version in conan.conf would be the way to go. For recipes in the wild, I'm really afraid of people just adding a minimum_conan_version to their recipes because it works for them.
Easy feature, but maybe it has undesired effects, wdyt about my comments?
Easy feature, but maybe it has undesired effects, wdyt about my comments?
Yeah, I agree, those are valid concerns. As usual, it is a tradeoff, lets see other people (@TheQwertiest, @KerstinKeller, @sourcedelica) feedback, specially regarding the required_conan_version in conan.conf , it is relatively new, so it is likely it is not known yet.
I don't really care much, since I'm not using conan-center. Just heard that there was such a problem and thought that this feature could (somewhat) solve it.
I like the idea for the recipe attribute. As a matter of fact, a user reported this to me yesterday:
ERROR: Error loading conanfile at 'C:\Users\pfraval\.conan\data\boost\1.73.0\_\_\export\conanfile.py': Unable to load conanfile in C:\Users\pfraval\.conan\data\boost\1.73.0\_\_\export\conanfile.py
File "c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 684, in _load
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\pfraval\.conan\data\boost\1.73.0\_\_\export\conanfile.py", line 3, in <module>
from conans.tools import Version, cppstd_flag
ImportError: cannot import name 'cppstd_flag'
For the Conan Center recipes the level of code review would probably prevent the version in the recipe attribute from getting stale.
I also like the conan.conf property to catch problems even earlier.
PS. I 鉂わ笍 config_install_interval.
What do you think about this alternative at python-file level?
from conans import ConanFile
min_conan_version = "1.26"
class Lib(ConanFile):
pass
This has been implemented in https://github.com/conan-io/conan/pull/7360, will be finally available in next Conan 1.28 (as required_conan_version = <range>, to match the conan.conf.
This feature should be probably also mentioned somewhere in PR template for CCI.