How to use the setupmeta.scm.Version 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_versioning.py View on Github external
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
github zsimic / setupmeta / setupmeta / scm.py View on Github external
def get_version(self):
        dirty = self.is_dirty()
        # Allow to override git describe command via env var SETUPMETA_GIT_DESCRIBE_COMMAND (just in case)
        cmd = os.environ.get("SETUPMETA_GIT_DESCRIBE_COMMAND", "describe --dirty --tags --long --match *.* --first-parent")
        cmd = cmd.split(" ")
        text = self.get_output(*cmd)
        version = self.parsed_version(text, dirty)
        if version:
            return version

        # Try harder
        commitid = self.get_output("rev-parse", "--short", "HEAD")
        commitid = "g%s" % commitid if commitid else ""
        distance = self.get_output("rev-list", "HEAD")
        distance = distance.count("\n") + 1 if distance else 0
        return Version(None, distance, commitid, dirty)
github zsimic / setupmeta / setupmeta / versioning.py View on Github external
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:
            cvc = setupmeta.version_components(cv)
            cvv = Version(main="%s.%s.%s" % cvc[:3], distance=cvc[4], commitid=gv.commitid, dirty=cvc[5])
            actual = self.strategy.rendered(cvv, auto_bumped=False)
            cleaned = self.strategy.rendered(gv.non_dirty)
            if actual not in (cleaned, rendered):
                source = vdef.sources[0].source
                expected = self.strategy.rendered(gv, extra=False)
                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)
github zsimic / setupmeta / setupmeta / scm.py View on Github external
def parsed_version(text, dirty=None):
        if text:
            m = RE_GIT_DESCRIBE.match(text)
            if m:
                main = m.group(1)
                distance = setupmeta.strip_dash(m.group(2))
                distance = setupmeta.to_int(distance, default=0)
                commitid = setupmeta.strip_dash(m.group(3))
                if dirty is None:
                    # This is only settable via env var SCM_DESCRIBE
                    dirty = m.group(4) == "-dirty"
                return Version(main, distance, commitid, dirty, text)
        return None
github zsimic / setupmeta / setupmeta / scm.py View on Github external
def non_dirty(self):
        """Non-dirty version associated to this Version"""
        main = "%s.%s.%s" % (self.major, self.minor, self.patch)
        return Version(main=main, distance=self.distance, commitid=self.commitid, dirty=False, text=main)
github zsimic / setupmeta / setupmeta / versioning.py View on Github external
def __init__(self, strategy, text, alternative=None, constant=False):
        self.strategy = strategy
        self.text = text
        self.alternative = alternative
        self.constant = constant
        self.renderer = None
        self.problem = None
        if self.constant:
            self.renderer = self.rendered_constant

        elif "$" in self.text:
            self.renderer = self.rendered_env_var

        elif not hasattr(Version, self.text):
            self.problem = "invalid versioning part '%s'" % self.text

        else:
            self.renderer = self.rendered_attr
github zsimic / setupmeta / setupmeta / versioning.py View on Github external
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)