Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/virtualenv/pyenv_cfg.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 logging | |
4 from collections import OrderedDict | |
5 | |
6 from virtualenv.util.six import ensure_text | |
7 | |
8 | |
9 class PyEnvCfg(object): | |
10 def __init__(self, content, path): | |
11 self.content = content | |
12 self.path = path | |
13 | |
14 @classmethod | |
15 def from_folder(cls, folder): | |
16 return cls.from_file(folder / "pyvenv.cfg") | |
17 | |
18 @classmethod | |
19 def from_file(cls, path): | |
20 content = cls._read_values(path) if path.exists() else OrderedDict() | |
21 return PyEnvCfg(content, path) | |
22 | |
23 @staticmethod | |
24 def _read_values(path): | |
25 content = OrderedDict() | |
26 for line in path.read_text(encoding="utf-8").splitlines(): | |
27 equals_at = line.index("=") | |
28 key = line[:equals_at].strip() | |
29 value = line[equals_at + 1 :].strip() | |
30 content[key] = value | |
31 return content | |
32 | |
33 def write(self): | |
34 logging.debug("write %s", ensure_text(str(self.path))) | |
35 text = "" | |
36 for key, value in self.content.items(): | |
37 line = "{} = {}".format(key, value) | |
38 logging.debug("\t%s", line) | |
39 text += line | |
40 text += "\n" | |
41 self.path.write_text(text, encoding="utf-8") | |
42 | |
43 def refresh(self): | |
44 self.content = self._read_values(self.path) | |
45 return self.content | |
46 | |
47 def __setitem__(self, key, value): | |
48 self.content[key] = value | |
49 | |
50 def __getitem__(self, key): | |
51 return self.content[key] | |
52 | |
53 def __contains__(self, item): | |
54 return item in self.content | |
55 | |
56 def update(self, other): | |
57 self.content.update(other) | |
58 return self | |
59 | |
60 def __repr__(self): | |
61 return "{}(path={})".format(self.__class__.__name__, self.path) |