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] Is it possible to use inheritance in conanfile.py to factorize some data and logic ? #6054

Closed
1 task done
cedriclaplace opened this issue Nov 11, 2019 · 3 comments

Comments

@cedriclaplace
Copy link

We have a bunch of projects, each of them has a project.json file defining common informations about the project. This json file is used by several tools to share informations. We have created some helpers to read this file in order to fill conan attributes. We are looking to hide this kind of processing in a base class (which inherit from ConanFile) inherited by all projects. This base class holds common attributes (name, version, description, ...) and several helpers. We would like to hide as much as we can from the project recipe to have it as simple as possible, specifying only specific stuff of the project we are packaging.

That works pretty well but some commands raise an error saying "ERROR: conanfile didn't specify name". Same error message for the version number. In my case I define name and version attributes in the base class and it's like they cannot be inherited from a base class. As a workaround, I pass the complete package reference on the command line and everything is fine. We execute these commands through CI scripts so we can deal with this behavior.

I would like to know if I am doing something wrong or illegal ? Can we share name, version, ... from a bse class ?

@lasote lasote self-assigned this Nov 11, 2019
@lasote
Copy link
Contributor

lasote commented Nov 11, 2019

Are you using python requires? FYI We are working on a new version of the python requires, you can follow here: #5804 feedback is welcome.

About the name and version, at Conan 1.20 we released a new feature to set the name and version dynamically:

https://docs.conan.io/en/latest/reference/conanfile/methods.html?highlight=set_name#set-name-set-version

@cedriclaplace
Copy link
Author

Thanks for the quick reply.

We are indeed using a PythonRequire module. I'll look at the changes of this new version and the feature provided by conan 1.20 (I did my tests with conan 1.19) and I'll come back to you.

@cedriclaplace
Copy link
Author

I have done some tests using conan 1.20.3, the error is not raised anymore and it works as expected. I didn't have to use the new methods, my implementation works as is. I should have try the latest version before posting my question. Thanks for the improvement.

About PythonRequires, we manage to do what we need. We still need to use it more widdely. We'll come back later with more feedbacks.

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

No branches or pull requests

2 participants