MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / main

Function main

tools/python-3.11.9-amd64/Lib/zipapp.py:156–202  ·  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

154
155
156def main(args=None):
157 """Run the zipapp command line interface.
158
159 The ARGS parameter lets you specify the argument list directly.
160 Omitting ARGS (or setting it to None) works as for argparse, using
161 sys.argv[1:] as the argument list.
162 """
163 import argparse
164
165 parser = argparse.ArgumentParser()
166 parser.add_argument('--output', '-o', default=None,
167 help="The name of the output archive. "
168 "Required if SOURCE is an archive.")
169 parser.add_argument('--python', '-p', default=None,
170 help="The name of the Python interpreter to use "
171 "(default: no shebang line).")
172 parser.add_argument('--main', '-m', default=None,
173 help="The main function of the application "
174 "(default: use an existing __main__.py).")
175 parser.add_argument('--compress', '-c', action='store_true',
176 help="Compress files with the deflate method. "
177 "Files are stored uncompressed by default.")
178 parser.add_argument('--info', default=False, action='store_true',
179 help="Display the interpreter from the archive.")
180 parser.add_argument('source',
181 help="Source directory (or existing archive).")
182
183 args = parser.parse_args(args)
184
185 # Handle `python -m zipapp archive.pyz --info`.
186 if args.info:
187 if not os.path.isfile(args.source):
188 raise SystemExit("Can only get info for an archive file")
189 interpreter = get_interpreter(args.source)
190 print("Interpreter: {}".format(interpreter or "<none>"))
191 sys.exit(0)
192
193 if os.path.isfile(args.source):
194 if args.output is None or (os.path.exists(args.output) and
195 os.path.samefile(args.source, args.output)):
196 raise SystemExit("In-place editing of archives is not supported")
197 if args.main:
198 raise SystemExit("Cannot change the main function when copying")
199
200 create_archive(args.source, args.output,
201 interpreter=args.python, main=args.main,
202 compressed=args.compress)
203
204
205if __name__ == '__main__':

Callers 1

zipapp.pyFile · 0.70

Calls 10

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

Tested by

no test coverage detected