Skip to content

Commit

Permalink
- bugfix: reenable python parsers by turning simple mappings into lists
Browse files Browse the repository at this point in the history
- robustness: precheck to disable parsers quickly when their dependencies are not found
  • Loading branch information
spio committed Jul 2, 2018
1 parent 6aa3d1b commit 91cc181
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions snafulib/parsers/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import os
import subprocess

def precheck():
r = subprocess.run("java 2>/dev/null", shell=True)
if r.returncode == 127:
return False
return True

def activatefile(self, source, convention, SnafuFunctionSource):
if not os.path.isfile("snafulib/executors/java/JavaExec.class"):
pwd = os.getcwd()
Expand Down
17 changes: 12 additions & 5 deletions snafulib/snafu.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,19 @@ def __init__(self, quiet=False):
self.configpath = None

def setupparsers(self, parsers):
if not self.quiet:
for parser in parsers:
print("+ parser:", parser)

self.parsermods = []
for parser in parsers:
mod = importlib.import_module("snafulib.parsers." + parser)
self.parsermods.append(mod)
if "precheck" in dir(mod):
ok = mod.precheck()
if not self.quiet:
print("+ parser: {} ({})".format(parser, ("forced-disabled", "ok")[ok]))
if ok:
self.parsermods.append(mod)
else:
if not self.quiet:
print("+ parser: {}".format(parser))
self.parsermods.append(mod)

def setupexecutors(self, executors):
if not self.quiet:
Expand Down Expand Up @@ -410,6 +415,8 @@ def activate(self, sources, convention, ignore=False):
handled = False
needshandling = False
for suffixkey, suffixvalues in parsermapping.items():
if type(suffixvalues) != list:
suffixvalues = [suffixvalues]
for suffixvalue in suffixvalues:
if source.endswith("." + suffixvalue):
needshandling = True
Expand Down

0 comments on commit 91cc181

Please sign in to comment.