text
stringlengths 0
828
|
|---|
short = shorts[param]
|
else:
|
if param not in special_flags and len(param) > 1:
|
first_char = param[0]
|
if first_char not in used_shorts:
|
used_shorts.add(first_char)
|
short = '-' + first_char
|
# -h conflicts with 'help'
|
if short and short != '-h':
|
args = [short] + args
|
kwargs = {'default': default, 'dest': param.replace(""-"", ""_"")}
|
if param == 'version':
|
kwargs['action'] = 'version'
|
kwargs['version'] = module_version(func)
|
elif default is True:
|
kwargs['action'] = 'store_false'
|
elif default is False:
|
kwargs['action'] = 'store_true'
|
elif isinstance(default, list):
|
kwargs['action'] = 'append'
|
# default is not working
|
# if len(default):
|
# first = default[0]
|
# if type(first) in [type(None), unicode]:
|
# kwargs['type'] = unidecode
|
# else:
|
# kwargs['type'] = type(first)
|
# kwargs['default'] = []
|
# else:
|
kwargs['type'] = unidecode
|
else:
|
kwargs['action'] = 'store'
|
if type(default) in [type(None), unicode]:
|
kwargs['type'] = unidecode
|
else:
|
kwargs['type'] = type(default)
|
if param in helps:
|
kwargs['help'] = helps[param]
|
if param in metavars:
|
kwargs['metavar'] = metavars[param]
|
parser.add_argument(*args, **kwargs)
|
# Compulsary positional options
|
for need in needed:
|
kwargs = {'action': 'store', 'type': unidecode}
|
if need in helps:
|
kwargs['help'] = helps[need]
|
if need in shorts:
|
args = [shorts[need]]
|
else:
|
args = [need]
|
parser.add_argument(*args, **kwargs)
|
# The trailing arguments
|
if trail:
|
kwargs = {'action': 'store', 'type': unidecode, 'nargs': ""*""}
|
if trail in helps:
|
kwargs['help'] = helps[trail]
|
if trail in shorts:
|
kwargs['metavar'] = shorts[trail]
|
else:
|
kwargs['metavar'] = trail
|
parser.add_argument('__args', **kwargs)
|
return parser"
|
521,"def _correct_args(func, kwargs):
|
""""""
|
Convert a dictionary of arguments including __argv into a list
|
for passing to the function.
|
""""""
|
args = inspect.getargspec(func)[0]
|
return [kwargs[arg] for arg in args] + kwargs['__args']"
|
522,"def entrypoint(func):
|
""""""
|
A decorator for your main() function.
|
Really a combination of @autorun and @acceptargv, so will run the
|
function if __name__ == '__main__' with arguments extricated from
|
argparse.
|
As with @acceptargv, this must either be the innermost decorator, or
|
separated only by ""well-behaved"" decorators that preserve the __doc__
|
attribute AND the function signature.
|
As with @autorun, this must be theoutermost decorator, as any
|
decorators further out will not be applied to the function until after
|
it is run.
|
""""""
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.