From a91e234c90c4415e9ba5b69b2aaa3df6f4228f6d Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 5 Mar 2021 12:14:42 +0100 Subject: [PATCH] build: `get_version()` replaced with `set_version()` --- conanfile.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/conanfile.py b/conanfile.py index e3e7d95b..38d5582f 100644 --- a/conanfile.py +++ b/conanfile.py @@ -24,21 +24,12 @@ from conans import ConanFile, tools from conans.tools import Version, check_min_cppstd from conan.tools.cmake import CMakeToolchain, CMake, CMakeDeps from conans.errors import ConanInvalidConfiguration -import re +import os, re required_conan_version = ">=1.33.0" -def get_version(): - try: - content = tools.load("src/CMakeLists.txt") - version = re.search(r"project\([^\)]+VERSION (\d+\.\d+\.\d+)[^\)]*\)", content).group(1) - return version.strip() - except Exception: - return None - class UnitsConan(ConanFile): name = "mp-units" - version = get_version() homepage = "https://github.com/mpusz/units" description = "Physical Units library for C++" topics = ("units", "dimensions", "quantities", "dimensional-analysis", "physical-quantities", "physical-units", "system-of-units", "cpp23", "cpp20", "library", "quantity-manipulation") @@ -84,6 +75,11 @@ class UnitsConan(ConanFile): self._cmake.configure(source_folder="src") return self._cmake + def set_version(self): + content = tools.load(os.path.join(self.recipe_folder, "src/CMakeLists.txt")) + version = re.search(r"project\([^\)]+VERSION (\d+\.\d+\.\d+)[^\)]*\)", content).group(1) + self.version = version.strip() + def validate(self): compiler = self.settings.compiler version = Version(self.settings.compiler.version)