MCPcopy Create free account
hub / github.com/catboost/catboost / _init_venv

Function _init_venv

library/python/runtime_py3/__res.py:66–101  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

64
65
66def _init_venv():
67 if not _path_isabs(executable):
68 raise RuntimeError(f'path in sys.executable is not absolute: {executable}')
69
70 # Creative copy-paste from site.py
71 exe_dir, _ = _path_split(executable)
72 site_prefix, _ = _path_split(exe_dir)
73 libpath = _path_join(site_prefix, 'lib',
74 'python%d.%d' % sys.version_info[:2],
75 'site-packages')
76 sys.path.insert(0, libpath)
77
78 # emulate site.venv()
79 sys.prefix = site_prefix
80 sys.exec_prefix = site_prefix
81
82 conf_basename = 'pyvenv.cfg'
83 candidate_confs = [
84 conffile for conffile in (
85 _path_join(exe_dir, conf_basename),
86 _path_join(site_prefix, conf_basename)
87 )
88 if _path_isfile(conffile)
89 ]
90 if not candidate_confs:
91 raise RuntimeError(f'{conf_basename} not found')
92 virtual_conf = candidate_confs[0]
93 with FileIO(virtual_conf, 'r') as f:
94 for line in f:
95 if b'=' in line:
96 key, _, value = line.partition(b'=')
97 key = key.strip().lower()
98 value = value.strip()
99 if key == cfg_source_root:
100 return value
101 raise RuntimeError(f'{cfg_source_root} key not found in {virtual_conf}')
102
103
104def file_bytes(path, strip=False):

Callers 1

_get_source_rootFunction · 0.85

Calls 2

insertMethod · 0.45
partitionMethod · 0.45

Tested by

no test coverage detected