From 627e6d6ab2f057eb4ef3e541014fa530e2f2422d Mon Sep 17 00:00:00 2001 From: Lukas Berbuer Date: Thu, 11 Jul 2024 17:31:38 +0200 Subject: [PATCH] fix: allow single quotes in conanfile.py --- src/conan_check_updates/conan.py | 13 +++++++++++-- tests/conanfile.py | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/conan_check_updates/conan.py b/src/conan_check_updates/conan.py index d381f39..d1f211b 100644 --- a/src/conan_check_updates/conan.py +++ b/src/conan_check_updates/conan.py @@ -173,6 +173,14 @@ def version_str() -> str: _REQUIRES_ATTRIBUTES = ("requires", "build_requires", "tool_requires", "test_requires") +def dequote(s: str) -> str: + """If a string has single or double quotes around it, remove them.""" + min_length = 2 + if (len(s) >= min_length and s[0] == s[-1]) and s.startswith(("'", '"')): + return s[1:-1] + return s + + def inspect_requirements_conanfile_py(conanfile: Path) -> List[ConanReference]: """Get requirements from requirements() method of conanfile.py""" assert conanfile.name == "conanfile.py" @@ -185,9 +193,10 @@ def inspect_requirements_conanfile_py(conanfile: Path) -> List[ConanReference]: # ignore empty line or line comments if not line or line.startswith("#"): continue - res = re.search(r'self\.(?:tool_)*requires\("(.*)"\)', line) + res = re.search(r"self\.(?:tool_)*requires\((.*)\)", line) if res: - ref = res.group(1) + args = res.group(1) + ref = dequote(args) if len(ref) > 0: refs.append(ref) return list(map(ConanReference.parse, refs)) diff --git a/tests/conanfile.py b/tests/conanfile.py index 56b56bd..3d1fc23 100644 --- a/tests/conanfile.py +++ b/tests/conanfile.py @@ -16,7 +16,7 @@ class Example(ConanFile): def requirements(self): self.requires("openssl/3.2.0") - self.requires("nanodbc/2.13.0") + self.requires('nanodbc/2.13.0') # fmt:off self.requires("ms-gsl/3.1.0") self.tool_requires("cmake/3.27.7") # self.requires("quill/3.6.0")