conan-io / conan-io/docs

[question] python_requires attributes and additional files

Open
#4,086 6 comments 0 reactions 1 assignee Claimed by @memsharded View on GitHub
type: question
Dominant language
C++
Stars
125
Forks
382
Avg merge
22h 39m
Merged PRs (30d)
21

Description

### What is your question?

Hi,

I have two questions regarding [`python_requires` packages](https://docs.conan.io/2/reference/extensions/python_requires.html).
For context: We have a bunch of Conan packages that are build in the same way. They use the same `CMakeLists.txt` and the same `conanfile.py`. Everything that's different for these packages is handled by Conan/CMake internally (e.g. via `set_name()` and `set_version()` and similar stuff). In order to not duplicate that, a very minimal `conanfile.py` should be used for such stuff, the logic (for both Conan and CMake) should be imported from a central place (another Conan package) instead.

* The attributes seems to be inherited, even if docs say they aren't. Is that expected? Should I put it into the [`init()`](https://docs.conan.io/2/reference/conanfile/methods/init.html) method nevertheless?
From [`python_requires`: Extending base classes](https://docs.conan.io/2/reference/extensions/python_requires.html#extending-base-classes):
> In general, base class attributes are not inherited, and should be avoided as much as possible.

* However, this seems to work without problems in my case (see below).
* Can a `python_requires` package also contain some additional files? (like the mentioned `CMakeLists.txt`).
Putting that in a separate package (with [`package_type = "build-scripts"`](https://docs.conan.io/2/reference/conanfile/attributes.html#package-type) would just complicate things, as the versions must match and that needs additional thoughts. The `package_info()` stuff should work. Maybe couple with `build_policy = "missing"`?
(I know `conan create` doesn't build a package and there are no settings/options, but that's not required for my build scripts anyway.)

`conanfile.py` of `base/1.0`:
```py
from conan import ConanFile

class GenericRecipe:
user = "our-user"

description = "our description"
license = "our license"

settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": True, "fPIC": True}

exports_sources = ""

def export(self):
# ...

# other methods follow here ...

class Recipe(ConanFile):
name = "base"
version = "1.0"
package_type = "python-require"
```

`conanfile.py` at every location:
```py
from conan import ConanFile

class Recipe(ConanFile):
python_requires = "base/1.0"
python_requires_extend = "base.GenericRecipe"
```

### Have you read the CONTRIBUTING guide?

- [x] I've read the CONTRIBUTING guide

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.