Skip to content

Commit e1504a1

Browse files
committed
fix(helper): Remove PyYAML dependency by using regex
Removes the PyYAML dependency from infra/helper.py to fix a ModuleNotFoundError in the indexer build tests, which run in a minimal environment. The language and base_os_version properties in the Project class were refactored to manually parse project.yaml using regex, restoring CI compatibility without losing functionality.
1 parent c0362f9 commit e1504a1

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

infra/helper.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import sys
3232
import tempfile
3333
import urllib.request
34-
import yaml
3534

3635
import constants
3736
import templates
@@ -91,6 +90,7 @@ def _get_base_runner_image(args, debug=False):
9190

9291
LANGUAGE_REGEX = re.compile(r'[^\s]+')
9392
PROJECT_LANGUAGE_REGEX = re.compile(r'\s*language\s*:\s*([^\s]+)')
93+
BASE_OS_VERSION_REGEX = re.compile(r'\s*base_os_version\s*:\s*([^\s]+)')
9494

9595
WORKDIR_REGEX = re.compile(r'\s*WORKDIR\s*([^\s]+)')
9696

@@ -161,9 +161,11 @@ def language(self):
161161
return constants.DEFAULT_LANGUAGE
162162

163163
with open(project_yaml_path) as file_handle:
164-
config = yaml.safe_load(file_handle)
165-
if config and 'language' in config:
166-
return config['language']
164+
content = file_handle.read()
165+
for line in content.splitlines():
166+
match = PROJECT_LANGUAGE_REGEX.match(line)
167+
if match:
168+
return match.group(1)
167169

168170
logger.warning('Language not specified in project.yaml. Assuming c++.')
169171
return constants.DEFAULT_LANGUAGE
@@ -177,11 +179,13 @@ def base_os_version(self):
177179
return 'legacy'
178180

179181
with open(project_yaml_path) as file_handle:
180-
config = yaml.safe_load(file_handle)
181-
version = 'legacy'
182-
if config and 'base_os_version' in config:
183-
version = config['base_os_version']
184-
return version
182+
content = file_handle.read()
183+
for line in content.splitlines():
184+
match = BASE_OS_VERSION_REGEX.match(line)
185+
if match:
186+
return match.group(1)
187+
188+
return 'legacy'
185189

186190
@property
187191
def coverage_extra_args(self):

0 commit comments

Comments
 (0)