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