-
Notifications
You must be signed in to change notification settings - Fork 990
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
How to set default_option based on some setting? #3519
Comments
I am afraid it is not possible to define conditional default options. The behavior you are reporting is the intended one, once an option is specified like |
From the documentation:
Due to this sentence, I was under impression that
Obviously, I got it wrong. Can you please explain (or update the documentation) what is and what isn't allowed in Also, can you consider adding support for conditional default values in the future (either with the described mechanism or by introducing the new method
This does not work either: from conans import ConanFile
class MyConan(ConanFile):
name = "Test"
version = "0.1.0"
description = "Insert project description here"
settings = 'arch', 'os', 'build_type', 'compiler'
options = {
'some_option': [True, False]
}
default_options = f'some_option={self.calculate_some_option()}'
def calculate_some_option(self):
if self.settings.os == 'Android':
return True
else:
return False I get
I am already using profiles for specifying other settings and options, that are orthogonal to specific option in my specific package. Having separate profile for each combination of options for each package would cause a combinatorial explosion and is not feasable for my setup. |
Ha, it appears this hack works correctly, at least for my use case: from conans import ConanFile
class MyConan(ConanFile):
name = "Test"
version = "0.1.0"
description = "Insert project description here"
settings = 'arch', 'os', 'build_type', 'compiler'
options = {
'some_option': [True, False]
}
def config_options(self):
if self.options.some_option == None:
if self.settings.os == 'Android':
self.options.some_option = True
else:
self.options.some_option = False
def configure(self):
print( f'[configure] Some option: {self.options.some_option}')
The only mystery is why it is mandatory to compare with if self.options.some_option == None: works, while if self.options.some_option is None: does not? EDIT: mystery solved |
@memsharded, if that hack looks OK to you, can you consider adding that to the documentation about conditional settings and options and making it official way to handle conditional default options? |
Yes, I agree it would be good to add it to the docs: conan-io/docs#816
The problem is that the semantics of assigning an option in the
Yes, we are thinking about possible improvements regarding the configuration of options, we are studying what could be done in a future conan 2.0 (breaking) release. This, or something close will probably be provided. I am linking this issue #3524 there too, so I think this one can be closed by now. Thanks for all the feeback! |
Exactly that confused me - I got the impression that the final one is assigned in This makes it difficult to understand the differences between def config_options(self):
if self.settings.os == "Windows":
del self.options.shared is executed before However, the fact is that it is executed after evaluation of command line option, but before the execution of From my tests with the current issue, I've found that not having default option at all and not specifying it on command line, fails with error before Can you please improve the documentation of |
Hey, @memsharded . Could we include this issue of conditional |
@memsharded conditional default values for options are also a feature we are looking for. |
Consider this conanfile:
I want the
some_option
to be set toTrue
by default if OS is Android and toFalse
otherwise. However, if someone specifies thesome_option
via command line, I want to use that. How to do that? I was under impression thatconfig_options
method is used for that, but when it appears it is not:$ conan install . Some option: False
$ conan install . -o some_option=True Some option: False
If I remove the
config_options
method, then the second example works correctly, but the first one fails withERROR: Conanfile: 'some_option' value not defined
.How to set a default value for the option, based on some setting, like OS?
I am using Conan v1.7.3 on MacOS.
The text was updated successfully, but these errors were encountered: