MCPcopy
hub / github.com/mne-tools/mne-python / get_optparser

Function get_optparser

mne/commands/utils.py:51–81  ·  view source on GitHub ↗

Create OptionParser with cmd specific settings (e.g., prog value).

(cmdpath, usage=None, prog_prefix="mne", version=None)

Source from the content-addressed store, hash-verified

49
50
51def get_optparser(cmdpath, usage=None, prog_prefix="mne", version=None):
52 """Create OptionParser with cmd specific settings (e.g., prog value)."""
53 # Fetch description
54 mod = load_module("__temp", cmdpath)
55 if mod.__doc__:
56 doc, description, epilog = mod.__doc__, None, None
57
58 doc_lines = doc.split("\n")
59 description = doc_lines[0]
60 if len(doc_lines) > 1:
61 epilog = "\n".join(doc_lines[1:])
62
63 # Get the name of the command
64 command = os.path.basename(cmdpath)
65 command, _ = os.path.splitext(command)
66 command = command[len(prog_prefix) + 1 :] # +1 is for `_` character
67
68 # Set prog
69 prog = prog_prefix + f" {command}"
70
71 # Set version
72 if version is None:
73 version = mne.__version__
74
75 # monkey patch OptionParser to not wrap epilog
76 OptionParser.format_epilog = lambda self, formatter: self.epilog
77 parser = OptionParser(
78 prog=prog, version=version, description=description, epilog=epilog, usage=usage
79 )
80
81 return parser
82
83
84def main():

Callers 15

runFunction · 0.90
runFunction · 0.90
runFunction · 0.90
runFunction · 0.90
runFunction · 0.90
runFunction · 0.90
runFunction · 0.90
runFunction · 0.90
runFunction · 0.90
runFunction · 0.90
runFunction · 0.90
runFunction · 0.90

Calls 2

load_moduleFunction · 0.85
splitMethod · 0.80

Tested by

no test coverage detected