MCPcopy Create free account
hub / github.com/bloomberg/pystack / _get_python_version_from_map_information

Function _get_python_version_from_map_information

src/pystack/process.py:63–95  ·  view source on GitHub ↗
(
    mapinfo: MemoryMapInformation,
)

Source from the content-addressed store, hash-verified

61
62
63def _get_python_version_from_map_information(
64 mapinfo: MemoryMapInformation,
65) -> Tuple[int, int]:
66 match = None
67 assert mapinfo.python.path is not None
68 if mapinfo.libpython:
69 assert mapinfo.libpython.path is not None
70 LOGGER.info(
71 "Trying to extract version from filename: %s", mapinfo.libpython.path.name
72 )
73 match = LIBPYTHON_REGEXP.match(mapinfo.libpython.path.name)
74 else:
75 LOGGER.info(
76 "Trying to extract version from filename: %s", mapinfo.python.path.name
77 )
78 match = BINARY_REGEXP.match(mapinfo.python.path.name)
79 if match is None:
80 LOGGER.info(
81 "Could not find version by looking at library or binary path: "
82 "Trying to get it from running python --version"
83 )
84 output = subprocess.check_output(
85 [mapinfo.python.path, "--version"], text=True, stderr=subprocess.STDOUT
86 )
87 match = VERSION_REGEXP.match(output)
88 if not match:
89 raise InvalidPythonProcess(
90 f"Could not determine python version from {mapinfo.python.path}"
91 )
92 major = match.group("major")
93 minor = match.group("minor")
94 LOGGER.info("Python version determined: %s.%s", major, minor)
95 return int(major), int(minor)
96
97
98def get_python_version_for_process(

Callers 2

Calls 1

Tested by

no test coverage detected