Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

significantly speed up parsing of easyconfig files by only extracting comments from an easyconfig file when they're actually needed #3498

Merged
merged 2 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion easybuild/framework/easyconfig/format/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,17 @@ def __init__(self):
raise EasyBuildError('Invalid version number %s (incorrect length)', self.VERSION)

self.rawtext = None # text version of the easyconfig
self.comments = {} # comments in easyconfig file
self._comments = {} # comments in easyconfig file
self.header = None # easyconfig header (e.g., format version, license, ...)
self.docstring = None # easyconfig docstring (e.g., author, maintainer, ...)

self.specs = {}

@property
def comments(self):
"""Return comments in easyconfig file"""
return self._comments

def set_specifications(self, specs):
"""Set specifications."""
self.log.debug('Set copy of specs %s' % specs)
Expand Down
15 changes: 13 additions & 2 deletions easybuild/framework/easyconfig/format/one.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ def parse(self, txt):
"""
Pre-process txt to extract header, docstring and pyheader, with non-indented section markers enforced.
"""
super(FormatOneZero, self).parse(txt, strict_section_markers=True)
self.rawcontent = txt
super(FormatOneZero, self).parse(self.rawcontent, strict_section_markers=True)

def _reformat_line(self, param_name, param_val, outer=False, addlen=0):
"""
Expand Down Expand Up @@ -356,14 +357,24 @@ def dump(self, ecfg, default_values, templ_const, templ_val, toolchain_hierarchy

return '\n'.join(dump)

@property
def comments(self):
"""
Return comments (and extract them first if needed).
"""
if not self._comments:
self.extract_comments(self.rawcontent)

return self._comments

def extract_comments(self, rawtxt):
"""
Extract comments from raw content.

Discriminates between comment header, comments above a line (parameter definition), and inline comments.
Inline comments on items of iterable values are also extracted.
"""
self.comments = {
self._comments = {
'above': {}, # comments above a parameter definition
'header': [], # header comment lines
'inline': {}, # inline comments
Expand Down
2 changes: 0 additions & 2 deletions easybuild/framework/easyconfig/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ def __init__(self, filename=None, format_version=None, rawcontent=None,
else:
raise EasyBuildError("Neither filename nor rawcontent provided to EasyConfigParser")

self._formatter.extract_comments(self.rawcontent)

def process(self, filename=None):
"""Create an instance"""
self._read(filename=filename)
Expand Down