Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _show_dependencies(definitions):
"""
Conveniently get dependency tree via ./setup.py check --dep, similar to https://pypi.org/project/pipdeptree
"""
if setupmeta.pkg_resources is None or not hasattr(setupmeta.pkg_resources, "WorkingSet"):
setupmeta.warn("pkg_resources is not available, can't show dependencies")
return 1
venv = find_venv()
if not venv:
setupmeta.warn("Could not find virtual environment to scan for dependencies")
return 1
entries = list(find_subfolders(venv, ["site-packages"]))
if not entries:
setupmeta.warn("Could not find 'site-packages' subfolder in '%s'" % venv)
return 1
tree = DepTree(setupmeta.pkg_resources.WorkingSet(entries), definitions)
print(tree.rendered())
return len(tree.conflicts) + len(tree.cycles)
if self.strategy:
setupmeta.warn(self.problem)
setupmeta.trace("not auto-filling version due to problem: [%s]" % self.problem)
return
gv = self.scm.get_version()
if self.generate_version_file:
path = setupmeta.project_path(setupmeta.VERSION_FILE)
with open(path, "w") as fh:
fh.write("%s" % gv)
if gv.patch and "patch" not in self.strategy.bumpable:
msg = "patch version component should be .0 for versioning strategy '%s', " % self.strategy
msg += "'.%s' from current version tag '%s' will be ignored" % (gv.patch, gv)
setupmeta.warn(msg)
rendered = self.strategy.rendered(gv)
if cv and gv:
cvc = setupmeta.version_components(cv)
cvv = Version(main="%s.%s.%s" % cvc[:3], distance=cvc[4], commitid=gv.commitid, dirty=cvc[5])
actual = self.strategy.rendered(cvv, auto_bumped=False)
cleaned = self.strategy.rendered(gv.non_dirty)
if actual not in (cleaned, rendered):
source = vdef.sources[0].source
expected = self.strategy.rendered(gv, extra=False)
msg = "In %s version should be '%s', not '%s'" % (source, expected, cv)
setupmeta.warn(msg)
self.meta.auto_fill("version", rendered, self.scm.name, override=True)
def __init__(self, main, extra, separator, branches, hook, **kwargs):
self.main = main
self.extra = extra
if kwargs:
setupmeta.warn("Ignored fields for 'versioning': %s" % kwargs)
self.main_bits = self.bits(main)
if isinstance(self.main_bits, list):
self.bumpable = [b.text for b in self.main_bits if b.text in BUMPABLE]
else:
self.bumpable = []
self.extra_bits = self.bits(extra)
self.separator = separator
self.branches = branches
self.hook = hook
if self.branches and hasattr(self.branches, "lstrip"):
self.branches = self.branches.lstrip("(").rstrip(")")
self.branches = setupmeta.listify(self.branches, separator=",")
def _show_dependencies(definitions):
"""
Conveniently get dependency tree via ./setup.py check --dep, similar to https://pypi.org/project/pipdeptree
"""
if setupmeta.pkg_resources is None or not hasattr(setupmeta.pkg_resources, "WorkingSet"):
setupmeta.warn("pkg_resources is not available, can't show dependencies")
return 1
venv = find_venv()
if not venv:
setupmeta.warn("Could not find virtual environment to scan for dependencies")
return 1
entries = list(find_subfolders(venv, ["site-packages"]))
if not entries:
setupmeta.warn("Could not find 'site-packages' subfolder in '%s'" % venv)
return 1
tree = DepTree(setupmeta.pkg_resources.WorkingSet(entries), definitions)
print(tree.rendered())
return len(tree.conflicts) + len(tree.cycles)
if package and "." not in package:
# Look at top level modules only
self.merge(
SimpleModule(package, "__about__.py"),
SimpleModule(package, "__version__.py"),
SimpleModule(package, "__init__.py"),
SimpleModule("src", package, "__about__.py"),
SimpleModule("src", package, "__version__.py"),
SimpleModule("src", package, "__init__.py"),
)
if not self.name:
warn("'name' not specified in setup.py, auto-fill will be incomplete")
elif not self.definitions.get("packages") and not self.definitions.get("py_modules"):
warn("No 'packages' or 'py_modules' defined, this is an empty python package")
scm = scm or project_scm(MetaDefs.project_dir)
self.versioning = Versioning(self, scm)
self.versioning.auto_fill_version()
self.fill_urls()
self.auto_adjust("author", self.extract_email)
self.auto_adjust("contact", self.extract_email)
self.auto_adjust("maintainer", self.extract_email)
self.requirements = Requirements(self.pkg_info)
self.auto_fill_requires("install_requires")
self.auto_fill_requires("tests_require")
if self.requirements.dependency_links:
self.auto_fill("dependency_links", self.requirements.dependency_links, self.requirements.links_source)
if not self.enabled:
setupmeta.trace("not auto-filling version, versioning is disabled")
return
vdef = self.meta.definitions.get("version")
if vdef and vdef.source and vdef.source.lower().endswith("-info"):
# We already got version from PKG-INFO
return
cv = vdef.sources[0].value if vdef and vdef.sources else None
if self.problem:
if not cv:
self.meta.auto_fill("version", "0.0.0", "missing")
if self.strategy:
setupmeta.warn(self.problem)
setupmeta.trace("not auto-filling version due to problem: [%s]" % self.problem)
return
gv = self.scm.get_version()
if self.generate_version_file:
path = setupmeta.project_path(setupmeta.VERSION_FILE)
with open(path, "w") as fh:
fh.write("%s" % gv)
if gv.patch and "patch" not in self.strategy.bumpable:
msg = "patch version component should be .0 for versioning strategy '%s', " % self.strategy
msg += "'.%s' from current version tag '%s' will be ignored" % (gv.patch, gv)
setupmeta.warn(msg)
rendered = self.strategy.rendered(gv)
return parse_requirements, PipSession
except ImportError:
pass
try:
# pip < 10.0
from pip.req import parse_requirements
from pip.download import PipSession
return parse_requirements, PipSession
except ImportError:
from setupmeta import warn
warn("Can't find PipSession, won't auto-fill requirements")
return None, None