Comments (5)
This section about the "modes" here might help: https://docs.conan.io/2/reference/conanfile/attributes.html#package-id-embed-non-embed-python-unknown-mode
Also https://docs.conan.io/2/reference/extensions/python_requires.html#effect-in-package-id
Then I think we can close this question as solved, don't hesitate to open new tickets for any further question. Thanks for the feedback!
from conan.
Hi @GRyzer
Thanks for your question.
I rejected the first one because python_requires is a class variable and that would be required for every platform, which does not correspond to my use case.
It can be "imported", in the same way a python import or a C++ header can be included, but that doesn't mean it needs to be used for all platforms. The python_requires
is relatively cheap, as it is fetching just some python code, it won't add any overhead compared with all the other heavier operations. Then you decide to call or not the functionality in the python_requires
conditionally on the platform in the generate()
method, it is not compulsory to extend them, a python-requires can contain just a function that you can call from your generate()
. I wouldn't reject this approach, using python_requires
can be quite useful for this purpose and in general if you maintain multiple packages for your own code.
If my generator is in [CONAN_HOME]/extensions/generators/my_generator.py, I would have assumed that I would need such an include in my conanfile.py files.
It means that you need to do:
generators = "MyGenerator"
in your conanfile.py
, and it will be called in the same way as other built-ins.
This approach is inferior to the previous one, because global generators are not versioned, it is more difficult to track and reproduce builds using them, they do not have any effect on the package_ids
, they are not self-contained (automatically resolved), they are more difficult to upgrade, specially if at some point you need to do some breaking changes.
I'd probably strongly recommend python_requires
approach for most cases.
from conan.
So Conan implicitly finds my generator. Would have expected me to need an import conan.extensions.generator.my_generator
or something similar. I'm not quite happy with the solution yet, because both use class variables. This means I can't call a python_requires
in the requirements(self)
method to use self.settings.os
.
I understand the point of python_requires
and why I should prefer it. My issue is that it affects the package_id
, which I don't want in this case. In my usecase I create a file that will be different from user to user and is basically an IDE file (for the indexer, to find some header files if i click on an include), which has no influence on a src or header file, and therefore should have no influence on the package_id
.
from conan.
So Conan implicitly finds my generator. Would have expected me to need an import conan.extensions.generator.my_generator or something similar. I'm not quite happy with the solution yet, because both use class variables.
If this is an IDE file, then most likely the best approach is this one, global custom generators, called in the command line with -g MyCustomGenerator
(by name), when desired to generate for the IDE. But not from the recipe, because no need to add it to all recipes, because that would still be required and used even when not using the IDE, like in CI, that doesn't sound good.
This means I can't call a python_requires in the requirements(self) method to use self.settings.os.
Yes, you can define any function in a python-requires
and then call it from the consumer with something like my_generator_function(self)
or my_generator_function(self.settings)
and pass whatever information it needs from the consumer data.
I understand the point of python_requires and why I should prefer it. My issue is that it affects the package_id, which I don't want in this case. In my usecase I create a file that will be different from user to user and is basically an IDE file (for the indexer, to find some header files if i click on an include), which has no influence on a src or header file, and therefore should have no influence on the package_id.
Agree. It is also possible to define independence from the python_requires
, so it doesn't affect the package_id
, but as commented above, I agree that for this use case a global generator is better.
from conan.
Is there documentation what i have to do that python_requires
does not affect my package_id
?
The other point is resolved for me. I managed to do what i tried to achieve. Thanks a lot
from conan.
Related Issues (20)
- [bug] conan list --graph with non-existing file HOT 2
- [question] how to deploy without dependencies HOT 3
- [suggestion] Label only highest tag as latest release HOT 5
- [bug] Conflict with built-in cmake findpackage scripts can break the build HOT 2
- [question] Is there a way to define information in a recipe that can be used in CMake (or other build systems potentially) HOT 2
- [question] How to build C++ project with Apple Hardened Runtime enabled? HOT 12
- [question] Can I pass --vs-args or --ninja-args arguments to the meson tool when executing build command HOT 1
- [bug] file DOWNLOAD cannot compute hash on failed download, it shows 'status: [35;"SSL connect error"]' HOT 8
- [bug] test_package_folder attribute doesn't work HOT 1
- [question] Limitations of `CMakeToolchain` wrt legacy generators HOT 4
- [bug] Github actions fail when set `tools.system.package_manager:mode` HOT 2
- [question] How to depend on a specific Git commit or branch of a project HOT 7
- [bug] build_requires with different #RREV are not used correctly HOT 2
- [question] What is the correct way of exposing PATH when packaging library type? HOT 2
- [bug] CMakeToolchain changes the value of string variables unexpectedly/incorrectly HOT 6
- [feature] [question] Support the Tricore-gcc toolchain and arch
- Incorrect generation of file conanvcvars.ps1 HOT 2
- [question] Conan centre package rereleases HOT 7
- [question] Should Visual Studio 17.10 require a profile update to 194? HOT 31
- [bug] Multiple `--build=missing:~foo` does not work HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from conan.