Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pkg = get_distribution(name)
except DistributionNotFound:
return None
# For an installed package, the parent is the install location
path_pkg = Path(pkg.location).resolve()
if parent is not None and path_pkg != parent.resolve():
msg = f"""\
metadata: Failed; distribution and package paths do not match:
{path_pkg}
!=
{parent.resolve()}\
"""
return None
return Version.parse(pkg.version)
def get_version_from_dirname(name, parent):
"""Extracted sdist"""
parent = parent.resolve()
re_dirname = re.compile(f"{name}-{RE_VERSION}$")
if not re_dirname.match(parent.name):
return None
return Version.parse(parent.name[len(name) + 1 :])