can git tags be created for each of the releases into pypi?
I was considering installing using git, but couldn't find any tags to use.
I was considering installing using git, but couldn't find any tags to use.
Added a post-commit hook, which adds a tag if version increments, so the future versions will have tags.
#!/usr/bin/python
# place in .git/hooks/post-commit
"""Post-commit hook for git, which automatically adds tag
corresponding to the new version, to adapt it to your needs,
change the ``VERSION_FILE`` variable below.
"""
VERSION_FILE = 'askbot/__init__.py'
import commands, re
class Version(object):
"""basic implementation of version utility,
only supports numeric triples like '0.1.3'
"""
def __init__(self, vstring = None):
if vstring:
self.parse(vstring)
def parse(self, vstring):
major, minor, micro = vstring.split('.')
self.major = int(major)
self.minor = int(minor)
self.micro = int(micro)
def __str__(self):
return "%s.%s.%s" % (self.major, self.minor, self.micro)
def __cmp__(self, other):
cmp_major = cmp(self.major, other.major)
if cmp_major == 0:
cmp_minor = cmp(self.minor, other.minor)
if cmp_minor == 0:
return cmp(self.micro, other.micro)
else:
return cmp_minor
else:
return cmp_major
def add_tag(tag):
"""tag the git repo with the new version"""
status, output = commands.getstatusoutput('git tag -f %s' % tag)
if status:
raise Exception('tagging not successful: %s %s' % (output, status))
def get_version(version_file_string):
"""returns instance of :class:`Version`
based on the string input,
which is expected to be contents of some file or output"""
regex_string = r"VERSION\s?\=\s?" + \
r"\((?P<major>[0-9]+)\s?\," + \
r"\s?(?P<minor>[0-9]+)\s?\," + \
r"\s?(?P<micro>[0-9]+)\s?\)"
for line in version_file_string.split("\n"):
regex = re.compile(regex_string)
match = regex.search(line)
if match:
vstring = '.'.join(match.groups())
return Version(vstring = vstring)
return Version('0.0.0')
def get_versions():
"""returns name of a new version as string
if there is a new version, otherwise
``None``
"""
status, output = commands.getstatusoutput(
'git show HEAD:' + VERSION_FILE
)
new_version = get_version(output)
status, output = commands.getstatusoutput(
'git show HEAD^:' + VERSION_FILE
)
old_version = get_version(output)
return new_version, old_version
if __name__ == '__main__':
NEW, OLD = get_versions()
if NEW > OLD:
add_tag(NEW)
print "added new tag %s" % NEW
elif NEW < OLD:
raise ValueError("Error: new version is older than the previous")
To enter a block of code:
Comments