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

#123 Custom attributes must be protected #124

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

uilianries
Copy link
Member

@uilianries uilianries commented Nov 1, 2019

  • I need to compare if the attributes in the conanfile passed to this hook, contains more attributes and if they are protected. However, I need to compare using a default ConanFile object, which is not loaded by basic_load, because it requires a conan recipe (file) to be loaded. Also, the loaded injects some attributes, which are not present in the Conanfile, so I checked them adding the attributes by their names (conan_data and python_requires)

closes #123

Wiki:

#KB-H035: "CUSTOM ATTRIBUTES"

When a new attribute have to be added to the recipe, and it is not a default one provided by ConanFile, it must added as protected member:

class Recipe(ConanFile):
    settings = "os", "arch" # default attributes are public
    _my_attr = "foobar" # custom attributes are protected
    __private_attr = "qux" # private should not be used. Use protected instead.

@uilianries uilianries requested review from danimtb, SSE4 and jgsogo May 8, 2020 17:15
@jgsogo
Copy link
Contributor

jgsogo commented May 12, 2020

A little bit afraid of this one. It can break if we add to Conan any field (also dynamic ones) and we might not notice it until all the PRs in ConanCenter fail. For example, here you are missing python_requires_extend, but there are other fields we all might not be aware right now.

This is a nice hook, but I will make it a warning, not an error. wdyt?

@uilianries
Copy link
Member Author

It can break if we add to Conan any field (also dynamic ones) and we might not notice it until all the PRs in ConanCenter fail.

Do you mean protected Conan fields? But we are not allowed to use it in CCI because we can't ensure them for breaking, we only use public and exported methods.

For example, here you are missing python_requires_extend, but there are other fields we all might not be aware right now.

I didn't understand, python_requires_extend is public, it won't be blocked by this hook. Is there any protected field that we are using and should be public?

This is a nice hook, but I will make it a warning, not an error. wdyt?

The problem using warning level is that we need to build when reviewing and checking the log, OR read output logs from CI. IMO it doesn't work, repetitive human review is susceptible to failure.

@SSE4
Copy link
Contributor

SSE4 commented May 12, 2020

python_requires_extend is mentioned twice in the docs, but appears to be undocumented on its own. what does it do?

@uilianries
Copy link
Member Author

@SSE4 Indeed the example on https://docs.conan.io/en/latest/extending/python_requires.html#extending-base-classes shows its usage, but I didn't find any reference with details.

@jgsogo
Copy link
Contributor

jgsogo commented May 12, 2020

My concern is that you have added conan_data and python_requires by hand. Any other field can pop up in the future and this hook will fail. Probably this is not as bad as I'm thinking about because we can iterate really fast in this repo to handle the new member if needed. So ok, not a problem.

@SSE4 python_requires_extend is the way to inherit from a base class inside a python requires. Conan injects this class as a base class to the conanfile in runtime. Why? We need to be able to load the python file with the recipe and the python requires information before resolving the classes/methods from python_requires (if we use Python inheritance we need to retrieve python_requires first and the interpreter will use the base class). This let Conan control the python_requires.

Agree it needs better docs, it should appear in the text, not only in the example.

jgsogo
jgsogo previously approved these changes May 12, 2020
@uilianries
Copy link
Member Author

Nice explanation, thanks @jgsogo !

@SSE4
Copy link
Contributor

SSE4 commented May 12, 2020

@jgsogo thanks for the explanation. I believe python_requires_extend should be documented there. I'll create an issue for docs.

SSE4
SSE4 previously approved these changes May 12, 2020
@run_test("KB-H035", output)
def test(out):
mock = ConanFile(conanfile.output, None)
valid_attrs = [attr for attr in dir(mock) if not callable(attr)] + ['conan_data', 'python_requires']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least, here we need python_requires_extend too. And for 1.26 we should handle new attributes/functions that could result of this PR conan-io/conan#6945

@SSE4 SSE4 dismissed stale reviews from jgsogo and themself via f3532d2 February 17, 2022 14:58
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 this pull request may close these issues.

Custom attributes must be protected
3 participants