Merge pull request #2017 from codeflash-ai/codeflash/optimize-pr2015-2026-04-07T11.40.43
⚡️ Speed up function `_extract_modules_from_settings_gradle` by 23% in PR #2015 (`fix/gradle-maven-central-dependency`)
This commit is contained in:
commit
2a2125be9c
1 changed files with 13 additions and 5 deletions
|
|
@ -24,6 +24,12 @@ from typing import Any
|
||||||
from codeflash.code_utils.code_utils import get_run_tmp_file
|
from codeflash.code_utils.code_utils import get_run_tmp_file
|
||||||
from codeflash.languages.base import TestResult
|
from codeflash.languages.base import TestResult
|
||||||
|
|
||||||
|
_INCLUDE_PATTERN = re.compile(r"""(?:^|(?<=\s))include\s*\(?[^)\n]*\)?""", re.MULTILINE)
|
||||||
|
|
||||||
|
_LISTOF_PATTERN = re.compile(r"""listOf\s*\(([^)]*)\)""", re.DOTALL)
|
||||||
|
|
||||||
|
_QUOTED_PATTERN = re.compile(r"""['"]([^'"]+)['"]""")
|
||||||
|
|
||||||
_result_counter = itertools.count(1)
|
_result_counter = itertools.count(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -213,17 +219,19 @@ def _extract_modules_from_settings_gradle(content: str) -> list[str]:
|
||||||
modules: list[str] = []
|
modules: list[str] = []
|
||||||
# Standard include(...) directives — word boundary avoids matching variable names
|
# Standard include(...) directives — word boundary avoids matching variable names
|
||||||
# like 'includedProjects'
|
# like 'includedProjects'
|
||||||
for match in re.findall(r"""(?:^|(?<=\s))include\s*\(?[^)\n]*\)?""", content, re.MULTILINE):
|
for match in _INCLUDE_PATTERN.findall(content):
|
||||||
for name in re.findall(r"""['"]([^'"]+)['"]""", match):
|
for name in _QUOTED_PATTERN.findall(match):
|
||||||
modules.append(name.lstrip(":"))
|
modules.append(name.lstrip(":"))
|
||||||
# Kotlin DSL: val ... = listOf("module-a", "module-b", ...) spanning multiple lines.
|
# Kotlin DSL: val ... = listOf("module-a", "module-b", ...) spanning multiple lines.
|
||||||
# Used when settings.gradle.kts builds the include list dynamically.
|
# Used when settings.gradle.kts builds the include list dynamically.
|
||||||
if not modules or not any("/" not in m and "." not in m for m in modules):
|
if not modules or not any("/" not in m and "." not in m for m in modules):
|
||||||
for match in re.findall(r"""listOf\s*\(([^)]*)\)""", content, re.DOTALL):
|
seen = set(modules)
|
||||||
for name in re.findall(r"""['"]([^'"]+)['"]""", match):
|
for match in _LISTOF_PATTERN.findall(content):
|
||||||
|
for name in _QUOTED_PATTERN.findall(match):
|
||||||
stripped = name.lstrip(":")
|
stripped = name.lstrip(":")
|
||||||
if stripped not in modules:
|
if stripped not in seen:
|
||||||
modules.append(stripped)
|
modules.append(stripped)
|
||||||
|
seen.add(stripped)
|
||||||
return modules
|
return modules
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue