示例#1
0
    def bumped(self, what, current_version):
        """
        :param str what: Which component to bump
        :param Version current_version: Current version
        :return str: Represented next version, with 'what' bumped
        """
        if not isinstance(self.main_bits, list):
            setupmeta.abort("Main format is not a list: %s" %
                            setupmeta.stringify(self.main_bits))

        if what not in self.bumpable:
            msg = "Can't bump '%s', it's out of scope" % what
            msg += " of main format '%s'" % self.main
            msg += " acceptable values: %s" % ", ".join(self.bumpable)
            setupmeta.abort(msg)

        major, minor, rev = current_version.major, current_version.minor, current_version.patch
        if what == "major":
            major, minor, rev = (major + 1, 0, 0)

        elif what == "minor":
            major, minor, rev = (major, minor + 1, 0)

        elif what == "patch":
            major, minor, rev = (major, minor, rev + 1)

        next_version = Version(main="%s.%s.%s" % (major, minor, rev))
        return self.rendered(next_version, extra=False)
示例#2
0
    def auto_fill_version(self):
        """
        Auto-fill version as defined by self.strategy
        :param setupmeta.model.SetupMeta meta: Parent meta object
        """
        pygradle_version = os.environ.get("PYGRADLE_PROJECT_VERSION")
        if pygradle_version:
            # Minimal support for https://github.com/linkedin/pygradle
            self.meta.auto_fill("version",
                                pygradle_version,
                                "pygradle",
                                override=True)
            return

        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)
        if cv and gv:
            cvv = Version(main=cv,
                          distance=gv.distance,
                          commitid=gv.commitid,
                          dirty=gv.dirty)
            if cvv.major != gv.major or cvv.minor != gv.minor or cvv.patch != gv.patch:
                source = vdef.sources[0].source
                expected = rendered[:len(cv)]
                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)
示例#3
0
def check_render(v,
                 expected,
                 main="1.0",
                 distance=None,
                 cid=None,
                 dirty=False):
    version = Version(main=main, distance=distance, commitid=cid, dirty=dirty)
    assert v.strategy.rendered(version) == expected