Commit 25829697 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed broken parser matching for gpaw2.

parent 5651ac5e
......@@ -23,6 +23,7 @@ def parse(
logger = utils.get_logger(__name__)
if parser_name is not None:
parser = parser_dict.get(parser_name)
assert parser is not None, 'the given parser must exist'
else:
parser = match_parser(mainfile, upload_files, strict=strict)
if isinstance(parser, MatchingParser):
......@@ -94,10 +95,11 @@ def normalize_all(parser_backend: LocalBackend = None, logger=None) -> LocalBack
@click.option('--show-metadata', is_flag=True, default=False, help='Print the extracted repo metadata.')
@click.option('--skip-normalizers', is_flag=True, default=False, help='Do not run the normalizer.')
@click.option('--not-strict', is_flag=True, help='Do also match artificial parsers.')
def _parse(mainfile, show_backend, show_metadata, skip_normalizers, not_strict):
@click.option('--parser', help='Skip matching and use the provided parser')
def _parse(mainfile, show_backend, show_metadata, skip_normalizers, not_strict, parser):
utils.configure_logging()
backend = parse(mainfile, '.', strict=not not_strict)
backend = parse(mainfile, '.', strict=not not_strict, parser_name=parser)
if not skip_normalizers:
normalize_all(backend)
......
......@@ -313,18 +313,19 @@ parsers = [
# We decided to use the octopus eyes instead of
# r'\*{32} Grid \*{32}Simulation Box:' since it was so far down in the file.
),
# match gpaw2 first, other .gpw files are then considered to be "gpaw1"
LegacyParser(
name='parsers/gpaw2', code_name='GPAW',
parser_class_name='gpawparser.GPAWParser2Wrapper',
mainfile_binary_header=b'GPAW',
mainfile_name_re=(r'^.*\.(gpw2|gpw)$'),
mainfile_mime_re=r'application/(x-tar|octet-stream)'
),
LegacyParser(
name='parsers/gpaw', code_name='GPAW',
parser_class_name='gpawparser.GPAWParserWrapper',
mainfile_name_re=(r'^.*\.gpw$'),
mainfile_mime_re=r'application/x-tar'
),
LegacyParser(
name='parsers/gpaw2', code_name='GPAW',
parser_class_name='gpawparser.GPAWParser2Wrapper',
# mainfile_contents_re=r'', # We can't read .gpw2 to match AFFormatGPAW'
mainfile_name_re=(r'^.*\.gpw2$'),
mainfile_mime_re=r'application/x-tar'
mainfile_mime_re=r'application/(x-tar|octet-stream)'
),
LegacyParser(
name='parsers/atk', code_name='ATK',
......
......@@ -112,6 +112,7 @@ class MatchingParser(Parser):
def __init__(
self, name: str, code_name: str,
mainfile_contents_re: str = None,
mainfile_binary_header: bytes = None,
mainfile_mime_re: str = r'text/.*',
mainfile_name_re: str = r'.*',
domain='DFT',
......@@ -121,6 +122,7 @@ class MatchingParser(Parser):
self.name = name
self.code_name = code_name
self.domain = domain
self._mainfile_binary_header = mainfile_binary_header
self._mainfile_mime_re = re.compile(mainfile_mime_re)
self._mainfile_name_re = re.compile(mainfile_name_re)
# Assign private variable this way to avoid static check issue.
......@@ -131,6 +133,9 @@ class MatchingParser(Parser):
self._supported_compressions = supported_compressions
def is_mainfile(self, filename: str, mime: str, buffer: bytes, compression: str = None) -> bool:
if self._mainfile_binary_header is not None:
if self._mainfile_binary_header not in buffer:
return False
if self._mainfile_contents_re is not None:
try: # Try to open the file as a string for regex matching.
decoded_buffer = buffer.decode('utf-8')
......
......@@ -42,7 +42,7 @@ parser_examples = [
('parsers/nwchem', 'tests/data/parsers/nwchem/single_point/output.out'),
('parsers/bigdft', 'tests/data/parsers/bigdft/n2_output.out'),
('parsers/wien2k', 'tests/data/parsers/wien2k/AlN/AlN_ZB.scf'),
('parsers/band', 'tests/data/parsers/band_adf.out'), # causes spglib to segfault
('parsers/band', 'tests/data/parsers/band_adf.out'),
('parsers/gaussian', 'tests/data/parsers/gaussian/aniline.out'),
('parsers/abinit', 'tests/data/parsers/abinit/Fe.out'),
('parsers/quantumespresso', 'tests/data/parsers/quantum-espresso/benchmark.out'),
......@@ -77,7 +77,7 @@ for parser, mainfile in parser_examples:
parser_examples = fixed_parser_examples
correct_num_output_files = 41
correct_num_output_files = 43
class TestLocalBackend(object):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment