MCPcopy Index your code
hub / github.com/python/cpython / main

Function main

Lib/zipapp.py:181–227  ·  view source on GitHub ↗

Run the zipapp command line interface. The ARGS parameter lets you specify the argument list directly. Omitting ARGS (or setting it to None) works as for argparse, using sys.argv[1:] as the argument list.

(args=None)

Source from the content-addressed store, hash-verified

179
180
181def main(args=None):
182 """Run the zipapp command line interface.
183
184 The ARGS parameter lets you specify the argument list directly.
185 Omitting ARGS (or setting it to None) works as for argparse, using
186 sys.argv[1:] as the argument list.
187 """
188 import argparse
189
190 parser = argparse.ArgumentParser(color=True)
191 parser.add_argument('--output', '-o', default=None,
192 help="The name of the output archive. "
193 "Required if SOURCE is an archive.")
194 parser.add_argument('--python', '-p', default=None,
195 help="The name of the Python interpreter to use "
196 "(default: no shebang line).")
197 parser.add_argument('--main', '-m', default=None,
198 help="The main function of the application "
199 "(default: use an existing __main__.py).")
200 parser.add_argument('--compress', '-c', action='store_true',
201 help="Compress files with the deflate method. "
202 "Files are stored uncompressed by default.")
203 parser.add_argument('--info', default=False, action='store_true',
204 help="Display the interpreter from the archive.")
205 parser.add_argument('source',
206 help="Source directory (or existing archive).")
207
208 args = parser.parse_args(args)
209
210 # Handle `python -m zipapp archive.pyz --info`.
211 if args.info:
212 if not os.path.isfile(args.source):
213 raise SystemExit("Can only get info for an archive file")
214 interpreter = get_interpreter(args.source)
215 print("Interpreter: {}".format(interpreter or "<none>"))
216 sys.exit(0)
217
218 if os.path.isfile(args.source):
219 if args.output is None or (os.path.exists(args.output) and
220 os.path.samefile(args.source, args.output)):
221 raise SystemExit("In-place editing of archives is not supported")
222 if args.main:
223 raise SystemExit("Cannot change the main function when copying")
224
225 create_archive(args.source, args.output,
226 interpreter=args.python, main=args.main,
227 compressed=args.compress)
228
229
230if __name__ == '__main__':

Callers 1

zipapp.pyFile · 0.70

Calls 9

parse_argsMethod · 0.95
get_interpreterFunction · 0.85
create_archiveFunction · 0.85
samefileMethod · 0.80
add_argumentMethod · 0.45
isfileMethod · 0.45
formatMethod · 0.45
exitMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…