-
Notifications
You must be signed in to change notification settings - Fork 998
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
Comments
Hi @valenotary Thanks for your question The Could you please provide something that we can reproduce on our side? Like some minimal |
@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):
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 Please let me know if there's anything more I can explain. |
No, this Could you please outline the A, B, C classes, how it looks like regarding the inheritance, is it using |
Okay, I'll try my best. Also you were right, my apologies: We call # 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, # relevant conan and os imports
# ...
class RecipeBConanFile(ConanFile):
python_requires = "RecipeA"
python_requires_extend = "RecipeA.NestedModule" So recipes |
Thanks for the feedback. Please check the examples in: https://docs.conan.io/2/reference/extensions/python_requires.html#extending-base-classes, see how I am not even sure how it would work, the following test fails: def test_reuse_nested(self):
client = TestClient(light=True)
tool = textwrap.dedent("""
from conan import ConanFile
class MyConanfileBase(ConanFile):
name = "pkg"
version = "0.1"
class Nested:
def source(self):
self.output.info("My cool source!")
""")
reuse = textwrap.dedent("""
from conan import ConanFile
class PkgTest(ConanFile):
python_requires = "pkg/0.1"
python_requires_extend = "pkg.Nested"
""")
client.save({"tool/conanfile.py": tool,
"consumer/conanfile.py": reuse})
client.run("create tool")
client.run("source consumer") with
|
Oh my bad! I completely misread the indents in the recipe file. It looks like # imports
class RecipeA(ConanFile):
# stuff...
class ModuleA(object):
# this is still python_requires_extended on child recipes You are correct, the |
Thanks for the feedback. So if the def test_reuse_nested():
c = TestClient(light=True)
tool = textwrap.dedent("""
from conan import ConanFile
class MyConanfileBase(ConanFile):
name = "pkg"
version = "0.1"
class Nested:
def generate(self):
self.output.info("Generate inherited!!")
""")
reuse = textwrap.dedent("""
from conan import ConanFile
class PkgTest(ConanFile):
python_requires = "pkg/0.1"
python_requires_extend = "pkg.Nested"
""")
c.save({"tool/conanfile.py": tool,
"consumer/conanfile.py": reuse})
c.run("create tool")
c.run("install consumer")
assert "Generate inherited!!" in c.out So there might be some other thing, but I don't know what it could be, there might be some detail in your files that we are missing. |
So inside Also, my child recipes call |
There are different things there, the first point: def test_reuse_nested():
c = TestClient(light=True)
tool = textwrap.dedent("""
from conan import ConanFile
class MyConanfileBase(ConanFile):
name = "pkg"
version = "0.1"
def generate(self):
raise Exception("This is a python requrires, it doesn't generate when used!!")
class Nested:
def generate(self):
self.output.info("Generate inherited!!")
""")
reuse = textwrap.dedent("""
from conan import ConanFile
class PkgTest(ConanFile):
python_requires = "pkg/0.1"
python_requires_extend = "pkg.Nested"
""")
c.save({"tool/conanfile.py": tool,
"consumer/conanfile.py": reuse})
c.run("export tool") # If you use create, it will raise the generate
c.run("install consumer") # this doesn't raise!
assert "Generate inherited!!" in c.out This test still works. You can see the
You mean you are inheriting both from Please let me know if that helps, or what else could we be missing. |
Hmmm okay. I think maybe then we weren't using this correctly even in Conan 1 -- I'm gonna assume that the case where Just out of curiousity, is it just undefined if we inherit from both, or just rendundant, or something else? |
yes, the main problem is that the So even if it might work in some cases, it is strongly discouraged, see https://docs.conan.io/2/knowledge/guidelines.html
|
Hi @valenotary Any further question here? If not maybe the ticket can be closed? You can always open new tickets for any new issues. Thanks for your feedback. |
No that will be all thank you, feel free to close. I'll audit our usages of python_requires and try to keep it simple as the docs suggest. |
Great, thanks for the feedback! |
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?
The text was updated successfully, but these errors were encountered: