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

[question] How to set options with hyphens in conanfile.py? #3768

Open
1 task done
gouriano opened this issue Jun 7, 2024 · 5 comments
Open
1 task done

[question] How to set options with hyphens in conanfile.py? #3768

gouriano opened this issue Jun 7, 2024 · 5 comments
Assignees
Milestone

Comments

@gouriano
Copy link

gouriano commented Jun 7, 2024

What is your question?

Hi
I am trying to customize aws-sdk-cpp package in my conanfile.py. The problem is that it uses hyphens in option names
See the recipe

My conanfile looks as follows:

from conan import ConanFile
class ConanApp(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "CMakeDeps"
#    default_options = {"aws-sdk-cpp*:text-to-speech": False}
    def requirements(self):
        self.requires("aws-sdk-cpp/1.9.234")
    def configure(self):
        self.options["aws-sdk-cpp/*"].text_to_speech = False

If I use "self.options["aws-sdk-cpp/"].text-to-speech = False", I get wrong python
If I use "self.options["aws-sdk-cpp/
"].text_to_speech = False", Conan2 does not complain, but the setting does not seem to have any effect (I know this because my app still requires pulseaudio package)
If I use "default_options = {"aws-sdk-cpp*:text-to-speech": False}", everything seems to work fine.

My question: is it possible to specify an option with hyphen in configure() method?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Jun 7, 2024
@memsharded
Copy link
Member

Hi @gouriano

Can you please clarify the Conan version you are using?

Also, please note that setting options in recipes is not the most recommended approach, but setting them in profile files, and having recipes to check them in validate() method, raising ConanInvalidConfiguration if something is strictly necessary.

@gouriano
Copy link
Author

gouriano commented Jun 7, 2024

$ conan version
version: 2.3.2
conan_path: /home/gouriano/venv_conan2/bin/conan
python
version: 3.9.19
sys_version: 3.9.19 (main, Apr 4 2024, 12:39:35) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)]
sys_executable: /home/gouriano/venv_conan2/bin/python
is_frozen: False
architecture: x86_64
system
version: conan-io/conan#1 SMP Mon Apr 8 11:23:13 EDT 2024
platform: Linux-4.18.0-513.24.1.el8_9.x86_64-x86_64-with-glibc2.28
system: Linux
release: 4.18.0-513.24.1.el8_9.x86_64
cpu: x86_64

@memsharded
Copy link
Member

I think this is mostly an overlook of the recipe, using hyphens that if is is true that it is not strictly forbidden, it is inconvenient for this use case.

I'd say that you can do something like setattr(self.options["aws-sdk-cpp"], "text-to-speech", False), please try that and let us know.

@gouriano
Copy link
Author

gouriano commented Jun 7, 2024

It works! Thank you!
Maybe, this should be documented.

@memsharded
Copy link
Member

Maybe, this should be documented.

Thanks for the feedback. The truth is that this sounds a bit as a workaround, but it is also true that there is a loophole there, as hyphens are not forbidden. But forbidding them now wouldn't be great, as that would mean breaking recipes in ConanCenter, or at the very least having some painful upgrades that would be also painful for users of those recipes.

As the general recommendation is to define options values in profiles, not in recipes, I think it might be better to leave it as-is. Please read https://docs.conan.io/2/knowledge/faq.html#defining-options-for-dependencies-in-conanfile-py-recipes-doesn-t-work, and try to define your options in profiles as much as possible (and let recipes validate() things)

I'll move it to the docs repo to try to add a note there about this.

@memsharded memsharded transferred this issue from conan-io/conan Jun 8, 2024
@memsharded memsharded added this to the 2 milestone Jun 8, 2024
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

No branches or pull requests

2 participants