Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/virtualenv/__main__.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
1 from __future__ import absolute_import, print_function, unicode_literals | |
2 | |
3 import logging | |
4 import sys | |
5 from datetime import datetime | |
6 | |
7 | |
8 def run(args=None, options=None): | |
9 start = datetime.now() | |
10 from virtualenv.run import cli_run | |
11 from virtualenv.util.error import ProcessCallFailed | |
12 | |
13 if args is None: | |
14 args = sys.argv[1:] | |
15 try: | |
16 session = cli_run(args, options) | |
17 logging.warning(LogSession(session, start)) | |
18 except ProcessCallFailed as exception: | |
19 print("subprocess call failed for {} with code {}".format(exception.cmd, exception.code)) | |
20 print(exception.out, file=sys.stdout, end="") | |
21 print(exception.err, file=sys.stderr, end="") | |
22 raise SystemExit(exception.code) | |
23 | |
24 | |
25 class LogSession(object): | |
26 def __init__(self, session, start): | |
27 self.session = session | |
28 self.start = start | |
29 | |
30 def __str__(self): | |
31 from virtualenv.util.six import ensure_text | |
32 | |
33 spec = self.session.creator.interpreter.spec | |
34 elapsed = (datetime.now() - self.start).total_seconds() * 1000 | |
35 lines = [ | |
36 "created virtual environment {} in {:.0f}ms".format(spec, elapsed), | |
37 " creator {}".format(ensure_text(str(self.session.creator))), | |
38 ] | |
39 if self.session.seeder.enabled: | |
40 lines += ( | |
41 " seeder {}".format(ensure_text(str(self.session.seeder))), | |
42 " added seed packages: {}".format( | |
43 ", ".join( | |
44 sorted( | |
45 "==".join(i.stem.split("-")) | |
46 for i in self.session.creator.purelib.iterdir() | |
47 if i.suffix == ".dist-info" | |
48 ), | |
49 ), | |
50 ), | |
51 ) | |
52 if self.session.activators: | |
53 lines.append(" activators {}".format(",".join(i.__class__.__name__ for i in self.session.activators))) | |
54 return "\n".join(lines) | |
55 | |
56 | |
57 def run_with_catch(args=None): | |
58 from virtualenv.config.cli.parser import VirtualEnvOptions | |
59 | |
60 options = VirtualEnvOptions() | |
61 try: | |
62 run(args, options) | |
63 except (KeyboardInterrupt, SystemExit, Exception) as exception: | |
64 try: | |
65 if getattr(options, "with_traceback", False): | |
66 raise | |
67 else: | |
68 if not (isinstance(exception, SystemExit) and exception.code == 0): | |
69 logging.error("%s: %s", type(exception).__name__, exception) | |
70 code = exception.code if isinstance(exception, SystemExit) else 1 | |
71 sys.exit(code) | |
72 finally: | |
73 logging.shutdown() # force flush of log messages before the trace is printed | |
74 | |
75 | |
76 if __name__ == "__main__": # pragma: no cov | |
77 run_with_catch() # pragma: no cov |