Skip to content

Commit

Permalink
fix: allow single quotes in conanfile.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasberbuer committed Jul 11, 2024
1 parent ac171ef commit 627e6d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/conan_check_updates/conan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion tests/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 627e6d6

Please sign in to comment.