Add fancy versioning stuff
This commit is contained in:
parent
78fdb6f175
commit
d3adedf3df
13
setup.py
13
setup.py
@ -1,5 +1,7 @@
|
|||||||
import setuptools
|
import setuptools
|
||||||
|
|
||||||
|
from sticker.get_version import git_tag, git_revision, version, linkified_version
|
||||||
|
|
||||||
with open("requirements.txt") as reqs:
|
with open("requirements.txt") as reqs:
|
||||||
install_requires = reqs.read().splitlines()
|
install_requires = reqs.read().splitlines()
|
||||||
|
|
||||||
@ -8,9 +10,18 @@ try:
|
|||||||
except IOError:
|
except IOError:
|
||||||
long_desc = "Failed to read README.md"
|
long_desc = "Failed to read README.md"
|
||||||
|
|
||||||
|
with open("sticker/version.py", "w") as version_file:
|
||||||
|
version_file.write(f"""# Generated in setup.py
|
||||||
|
|
||||||
|
git_tag = {git_tag!r}
|
||||||
|
git_revision = {git_revision!r}
|
||||||
|
version = {version!r}
|
||||||
|
linkified_version = {linkified_version!r}
|
||||||
|
""")
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="maunium-stickerpicker",
|
name="maunium-stickerpicker",
|
||||||
version="0.1.0",
|
version=version,
|
||||||
url="https://github.com/maunium/stickerpicker",
|
url="https://github.com/maunium/stickerpicker",
|
||||||
|
|
||||||
author="Tulir Asokan",
|
author="Tulir Asokan",
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
__version__ = "0.1.0+dev"
|
||||||
|
__author__ = "Tulir Asokan <tulir@maunium.net>"
|
50
sticker/get_version.py
Normal file
50
sticker/get_version.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
import os
|
||||||
|
|
||||||
|
from . import __version__
|
||||||
|
|
||||||
|
cmd_env = {
|
||||||
|
"PATH": os.environ["PATH"],
|
||||||
|
"HOME": os.environ["HOME"],
|
||||||
|
"LANG": "C",
|
||||||
|
"LC_ALL": "C",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def run(cmd):
|
||||||
|
return subprocess.check_output(cmd, stderr=subprocess.DEVNULL, env=cmd_env)
|
||||||
|
|
||||||
|
|
||||||
|
if (os.path.exists("../.git") or os.path.exists(".git")) and shutil.which("git"):
|
||||||
|
try:
|
||||||
|
git_revision = run(["git", "rev-parse", "HEAD"]).strip().decode("ascii")
|
||||||
|
git_revision_url = f"https://github.com/maunium/stickerpicker/commit/{git_revision}"
|
||||||
|
git_revision = git_revision[:8]
|
||||||
|
except (subprocess.SubprocessError, OSError):
|
||||||
|
git_revision = "unknown"
|
||||||
|
git_revision_url = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
git_tag = run(["git", "describe", "--exact-match", "--tags"]).strip().decode("ascii")
|
||||||
|
except (subprocess.SubprocessError, OSError):
|
||||||
|
git_tag = None
|
||||||
|
else:
|
||||||
|
git_revision = "unknown"
|
||||||
|
git_revision_url = None
|
||||||
|
git_tag = None
|
||||||
|
|
||||||
|
git_tag_url = (f"https://github.com/maunium/stickerpicker/releases/tag/{git_tag}"
|
||||||
|
if git_tag else None)
|
||||||
|
|
||||||
|
if git_tag and __version__ == git_tag[1:].replace("-", ""):
|
||||||
|
version = __version__
|
||||||
|
linkified_version = f"[{version}]({git_tag_url})"
|
||||||
|
else:
|
||||||
|
if not __version__.endswith("+dev"):
|
||||||
|
__version__ += "+dev"
|
||||||
|
version = f"{__version__}.{git_revision}"
|
||||||
|
if git_revision_url:
|
||||||
|
linkified_version = f"{__version__}.[{git_revision}]({git_revision_url})"
|
||||||
|
else:
|
||||||
|
linkified_version = version
|
1
sticker/version.py
Normal file
1
sticker/version.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .get_version import git_tag, git_revision, version, linkified_version
|
Loading…
Reference in New Issue
Block a user