Conan: How to compare version in conanfile.py ?

Created on 18 Oct 2018  路  3Comments  路  Source: conan-io/conan

In some conanfile.py, I would like to customize some steps depending on the version of the compiler (or some other elements). And I didn't find a proper way to compare versions.

Is it possible to add in Tools the version comparer that conan uses internally ?

Actually using conan 1.8.1

To help us debug your issue please explain:

  • [X] I've read the CONTRIBUTING guide.
  • [X] I've specified the Conan version, operating system version and any tool that can be relevant.
  • [X] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.
question

Most helpful comment

All 3 comments

Hi @dkgs !

one possible approach:

def configure(self):
    if self.settings.compiler == "gcc" and \
       float(settings.compiler.version.value) < 5:
        raise ConanInvalidConfiguration("This project does not support GCC < 5")

but there is a better approach:

from conans.model.version import Version

...

def configure(self):
    if self.settings.compiler == "gcc" and \
       Version(self.settings.compiler.version.value) < "5.0":
        raise ConanInvalidConfiguration("This project does not support GCC < 5")

Waow I completely missed that part !

Thansk !

Was this page helpful?
0 / 5 - 0 ratings