MCPcopy
hub / github.com/tqdm/tqdm / main

Function main

tqdm/cli.py:156–324  ·  view source on GitHub ↗

Parameters (internal use only) --------- fp : file-like object for tqdm argv : list (default: sys.argv[1:])

(fp=sys.stderr, argv=None)

Source from the content-addressed store, hash-verified

154
155
156def main(fp=sys.stderr, argv=None):
157 """
158 Parameters (internal use only)
159 ---------
160 fp : file-like object for tqdm
161 argv : list (default: sys.argv[1:])
162 """
163 if argv is None:
164 argv = sys.argv[1:]
165 try:
166 log_idx = argv.index('--log')
167 except ValueError:
168 for i in argv:
169 if i.startswith('--log='):
170 logLevel = i[len('--log='):]
171 break
172 else:
173 logLevel = 'INFO'
174 else:
175 # argv.pop(log_idx)
176 # logLevel = argv.pop(log_idx)
177 logLevel = argv[log_idx + 1]
178 logging.basicConfig(level=getattr(logging, logLevel),
179 format="%(levelname)s:%(module)s:%(lineno)d:%(message)s")
180
181 # py<3.13 doesn't dedent docstrings
182 d = (tqdm.__doc__ if sys.version_info < (3, 13)
183 else indent(tqdm.__doc__, " ")) + CLI_EXTRA_DOC
184
185 opt_types = dict(RE_OPTS.findall(d))
186 # opt_types['delim'] = 'chr'
187
188 for o in UNSUPPORTED_OPTS:
189 opt_types.pop(o)
190
191 log.debug(sorted(opt_types.items()))
192
193 # d = RE_OPTS.sub(r' --\1=<\1> : \2', d)
194 split = RE_OPTS.split(d)
195 opt_types_desc = zip(split[1::3], split[2::3], split[3::3])
196 d = ''.join(('\n --{0} : {2}{3}' if otd[1] == 'bool' else
197 '\n --{0}=<{1}> : {2}{3}').format(
198 otd[0].replace('_', '-'), otd[0], *otd[1:])
199 for otd in opt_types_desc if otd[0] not in UNSUPPORTED_OPTS)
200
201 help_short = "Usage:\n tqdm [--help | options]\n"
202 d = help_short + """
203Options:
204 -h, --help Print this help and exit.
205 -v, --version Print version and exit.
206""" + d.strip('\n') + '\n'
207
208 # opts = docopt(d, version=__version__)
209 if any(v in argv for v in ('-v', '--version')):
210 sys.stdout.write(__version__ + '\n')
211 sys.exit(0)
212 elif any(v in argv for v in ('-h', '--help')):
213 sys.stdout.write(d + '\n')

Callers 7

test_main_bytesFunction · 0.90
test_main_logFunction · 0.90
test_mainFunction · 0.90
test_manpathFunction · 0.90
test_comppathFunction · 0.90
test_exceptionsFunction · 0.90
__main__.pyFile · 0.70

Calls 8

castFunction · 0.85
TqdmKeyErrorClass · 0.85
cpFunction · 0.85
posix_pipeFunction · 0.85
callbackFunction · 0.85
exitMethod · 0.80
tqdmClass · 0.70
writeMethod · 0.45

Tested by 6

test_main_bytesFunction · 0.72
test_main_logFunction · 0.72
test_mainFunction · 0.72
test_manpathFunction · 0.72
test_comppathFunction · 0.72
test_exceptionsFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…