def _find_prefix(filename):
"""
In virtualenv, _CONFIG_H and _MAKEFILE may have same or different
prefixes, depending on the version of virtualenv.
Try to find the correct one, which is assumed to be the longest one.
"""
if not is_venv:
return sys.prefix
filename = os.path.abspath(filename)
prefixes = [os.path.abspath(sys.prefix), base_prefix]
possible_prefixes = []
for prefix in prefixes:
common = os.path.commonprefix([prefix, filename])
if common == prefix:
possible_prefixes.append(prefix)
possible_prefixes.sort(key=lambda p: len(p), reverse=True)
return possible_prefixes[0]
评论列表
文章目录