Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_meta_command_init():
with pytest.raises(Exception):
obj = setupmeta.MetaDefs()
setupmeta.meta_command_init(obj, {})
def preprocess(self, upstream):
self.find_project_dir(MetaDefs.dist_to_dict(upstream).pop("_setup_py_path", None))
for require_field in ('install_requires', 'tests_require'):
value = getattr(upstream, require_field)
if isinstance(value, str if sys.version_info.major >= 3 else basestring) and value.startswith('@'): # noqa: E501, F821 (basestring used by Python 2)
self.add_definition(require_field, value, EXPLICIT)
self.add_definition(require_field, requirements_from_file(value[1:]) or [], source=value[1:], override=True)
if isinstance(upstream.extras_require, dict):
if any([
isinstance(deps, str if sys.version_info.major >= 3 else basestring) # noqa: F821 (basestring used by Python 2)
and deps.startswith('@')
for deps in upstream.extras_require.values()
]):
self.add_definition('extras_require', upstream.extras_require, EXPLICIT)
self.add_definition('extras_require', {
extra: (requirements_from_file(deps[1:]) or []) if isinstance(deps, str) and deps.startswith('@') else deps
def MetaCommand(cls):
"""Decorator allowing for less boilerplate in our commands"""
return setupmeta.MetaDefs.register_command(cls)
def finalize(self, upstream):
self.attrs.update(MetaDefs.dist_to_dict(upstream))
self.find_project_dir(self.attrs.pop("_setup_py_path", None))
scm = self.attrs.pop("scm", None)
# Add definitions from setup()'s attrs (highest priority)
for key, value in self.attrs.items():
if key not in self.definitions:
self.add_definition(key, value, EXPLICIT)
# Add definitions from PKG-INFO, when available
self.pkg_info = PackageInfo(MetaDefs.project_dir)
for key, value in self.pkg_info.info.items():
if key in MetaDefs.all_fields:
self.add_definition(key, value, relative_path(self.pkg_info.path))
# Allow to auto-fill 'name' from setup.py's __title__, if any
self.merge(SimpleModule("setup.py"))
title = self.definitions.get("title")
if title:
self.auto_fill("name", title.value, source=title.source)
if "--name" in sys.argv[1:3]:
# No need to waste time auto-filling anything if all we need to show is package name
return self
packages = self.attrs.get("packages", [])
py_modules = self.attrs.get("py_modules", [])
if not packages and not py_modules and self.name:
def show_expanded_python(self):
"""Copy-pastable setup.py, if one wants to get rid of setupmeta"""
definitions = self.setupmeta.definitions
print('"""\nGenerated by https://pypi.org/project/setupmeta/\n"""\n')
print("from setuptools import setup\n\n")
version = definitions.get("version")
if version:
print('__version__ = %s\n\n' % setupmeta.stringify(version.value, quote=True))
print("setup(")
defs = []
for definition in sorted(definitions.values()):
if not definition.value or definition.key not in setupmeta.MetaDefs.all_fields:
continue
if definition.key == "setup_requires":
# When expanding, remove mention of 'setupmeta',
# as expansion is aimed at giving a people a way to get a setup.py as-if setupmeta didn't exist
# ie: it's a way of easily getting rid of setupmeta (should the need arise)
if "setupmeta" in definition.value:
definition.value.remove("setupmeta")
if definition.value:
definition.value = setupmeta.stringify(definition.value, quote=True, indent=" ")
elif definition.key == "download_url":
if version and version.value in definition.value:
definition.value = definition.value.replace(version.value, "%s")
definition.value = "%s %% __version__" % setupmeta.stringify(setupmeta.short(definition.value), quote=True)