Commit b36b8e87 authored by Daniel Speckhard's avatar Daniel Speckhard
Browse files

static check fixes.

parent f0e4d4a1
Pipeline #45231 passed with stages
in 28 minutes and 9 seconds
Subproject commit bab03a285bac95ee7c3d01727537065c8ae7f4d6
Subproject commit b03240e3d78b7e4f58974252e7d845229ec81188
Subproject commit cbd073af089103951ee5b267ab064b00442b3cfc
Subproject commit f5be159e49f643d220497726da9801138ed615c3
......@@ -150,7 +150,7 @@ parsers = [
r'^(.*\n)*'
r'?\s*Invoking FHI-aims \.\.\.'
r'?\s*Version'),
mainfile_name_re= r'^.(?!.*phonopy-FHI-aims-displacement)'
mainfile_name_re=r'^.(?!.*phonopy-FHI-aims-displacement)'
),
LegacyParser(
name='parsers/cp2k',
......@@ -244,14 +244,13 @@ parsers = [
LegacyParser(
name='parsers/gaussian',
parser_class_name='gaussianparser.GaussianParser',
mainfile_contents_re=
# This previous file matching string was too far down the line.
# r'\s*Cite this work as:'
# r'\s*Gaussian [0-9]+, Revision [A-Za-z0-9.]*,'
# r'\s\*\*\*\*\*\*\*\*\*\*\*\**'
# r'\s*Gaussian\s*([0-9]+):\s*([A-Za-z0-9-.]+)\s*([0-9][0-9]?\-[A-Z][a-z][a-z]\-[0-9]+)'
# r'\s*([0-9][0-9]?\-[A-Z][a-z][a-z]\-[0-9]+)')
r'Gaussian, Inc'),
# This previous file matching string was too far down the line.
# r'\s*Cite this work as:'
# r'\s*Gaussian [0-9]+, Revision [A-Za-z0-9.]*,'
# r'\s\*\*\*\*\*\*\*\*\*\*\*\**'
# r'\s*Gaussian\s*([0-9]+):\s*([A-Za-z0-9-.]+)\s*([0-9][0-9]?\-[A-Z][a-z][a-z]\-[0-9]+)'
# r'\s*([0-9][0-9]?\-[A-Z][a-z][a-z]\-[0-9]+)')
mainfile_contents_re=r'Gaussian, Inc'),
LegacyParser(
name='parsers/quantumespresso',
parser_class_name='quantumespressoparser.QuantumEspressoParserPWSCF',
......
......@@ -59,7 +59,7 @@ class TemplateParser(ArtificalParser):
"""
name = 'parsers/template'
def is_mainfile(self, filename: str, mime: str, buffer: str, compression: str = None) -> bool:
def is_mainfile(self, filename: str, mime: str, buffer: bytes, compression: str = None) -> bool:
return filename.endswith('template.json')
def transform_value(self, name, value):
......@@ -127,7 +127,7 @@ class ChaosParser(ArtificalParser):
"""
name = 'parsers/chaos'
def is_mainfile(self, filename: str, mime: str, buffer: str, compression: str = None) -> bool:
def is_mainfile(self, filename: str, mime: str, buffer: bytes, compression: str = None) -> bool:
return filename.endswith('chaos.json')
def run(self, mainfile: str, logger=None) -> LocalBackend:
......@@ -189,7 +189,7 @@ class GenerateRandomParser(TemplateParser):
self.template = json.load(open(template_file, 'r'))
self.random = None
def is_mainfile(self, filename: str, mime: str, buffer: str, compression: str = None) -> bool:
def is_mainfile(self, filename: str, mime: str, buffer: bytes, compression: str = None) -> bool:
return os.path.basename(filename).startswith('random_')
def transform_section(self, name, section):
......
......@@ -34,7 +34,7 @@ class Parser(metaclass=ABCMeta):
"""
@abstractmethod
def is_mainfile(self, filename: str, mime: str, buffer: str, compression: str = None) -> bool:
def is_mainfile(self, filename: str, mime: str, buffer: bytes, compression: str = None) -> bool:
"""
Checks if a file is a mainfile for the parsers.
......@@ -88,19 +88,21 @@ class LegacyParser(Parser):
self.parser_class_name = parser_class_name
self._mainfile_mime_re = re.compile(mainfile_mime_re)
self._mainfile_name_re = re.compile(mainfile_name_re)
self._mainfile_contents_re = mainfile_contents_re
if self._mainfile_contents_re is not None:
self._mainfile_contents_re = re.compile(self._mainfile_contents_re)
# Assign private variable this way to avoid static check issue.
if mainfile_contents_re is not None:
self._mainfile_contents_re = re.compile(mainfile_contents_re)
else:
self._mainfile_contents_re = None
self._supported_compressions = supported_compressions
def is_mainfile(self, filename: str, mime: str, buffer: bytes, compression: str = None) -> bool:
if self._mainfile_contents_re is not None:
try: # Try to open the file as a string for regex matching.
buffer = buffer.decode('utf-8')
decoded_buffer = buffer.decode('utf-8')
except UnicodeDecodeError:
return False # We're looking for a string match in a file that can't be converted to string.
if self._mainfile_contents_re.search(buffer) is None:
if self._mainfile_contents_re.search(decoded_buffer) is None:
return False
return self._mainfile_mime_re.match(mime) is not None and \
......
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