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.

[question] Extending settings and options with new `python_requires` syntax

See original GitHub issue

I am trying to migrate my recipes to use the new python_requires syntax as described in the documentation.

However, I cannot find a way to correctly extend or override options and settings from the base conanfile.

In the old python_requires, I used to do this:

from conans import python_requires, tools

base = python_requires('MyBaseConanFile/1.0.0@company/stable')

class MyPackage(base.MyBaseConanFile):
    settings = ("os_build", "arch_build") + base.MyBaseConanFile.settings
    options = dict(base.MyBaseConanFile.options, **{
        'another_option': [True, False]
    })
    default_options = dict(base.MyBaseConanFile.default_options, **{
        'another_option': True
    })

How to achieve the same with the new syntax?

The following does not work:


class MyPackage(ConanFile):
    python_requires = 'MyBaseConanFile/1.0.0@company/stable'
    python_requires_extend = "MyBaseConanFile.MyBaseConanFile"
 
    options = dict(self.python_requires_extend['MyBaseConanFile.MyBaseConanFile'].options, **{
        'another_option': [True, False]
    })

The self is not available in class attribute context. The documentation says nothing about that case. Is this even possible with the new syntax?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
memshardedcommented, Mar 24, 2020

init() method for this will be released in Conan 1.24

1reaction
DoDoENTcommented, Mar 3, 2020

Just a side note: Until this gets resolved, I managed to create a forward-compatible base conanfile which works with both the current version of python_requires and should work with the new syntax:

Base conanfile:

class MyBaseConanFile(object):
    options = {
        'base_option': [True, False]
    }
    settings = "os", "compiler", "build_type", "arch"

class MyBaseConanFilePkg(ConanFile):
    name = "MyBaseConanFile"
    version = "1.0.0"

and the usage in current models is as follows (notice the multiple inheritance):


from conans import python_requires, ConanFile

base = python_requires('MyBaseConanFile/1.0.0@company/stable')

class MyPackage(base.MyBaseConanFile, ConanFile):
    settings = ("os_build", "arch_build") + base.MyBaseConanFile.settings
    options = dict(base.MyBaseConanFile.options, **{
        'another_option': [True, False]
    })
    default_options = dict(base.MyBaseConanFile.default_options, **{
        'another_option': True
    })

and the (expected) future usage would be something like:

class MyPackage(ConanFile):
    python_requires = 'MyBaseConanFile/1.0.0@company/stable'
    python_requires_extend = "MyBaseConanFile.MyBaseConanFile"
 
    @classmethod
    def python_require_extend_class(cls, c):
        cls.options = c.options + cls.options
        cls.settings = c.settings + cls.settings

    options = {
        'another_option': [True, False]
    }
    settings = "os_build", "arch_build"
Read more comments on GitHub >

github_iconTop Results From Across the Web

2. Writing the Setup Script — Python 3.11.1 documentation
The setup script is the centre of all activity in building, distributing, and installing modules using the Distutils. The main purpose of the...
Read more >
What's New In Python 3.10 — Python 3.11.1 documentation
For full details, see the changelog. Summary – Release highlights¶. New syntax features: PEP 634, Structural Pattern Matching: Specification.
Read more >
typing — Support for type hints — Python 3.11.1 documentation
New features are frequently added to the typing module. ... Introducing syntax for annotating variables outside of function definitions, and ClassVar.
Read more >
What's New In Python 3.8 — Python 3.11.1 documentation
There is a new function parameter syntax / to indicate that some function parameters must be specified positionally and cannot be used as...
Read more >
7. Simple statements — Python 3.11.1 documentation
(See section Primaries for the syntax definitions for attributeref, subscription, and slicing.) An assignment statement evaluates the expression list (remember ...
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