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

[bug] Option names with hyphen character is not deleted correctly #10570

Closed
uilianries opened this issue Feb 14, 2022 · 4 comments
Closed

[bug] Option names with hyphen character is not deleted correctly #10570

uilianries opened this issue Feb 14, 2022 · 4 comments
Milestone

Comments

@uilianries
Copy link
Member

That's a limitation with python which creates an inconsistent situation with Conan recipes.

When naming an option using hyphen e.g. foo-bar, on python, it will be parsed as foo_bar, because - means minus operator.

del self.options.foo-bar    # SyntaxError: cannot delete operator
del self.options.foo_bar   # valid

However, once deleted with underscore character, the option is still valid when passing option as command argument.

conan create . foo/0.1@ -o foo:foo-bar=True  # works

The current workaround is using delattr.

delattr(self.options, "foo-bar")

We can't restrict option names to underscore only, but we need to remove accordingly and show the no option error message.

Related to conan-io/conan-center-index#9248

Environment Details (include every applicable attribute)

  • Operating System+version: Any
  • Compiler+version: Any
  • Conan version: 1.45.0
  • Python version: 3.5+

Steps to reproduce (Include if Applicable)

from conans import ConanFile
class FooConan(ConanFile):
    options = {"foo-bar": [True, False]}
    default_options = {"foo-bar": False}

    def config_options(self):
        del self.options.foo_bar
conan create . foo/0.1@ -o foo:foo_bar=False
ERROR: foo/0.1: option 'foo_bar' doesn't exist
Possible options are ['foo-bar']

conan create . foo/0.1@ -o foo:foo-bar=False
Works normally ...

Expected Behavior

The follow statement must return an error:

conan create . foo/0.1@ -o foo:foo-bar=False
ERROR: foo/0.1: option 'foo-bar' doesn't exist
@memsharded
Copy link
Member

I think there is a misunderstanding about what is happening: del self.options.foo_bar # valid is not removing anything. The del operator is coded so it doesn't fail when the option doesn't exist that is all (and can't be changed without breaking). Given the option name, I see no other possibility than doing it via delattr, we are not converting hyphens to underscores, that is also problematic at least if not fully breaking.

@uilianries
Copy link
Member Author

(and can't be changed without breaking)

I was afraid you would say that 😂

Can we at least, improve it for Conan 2.0?

@memsharded
Copy link
Member

memsharded commented Feb 14, 2022

Can we at least, improve it for Conan 2.0?

How? 😅
You mean, by raising an error for del self.options.foo_bar if it doesn't exist? I think that has already been addressed in 2.0, but I can check, yes.

Update: Yes, we are good:

ERROR: pkg/0.1: Error in config_options() method, line 28
        del self.options.some_thing
        ConanException: option 'some_thing' doesn't exist
Possible options are ['shared']

@uilianries
Copy link
Member Author

Amazing, at least we will no longer suffer it again.

We are good to close this issue. Thank you for clarifying.

@memsharded memsharded added this to the 2.0 milestone Feb 14, 2022
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