MCPcopy Create free account
hub / github.com/microsoft/debugpy / get_environment_description

Function get_environment_description

src/debugpy/common/log.py:282–368  ·  view source on GitHub ↗
(header)

Source from the content-addressed store, hash-verified

280
281
282def get_environment_description(header):
283 import sysconfig
284 import site # noqa
285
286 result = [header, "\n\n"]
287
288 def report(s, *args, **kwargs):
289 result.append(s.format(*args, **kwargs))
290
291 def report_paths(get_paths, label=None):
292 prefix = f" {label or get_paths}: "
293
294 expr = None
295 if not callable(get_paths):
296 expr = get_paths
297 get_paths = lambda: util.evaluate(expr)
298 try:
299 paths = get_paths()
300 except AttributeError:
301 report("{0}<missing>\n", prefix)
302 return
303 except Exception: # pragma: no cover
304 swallow_exception(
305 "Error evaluating {0}",
306 repr(expr) if expr else util.srcnameof(get_paths),
307 level="info",
308 )
309 return
310
311 if not isinstance(paths, (list, tuple)):
312 paths = [paths]
313
314 for p in sorted(paths):
315 report("{0}{1}", prefix, p)
316 if p is not None:
317 rp = os.path.realpath(p)
318 if p != rp:
319 report("({0})", rp)
320 report("\n")
321
322 prefix = " " * len(prefix)
323
324 report("System paths:\n")
325 report_paths("sys.executable")
326 report_paths("sys.prefix")
327 report_paths("sys.base_prefix")
328 report_paths("sys.real_prefix")
329 report_paths("site.getsitepackages()")
330 report_paths("site.getusersitepackages()")
331
332 site_packages = [
333 p
334 for p in sys.path
335 if os.path.exists(p) and os.path.basename(p) == "site-packages"
336 ]
337 report_paths(lambda: site_packages, "sys.path (site-packages)")
338
339 for name in sysconfig.get_path_names():

Callers 1

describe_environmentFunction · 0.85

Calls 4

report_pathsFunction · 0.85
swallow_exceptionFunction · 0.85
reportFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…