How to use the setupmeta.short function in setupmeta

To help you get started, we’ve selected a few setupmeta examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zsimic / setupmeta / tests / test_content.py View on Github external
def test_shortening():
    assert setupmeta.short(None) == "None"
    assert setupmeta.short("") == ""

    assert setupmeta.short("hello  there", c=13) == "hello there"
    assert setupmeta.short("hello  there", c=12) == "hello there"
    assert setupmeta.short("hello  there", c=11) == "hello there"
    assert setupmeta.short("hello  there", c=10) == "hello t..."
    assert setupmeta.short("hello  there", c=-10) == "hello ther..."
    assert setupmeta.short("hello there wild wonderful world", c=19) == "hello there wild..."
    assert setupmeta.short("hello there wild wonderful world", c=-19) == "hello there wild wo..."

    assert setupmeta.short(["hello", "there", "wild", "wonderful  world"], c=34) == '4 items: ["hello", "there", "wi...'

    path = os.path.expanduser("~/foo/bar")
    assert setupmeta.short(path) == "~/foo/bar"

    assert setupmeta.short("found in %s" % path) == "found in ~/foo/bar"

    assert setupmeta.short(dict(foo="bar"), c=8) == "1 keys"

    assert setupmeta.merged("a", None) == "a"
    assert setupmeta.merged(None, "a") == "a"
    assert setupmeta.merged("a", "b") == "a\nb"
github zsimic / setupmeta / tests / test_content.py View on Github external
def test_shortening():
    assert setupmeta.short(None) == "None"
    assert setupmeta.short("") == ""

    assert setupmeta.short("hello  there", c=13) == "hello there"
    assert setupmeta.short("hello  there", c=12) == "hello there"
    assert setupmeta.short("hello  there", c=11) == "hello there"
    assert setupmeta.short("hello  there", c=10) == "hello t..."
    assert setupmeta.short("hello  there", c=-10) == "hello ther..."
    assert setupmeta.short("hello there wild wonderful world", c=19) == "hello there wild..."
    assert setupmeta.short("hello there wild wonderful world", c=-19) == "hello there wild wo..."

    assert setupmeta.short(["hello", "there", "wild", "wonderful  world"], c=34) == '4 items: ["hello", "there", "wi...'

    path = os.path.expanduser("~/foo/bar")
    assert setupmeta.short(path) == "~/foo/bar"

    assert setupmeta.short("found in %s" % path) == "found in ~/foo/bar"

    assert setupmeta.short(dict(foo="bar"), c=8) == "1 keys"

    assert setupmeta.merged("a", None) == "a"
    assert setupmeta.merged(None, "a") == "a"
github zsimic / setupmeta / tests / test_content.py View on Github external
def test_shortening():
    assert setupmeta.short(None) == "None"
    assert setupmeta.short("") == ""

    assert setupmeta.short("hello  there", c=13) == "hello there"
    assert setupmeta.short("hello  there", c=12) == "hello there"
    assert setupmeta.short("hello  there", c=11) == "hello there"
    assert setupmeta.short("hello  there", c=10) == "hello t..."
    assert setupmeta.short("hello  there", c=-10) == "hello ther..."
    assert setupmeta.short("hello there wild wonderful world", c=19) == "hello there wild..."
    assert setupmeta.short("hello there wild wonderful world", c=-19) == "hello there wild wo..."

    assert setupmeta.short(["hello", "there", "wild", "wonderful  world"], c=34) == '4 items: ["hello", "there", "wi...'

    path = os.path.expanduser("~/foo/bar")
    assert setupmeta.short(path) == "~/foo/bar"

    assert setupmeta.short("found in %s" % path) == "found in ~/foo/bar"

    assert setupmeta.short(dict(foo="bar"), c=8) == "1 keys"

    assert setupmeta.merged("a", None) == "a"
    assert setupmeta.merged(None, "a") == "a"
    assert setupmeta.merged("a", "b") == "a\nb"
github zsimic / setupmeta / setupmeta / commands.py View on Github external
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":
                definition.value = setupmeta.stringify(definition.value, quote=True, indent="        ")

            if definition.value:
                defs.append(definition)
github zsimic / setupmeta / setupmeta / commands.py View on Github external
form = "%%%ss: (%%%ss) %%s" % (longest_key, -longest_source)
            max_chars = max(60, self.chars - longest_key - longest_source - 5)

            for definition in sorted(definitions.values()):
                count = 0
                for source in definition.sources:
                    if count:
                        prefix = "\\_"

                    elif source.key not in setupmeta.MetaDefs.all_fields:
                        prefix = "%s*" % source.key

                    else:
                        prefix = source.key

                    preview = setupmeta.short(source.value, c=max_chars)
                    s = form % (prefix, setupmeta.short(source.source), preview)
                    print(s)
                    count += 1
github zsimic / setupmeta / setupmeta / commands.py View on Github external
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":
                definition.value = setupmeta.stringify(definition.value, quote=True, indent="        ")

            if definition.value:
                defs.append(definition)

        longest = longest_line([d.value for d in defs])
        for definition in defs:
            if definition.key == "versioning":
                line = "    # versioning=%s," % definition.value

            else:
github zsimic / setupmeta / setupmeta / commands.py View on Github external
definition.value = setupmeta.stringify(definition.value, quote=True, indent="        ")

            if definition.value:
                defs.append(definition)

        longest = longest_line([d.value for d in defs])
        for definition in defs:
            if definition.key == "versioning":
                line = "    # versioning=%s," % definition.value

            else:
                line = "    %s=%s," % (definition.key, definition.value)

            source = definition.actual_source
            if source and source != "explicit":
                comment = "# from %s" % setupmeta.short(source)
                rest, _, last_line = line.rpartition("\n")
                if len(last_line) < longest:
                    padding = " " * (longest - len(last_line))

                else:
                    padding = " "

                last_line = "%s%s%s" % (last_line, padding, comment)
                line = "%s\n%s" % (rest, last_line) if rest else last_line

            print(line)

        print(")")
github zsimic / setupmeta / setupmeta / model.py View on Github external
def __repr__(self):
        return "%s=%s from %s" % (self.key, short(self.value), self.source)
github zsimic / setupmeta / setupmeta / model.py View on Github external
def __repr__(self):
        if len(self.sources) == 1:
            source = self.sources[0].source
        else:
            source = "%s sources" % len(self.sources)
        return "%s=%s from %s" % (self.key, short(self.value), source)