Closed Chris7 closed 8 years ago
Everything needs to be redone to do this correctly. I'm going to do a PR to get the api generic prior to the release of Wooey, then we can add in extra parsers.
Here is how I believe it should be done: 1) collect all parsers (subparsers, etc.) 2) collect all containers/groups 3) collect all arguments of those groups/containers
Currently we operate in reverse -- we get a parser, then find its arguments, then what container it is.
For support for other parsers (click, etc.) and for other languages, it would probably be a good idea define parser classes with attributes defining a few tests prior to attempting to parse, e.g.
class BaseParser(object):
extensions = []
regex = ''
def check_valid(script_path, script_src):
return os.path.splitext(script_path) in self.extensions and self.contains in script_src
class PythonParser(BaseParser):
extensions = ['.py'] # Check file extensions in this
class PythonArgParse(PythonParser):
contains = 'argparse' # Check file contains this
def parse()
pass
class PythonArgParse(PythonParser):
contains = '@click' # Check file contains this
def parse()
pass
class RParser(BaseParser):
extensions = ['.R', '.RScript'] # Check file extensions in this
class RArgParse(RParser):
def parse()
pass
parsers = [
PythonArgParse,
PythonClick,
RArgParse,
]
script_path = '...'
with open(script_path, 'r') as f:
script_src = f.read()
for parser in parsers:
if parser.check_valid(script_path, script_src)
break
else:
# Could not find parser
return False
return parser.parse(script_path, script_src)
@Chris should this be closed now the generic parser backend is in?
Yeah, I would need to rework all this anyways.
This is the beginning work on a generic parser interface that will provide a general framework for adding additional argument parsers.