Esempio n. 1
0
    def run(self):
        if not self.setupmeta:
            return

        if self.expand:
            return self.show_expanded_python()

        if self.dependencies:
            return self.show_dependencies()

        self.chars = setupmeta.to_int(self.chars,
                                      default=setupmeta.Console.columns())

        definitions = self.setupmeta.definitions
        self.check_recommend("name")
        self.check_recommend("version",
                             "you can use setupmeta's versioning='...'")
        self.check_recommend("description",
                             "add a README or a docstring to your module")
        self.check_recommend("long_description", "add a README file")
        if self.recommend:
            self.check_recommend("author")
            self.check_recommend("classifiers")
            self.check_recommend("download_url")
            self.check_recommend("license")
            self.check_recommend("url")
        if definitions:
            longest_key = min(30, max(len(key) for key in definitions))
            sources = sum((d.sources for d in definitions.values()), [])
            longest_source = min(40, max(len(s.source) for s in sources))
            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
Esempio n. 2
0
    def run(self):
        self.chars = setupmeta.to_int(self.chars, default=setupmeta.Console.columns())

        definitions = self.setupmeta.definitions
        self.check_recommend('name')
        self.check_recommend('version', "you can use setupmeta's versioning='...'")
        self.check_recommend('description', "add a README or a docstring to your module")
        self.check_recommend('long_description', "add a README file")
        if self.recommend:
            self.check_recommend('author')
            self.check_recommend('classifiers')
            self.check_recommend('download_url')
            self.check_recommend('license')
            self.check_recommend('url')
        if definitions:
            longest_key = min(24, max(len(key) for key in definitions))
            sources = sum((d.sources for d in definitions.values()), [])
            longest_source = min(32, max(len(s.source) for s in sources))
            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)
                    print(form % (prefix, source.source, preview))
                    count += 1
Esempio n. 3
0
 def add(self, value, source, override=False):
     """
     :param value: Value to add (first value wins, unless override used)
     :param str source: Where this key/value came from
     :param bool override: If True, 'value' is forcibly taken
     """
     if isinstance(source, list):
         return self.merge_sources(source)
     if override or not self.value:
         self.value = value
     entry = DefinitionEntry(self.key, value, source)
     if override:
         self.sources.insert(0, entry)
         trace("[high: %s] %s=%s" % (source, self.key, short(value)))
     else:
         self.sources.append(entry)
         trace("[low: %s] %s=%s" % (source, self.key, short(value)))
Esempio n. 4
0
def test_shortening():
    assert setupmeta.short(None) == "None"
    assert setupmeta.short("") == ""

    assert setupmeta.short("hello there", c=11) == "hello there"
    assert setupmeta.short("hello there", c=8) == "11 chars"

    assert setupmeta.short("hello there wild wonderful world",
                           c=19) == "32 chars: hello ..."

    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'
Esempio n. 5
0
 def __repr__(self):
     return "%s=%s from %s" % (self.key, short(self.value), self.source)
Esempio n. 6
0
 def __repr__(self):
     project_dir = short(MetaDefs.project_dir)
     return "%s definitions, %s" % (len(self.definitions), project_dir)
Esempio n. 7
0
 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)
Esempio n. 8
0
def print_warning(message, *_, **__):
    """Print simplified warnings for capture in testing, instead of letting warnings do its funky thing"""
    print("WARNING: %s" % setupmeta.short(message, -60))
Esempio n. 9
0
    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":
                if isinstance(definition.value,
                              list) and "setupmeta" in definition.value:
                    definition.value.remove("setupmeta")
                if "setupmeta" == definition.value:
                    continue
                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__"
            else:
                definition.value = setupmeta.stringify(definition.value,
                                                       quote=True,
                                                       indent="        ")
            if definition.value:
                defs.append(definition)

        longest = max(len(d.value) for d in defs if "\n" not in d.value)
        longest = min(longest, 70)
        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(")")
Esempio n. 10
0
    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)

                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:
                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(")")
Esempio n. 11
0
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"