Skip to content

Commit

Permalink
conan: improve regex of parse static and dynamic requires
Browse files Browse the repository at this point in the history
conan: add inspect_pyreq_conanfile_py to parse python_requires

conan: improve regex of dynamic require functions

Test success:
self.tool_requires("hell")
self.python_requires("dep")
self.python_requires("dep", run=True)
self.requires("bal/2024.1.0-0.dev")

conan: inspect_requirements_conanfile_py should parse static and dynamic requires
  • Loading branch information
YasLbk authored and Yassine Lambarki committed Aug 12, 2024
1 parent 0d61110 commit fe8ca2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions src/conan_check_updates/conan.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,15 @@ 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|python)_)*requires\("(.*)"(?:(\)|,.*))', line)
if res is None:
res = re.search(r'(tool|python)_requires = "(.*)"', line)
if res:
args = res.group(1)
arg = args.partition(",")[0].strip() # get first argument -> reference string
ref = _dequote(arg)
ref = res.group(2)
if len(ref) > 0:
refs.append(ref)
return list(map(ConanReference.parse, refs))


def inspect_requires_conanfile_py(conanfile: Path) -> List[ConanReference]:
"""Get requirements of conanfile.py with `conan inspect`."""
assert conanfile.name == "conanfile.py"
Expand Down Expand Up @@ -263,9 +262,7 @@ def gen_requires():
def inspect_requires_conanfile(conanfile: Path) -> List[ConanReference]:
"""Get requirements of conanfile.py/conanfile.py"""
if conanfile.name == "conanfile.py":
return inspect_requires_conanfile_py(conanfile) + inspect_requirements_conanfile_py(
conanfile
)
return inspect_requires_conanfile_py(conanfile) + inspect_requirements_conanfile_py(conanfile)
if conanfile.name == "conanfile.txt":
return inspect_requires_conanfile_txt(conanfile)
raise ValueError(f"Invalid conanfile: {conanfile!s}")
Expand Down
2 changes: 1 addition & 1 deletion src/conan_check_updates/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def check_updates(
pkg_name += f"@{ref.user}"
if ref.channel:
pkg_name += f"/{ref.channel}"
print(pkg_name)
print(pkg_name)

if package_filter and package_filter[-1] == "filter":
refs = [ref for ref in refs if matches_any(ref.package, *package_filter)]
Expand Down

0 comments on commit fe8ca2d

Please sign in to comment.