Git Product home page Git Product logo

Comments (5)

memsharded avatar memsharded commented on June 1, 2024 1

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.

memsharded avatar memsharded commented on June 1, 2024

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.

GRyzer avatar GRyzer commented on June 1, 2024

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.

memsharded avatar memsharded commented on June 1, 2024

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.

GRyzer avatar GRyzer commented on June 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.