mirror of
https://github.com/jongracecox/anybadge.git
synced 2025-07-21 04:11:05 +02:00
chore: Use git tag for package version
Update `setup.py` to use git tag for package version.
This commit is contained in:
26
setup.py
26
setup.py
@@ -1,23 +1,39 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import subprocess
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
with open("README.md", encoding="utf-8") as f:
|
with open("README.md", encoding="utf-8") as f:
|
||||||
long_description = f.read()
|
long_description = f.read()
|
||||||
|
|
||||||
# Attempt to get version number from TravisCI environment variable
|
|
||||||
version = os.environ.get("TRAVIS_TAG", default="0.0.0")
|
|
||||||
|
|
||||||
# Remove leading 'v'
|
def get_version():
|
||||||
version = re.sub("^v", "", version)
|
"""Get the version from git tags.
|
||||||
|
|
||||||
|
Version is determined by the latest git tag, and will be the tag name without the leading 'v'.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The version number.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Get the latest git tag
|
||||||
|
version = subprocess.check_output(
|
||||||
|
["git", "describe", "--tags", "--abbrev=0"], encoding="utf-8"
|
||||||
|
).strip()
|
||||||
|
version = re.sub("^v", "", version)
|
||||||
|
return version
|
||||||
|
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return "0.0.0"
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="anybadge",
|
name="anybadge",
|
||||||
description="Simple, flexible badge generator for project badges.",
|
description="Simple, flexible badge generator for project badges.",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
version=version,
|
version=get_version(),
|
||||||
author="Jon Grace-Cox",
|
author="Jon Grace-Cox",
|
||||||
author_email="30441316+jongracecox@users.noreply.github.com",
|
author_email="30441316+jongracecox@users.noreply.github.com",
|
||||||
packages=["anybadge", "anybadge.templates", "anybadge.server"],
|
packages=["anybadge", "anybadge.templates", "anybadge.server"],
|
||||||
|
Reference in New Issue
Block a user