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] Generate() vs. Imports() behavior #17700

Open
1 task done
valenotary opened this issue Feb 4, 2025 · 4 comments
Open
1 task done

[question] Generate() vs. Imports() behavior #17700

valenotary opened this issue Feb 4, 2025 · 4 comments
Assignees

Comments

@valenotary
Copy link

What is your question?

We are in the middle of migrating over to Conan2 -- we originally had some method override for the imports() method that we naively just moved to generate(). However, we're noticing now that the generate() method is not being executed (i.e. just for debugging, we tried putting some output logs in the generate method and just saw they werent being printed)... Are there any glaring pieces I might be missing in my understanding of how to migrate this/use generate() properly? Maybe my usecase might need some additional steps beyond changing just the method name?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Feb 4, 2025
@memsharded
Copy link
Member

Hi @valenotary

Thanks for your question

The generate() method executes for every conan install command in the "consumer" side, but also before every build() in the Conan cache.

Could you please provide something that we can reproduce on our side? Like some minimal conanfile.py and the commands to reproduce? Thanks for the feedback!

@valenotary
Copy link
Author

valenotary commented Feb 4, 2025

@memsharded thanks for the quick response!

I apologize, I can't share the code exactly because it's private for work, and I'm not sure if a minimal example would exactly recreate it. I can however describe more of the setup (and specifically what might be weird):

  • in our usecase, we have recipe A. This recipe always get exported first.
  • Within recipe A, we have two kinds of nested class definitions that we use in other recipes (B, C, etc.) via python_requires. As far as I can tell, the generate methods in those nested class definitions do work in the child recipes that declare their dependency on them via python_requires.
  • I think the weird part about this issue is that the problematic generate call isn't in either of those nested class definitions, but in the base class recipe A defines.

Based on that last part... I am assuming because no recipe explicitly depends on A, but instead the nested classes within them, that A's generate() method doesn't get invoked ? Does that sound like something that would have worked on Conan1 but not Conan2?

Please let me know if there's anything more I can explain.

@memsharded
Copy link
Member

Based on that last part... I am assuming because no recipe explicitly depends on A, but instead the nested classes within them, that A's generate() method doesn't get invoked ? Does that sound like something that would have worked on Conan1 but not Conan2?

No, this python_requires hasn't changed that much in Conan 2, it should be pretty similar.

Could you please outline the A, B, C classes, how it looks like regarding the inheritance, is it using python_requires_extend?
Some skeleton recipes, without much code, just the classes and generate() methods to illustrate, will help.

@valenotary
Copy link
Author

Okay, I'll try my best. Also you were right, my apologies: We call python_requires on the actual recipe, but python_requires_extend on the nested classes within RecipeAConanFile.

# relevant conan and os imports 
# ... 

class RecipeAConanFile(ConanFile):
   name = "RecipeA"
   # ... other recipe attributes
  
   def generate(self):
      # print statements and other copying SHOULD be happening here, but doesnt 

   # ... other methods like requirements, init, etc

   class NestedModule(object):
      # other typical conanfile attributes and methods. we call python_requires to THIS nested class
      # generate is also defined in this base nested class, and gets invoked properly during conan command

And an example of a child recipe that would depend on stuff from recipe A (specifically, NestedModule):

# relevant conan and os imports 
# ... 

class RecipeBConanFile(ConanFile):
   python_requires = "RecipeA"
   python_requires_extend = "RecipeA.NestedModule"

So recipes B, C, ... etc. will basically have the first two members (python_requires, python_requires_extends) be the same.

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