comparison env/lib/python3.7/site-packages/virtualenv/session.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
1 from __future__ import absolute_import, unicode_literals
2
3 import json
4 import logging
5
6 from virtualenv.util.six import ensure_text
7
8
9 class Session(object):
10 """Represents a virtual environment creation session"""
11
12 def __init__(self, verbosity, app_data, interpreter, creator, seeder, activators):
13 self._verbosity = verbosity
14 self._app_data = app_data
15 self._interpreter = interpreter
16 self._creator = creator
17 self._seeder = seeder
18 self._activators = activators
19
20 @property
21 def verbosity(self):
22 """The verbosity of the run"""
23 return self._verbosity
24
25 @property
26 def interpreter(self):
27 """Create a virtual environment based on this reference interpreter"""
28 return self._interpreter
29
30 @property
31 def creator(self):
32 """The creator used to build the virtual environment (must be compatible with the interpreter)"""
33 return self._creator
34
35 @property
36 def seeder(self):
37 """The mechanism used to provide the seed packages (pip, setuptools, wheel)"""
38 return self._seeder
39
40 @property
41 def activators(self):
42 """Activators used to generate activations scripts"""
43 return self._activators
44
45 def run(self):
46 self._create()
47 self._seed()
48 self._activate()
49 self.creator.pyenv_cfg.write()
50
51 def _create(self):
52 logging.info("create virtual environment via %s", ensure_text(str(self.creator)))
53 self.creator.run()
54 logging.debug(_DEBUG_MARKER)
55 logging.debug("%s", _Debug(self.creator))
56
57 def _seed(self):
58 if self.seeder is not None and self.seeder.enabled:
59 logging.info("add seed packages via %s", self.seeder)
60 self.seeder.run(self.creator)
61
62 def _activate(self):
63 if self.activators:
64 logging.info(
65 "add activators for %s", ", ".join(type(i).__name__.replace("Activator", "") for i in self.activators)
66 )
67 for activator in self.activators:
68 activator.generate(self.creator)
69
70 def __enter__(self):
71 return self
72
73 def __exit__(self, exc_type, exc_val, exc_tb):
74 self._app_data.close()
75
76
77 _DEBUG_MARKER = "=" * 30 + " target debug " + "=" * 30
78
79
80 class _Debug(object):
81 """lazily populate debug"""
82
83 def __init__(self, creator):
84 self.creator = creator
85
86 def __unicode__(self):
87 return ensure_text(repr(self))
88
89 def __repr__(self):
90 return json.dumps(self.creator.debug, indent=2)