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_stringify():
assert setupmeta.stringify((1, 2)) == '("1", "2")'
assert setupmeta.stringify(["1", "2"]) == '["1", "2"]'
assert setupmeta.stringify(("a b", "c d")) == '("a b", "c d")'
assert setupmeta.stringify("""quoted ("double"+'single')""", quote=True) == """'quoted ("double"+'single')'"""
assert setupmeta.stringify("""quoted 'single only'""", quote=True) == '''"quoted 'single only'"'''
assert setupmeta.stringify("no 'foo'") == "no 'foo'"
assert setupmeta.stringify("no 'foo'", quote=True) == '''"no 'foo'"'''
assert setupmeta.stringify({"bar": "no 'foo'"}) == """{bar: no 'foo'}"""
assert setupmeta.stringify({"bar": 'no "foo"'}) == """{bar: no "foo"}"""
assert setupmeta.listify("a b") == ["a", "b"]
assert sorted(setupmeta.listify(set("ab"))) == ["a", "b"]
assert setupmeta.listify(("a", "b")) == ["a", "b"]
def longest_line(lines, maximum=70):
lines = [setupmeta.stringify(line) for line in lines]
longest = max(len(line) for line in lines if "\n" not in line)
return min(longest, maximum)
def formatted(branches, main, separator, extra):
if isinstance(branches, list):
branches = ",".join(branches)
result = ""
if main:
result += setupmeta.stringify(main)
if result or extra:
result += setupmeta.stringify(separator)
if extra:
result += setupmeta.stringify(extra)
if branches:
result = "branch(%s):%s" % (branches, result)
return result
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:
def formatted(branches, main, separator, extra):
if isinstance(branches, list):
branches = ",".join(branches)
result = ""
if main:
result += setupmeta.stringify(main)
if result or extra:
result += setupmeta.stringify(separator)
if extra:
result += setupmeta.stringify(extra)
if branches:
result = "branch(%s):%s" % (branches, result)
return result
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)
else:
definition.value = setupmeta.stringify(definition.value, quote=True, indent=" ")
elif definition.key == "long_description":
definition.value = 'open(%s).read()' % setupmeta.stringify(setupmeta.short(definition.source), quote=True)
elif definition.key == "version":
definition.value = "__version__"
elif definition.key != "include_package_data":