Skip to content

Commit

Permalink
significantly speed up parsing of easyconfig files by only extracting…
Browse files Browse the repository at this point in the history
… comments from an easyconfig file when they're actually needed
  • Loading branch information
boegel committed Nov 8, 2020
1 parent 5046731 commit 7b3801e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
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

0 comments on commit 7b3801e

Please sign in to comment.