Skip to content
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

Default value for options with ANY #3232

Closed
danimtb opened this issue Jul 18, 2018 · 11 comments · Fixed by #3245
Closed

Default value for options with ANY #3232

danimtb opened this issue Jul 18, 2018 · 11 comments · Fixed by #3245
Assignees
Milestone

Comments

@danimtb
Copy link
Member

danimtb commented Jul 18, 2018

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:

  • No default value: ERROR

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
  • No assigned value in default_options: WORKS

conanfile.py

from conans import ConanFile

class MyConanFile(ConanFile):
    name = "MyConanFile"
    version = "1.0"
    options = {"shared": [True, False], "config": "ANY"}
    default_options = "shared=False", "config="
$ conan create . danimtb/testing
...
MyConanFile/1.0@danimtb/testing: Package '5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' created

But the generated conaninfo.txt has config= and conan search returns config: both without value.

  • Use None as default value: Works

conanfile.py

from conans import ConanFile

class MyConanFile(ConanFile):
    name = "MyConanFile"
    version = "1.0"
    options = {"shared": [True, False], "config": "ANY"}
    default_options = "shared=False", "config=None"
$ 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.

@lasote
Copy link
Contributor

lasote commented Jul 18, 2018

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.

@danimtb
Copy link
Member Author

danimtb commented Jul 18, 2018

you could use a defaulted value if you want or even None, but just "config=" is something very weird

@memsharded
Copy link
Member

"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?

@lasote
Copy link
Contributor

lasote commented Jul 19, 2018

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"

@danimtb
Copy link
Member Author

danimtb commented Jul 19, 2018

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"

@ericLemanissier
Copy link
Contributor

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: ?

@lasote
Copy link
Contributor

lasote commented Jul 19, 2018

@ericLemanissier no, this is not related.

@danimtb
Copy link
Member Author

danimtb commented Jul 19, 2018

@ericLemanissier it should be if self.options.config: and default value when "config=None" should be NoneType

@danimtb danimtb added this to the 1.7 milestone Jul 19, 2018
@danimtb danimtb self-assigned this Jul 19, 2018
@ericLemanissier
Copy link
Contributor

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

@lasote
Copy link
Contributor

lasote commented Jul 19, 2018

@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.

@danimtb
Copy link
Member Author

danimtb commented Jul 20, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants