In options you can define a special value "ANY" as stated in the docs: https://docs.conan.io/en/latest/reference/conanfile/attributes.html#options-default-options
But in the example there is no default_options defined. Doing some tests Conan behaves like this:
conanfile.py
from conans import ConanFile
class MyConanFile(ConanFile):
name = "MyConanFile"
version = "1.0"
options = {"shared": [True, False], "config": "ANY"}
default_options = "shared=False",
$ conan create . danimtb/testing
ERROR: MyConanFile/1.0@danimtb/testing: 'config' value not defined
md5-dcf998b85a62fe9120654d5962d45296
from conans import ConanFile
class MyConanFile(ConanFile):
name = "MyConanFile"
version = "1.0"
options = {"shared": [True, False], "config": "ANY"}
default_options = "shared=False", "config="
md5-678040da866b30c3e54caf83029fa494
$ conan create . danimtb/testing
...
MyConanFile/1.0@danimtb/testing: Package '5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' created
md5-89124b7d1ea631baedafd257991401e7
from conans import ConanFile
class MyConanFile(ConanFile):
name = "MyConanFile"
version = "1.0"
options = {"shared": [True, False], "config": "ANY"}
default_options = "shared=False", "config=None"
md5-678040da866b30c3e54caf83029fa494
$ conan create . danimtb/testing
...
MyConanFile/1.0@danimtb/testing: Package '5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' created
Generates conaninfo.txt with "config=None", conan search returns "config: None" and package ID is NOT affected.
I suggest to use the last option as default, encourage users to use "config": "ANY together with "config=None" default value and do not allow just "config=". Would be breaking but more clear.
I'm not sure why if an option admits any value has to automatically default to anything and not require a default like any other one.
you could use a defaulted value if you want or even None, but just "config=" is something very weird
"config=" is indeed weird.
What @lasote suggests is to change the current default behavior, and assign it a None value automatically without having to specify it in the conanfile, did I understand correctly?
You didn't understand correctly. I was asking why we should do that for the ANY options and not for others.
I think the feature should be: raise when "config=" and allow "config=None"
Yes, that is what I suggested in the original comment. By:
I suggest to use the last option as default, encourage users to use "config": "ANY together with "config=None" default value and do not allow just "config=".
I meant: "I suggest to use the last case indicated above" -> raise when "config=" and allow "config=None"
Just to be sure, you expect all recipes to handle the "config would be empty" case in the following way:
if self.options.config == "None": instead of the current if self.options.config: ?
@ericLemanissier no, this is not related.
@ericLemanissier it should be if self.options.config: and default value when "config=None" should be NoneType
ok, my bad, if self.options.config: takes the else branch when default_options= "config=None"
However str(self.options.config) is equal to the "None" string, instead of being an empty string
@ericLemanissier probably you are right, @danimtb performed some tests and default_options= "config=None" => self.options.config == "None" and self.options.config != None
I think this is a bug but a little dangerous.
@ericLemanissier at least if you declare:
from conans import ConanFile
class MyConanFile(ConanFile):
name = "MyConanFile"
version = "1.0"
options = {"config": "ANY"}
default_options = "config=None"
if self.options.config: should be false as you reported. It is evaluated as False.
Most helpful comment
You didn't understand correctly. I was asking why we should do that for the ANY options and not for others.
I think the feature should be: raise when "config=" and allow "config=None"