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)
| 154 | |
| 155 | |
| 156 | def 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 | |
| 205 | if __name__ == '__main__': |
no test coverage detected