question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature] Please provide all methods in base ConanFile

See original GitHub issue

Currently, ConanFile base class doesn’t provide methods which need to be overridden by user (for example package()), this makes writing mixins which add different steps to “common” flow harder.

Consider example:


class MixinHeaders(ConanFile):
    def package():
        super().package() # < See below
        self.copy("*.h")

class MixinLibraries(ConanFile):
    def package():
        super().package() # < See below
        self.copy("*.so*");

# Consumer:
class MyConan(ConanFIle):
    python_requires_extend = ["shared.MixinHeaders", "shared.MixinLibraries"]

As I understand, in order for this to work with arbitrary set of mixins all of them should call super().package() (something called MRO involved). The problem is that for one of them super() will be ConanFile which doesn’t have package() and recipe fails with AttributeError.

To work this around I had to use something like in every mixin:

try:
    super_package = getattr(super(), "package")
except AttributeError:
    pass
else:
    super_package()

which is bit ugly.

Maybe I get something wrong.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
memshardedcommented, Jul 8, 2022

I do agree that aggregation is to prefer. I just thought that since this mechanism is provided it should be used for these purposes. Was much skeptical myself about sharing python code as base classes when they were first introduced.

We introduced it because of high pressure by some users, but it is one of those features that we don’t love, because we feel that in general it adds little value (avoiding to type a couple of lines, 2 per method), but makes things more obscure (as you don’t know by reading a recipe if it is just missing a package_info() method, or it might be reusing an existing one from the base class, that you need to go elsewhere to read). So in that regard, it is fine that the feature is there, but we will try to limit its use as much as possible, and definitely try to limit it to simple cases.

0reactions
memshardedcommented, Jul 18, 2022

Sorry for late reply, was traveling…

No prob, thanks for the feedback.

Ok, the build_requires method made more sense, as it was not defined. In any case, if you can go explicit, we believe it is better in the midterm, even if not nasty super() tricks would be necessary, with multiple inheritance many different behaviors like order of evaluations, etc can easily bite you.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Methods — conan 1.44.1 documentation
Method used to retrieve the source code from any other external origin like github using $ git clone or just a regular download....
Read more >
Writing reusable base recipes for conan.io packages
Reusing the recipe is just simple python class inheritance, so all recipe methods ( source() , build() , etc) are available in your...
Read more >
Conan Package Manager for C++ in Practice - YouTube
By Jerry Wiltse, presented at Core C++ [online] meetup, March 2021. The slides can be found at http://bit.ly/ConanDemo, more links to Conan ...
Read more >
C/C++ Application Analysis - Sonatype Help
NEW IN RELEASE 86. The Conan coordinate-based matching feature provides the ability to scan and evaluate C/C++ dependencies found in either a conanfile.txt, ......
Read more >
I want to split conafile.py into two, with both files containing ...
I have two files(conanfile.py and parent_conanfile.py). conanfile.py from conans import ConanFile, CMake from parent_conanfile import ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found