Bake git hash at install time so /version works without .git
setup.py writes GIT_HASH file during install. The version view reads it at runtime instead of shelling out to git.
This commit is contained in:
parent
1ebfb5a8aa
commit
1b704f545f
3 changed files with 27 additions and 13 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -36,3 +36,5 @@ monero-wallet-cli.log
|
|||
monero-wallet-rpc.log
|
||||
monero-wallet-rpc.log*
|
||||
|
||||
GIT_HASH
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,17 @@
|
|||
import subprocess
|
||||
import os
|
||||
|
||||
from pyramid.response import Response
|
||||
from pyramid.view import view_config
|
||||
|
||||
# Capture git hash once at process start.
|
||||
VERSION = "1.1.5"
|
||||
|
||||
# Read git hash baked in by setup.py at install time.
|
||||
_hash_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), "GIT_HASH")
|
||||
try:
|
||||
GIT_HASH = (
|
||||
subprocess.check_output(
|
||||
["git", "rev-parse", "--short", "HEAD"],
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
.decode()
|
||||
.strip()
|
||||
)
|
||||
with open(_hash_file) as f:
|
||||
GIT_HASH = f.read().strip()
|
||||
except Exception:
|
||||
GIT_HASH = "unknown"
|
||||
|
||||
VERSION = "1.1.5"
|
||||
|
||||
|
||||
@view_config(route_name="version", renderer="json")
|
||||
def version(request):
|
||||
|
|
|
|||
18
setup.py
18
setup.py
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import subprocess
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
|
|
@ -27,6 +28,23 @@ here = os.path.abspath(os.path.dirname(__file__))
|
|||
with open(os.path.join(here, "README.rst"), "r", encoding="utf-8") as f:
|
||||
long_description = f.read()
|
||||
|
||||
# Bake git hash into package so /version works without .git directory.
|
||||
git_hash_file = os.path.join(here, "make_post_sell", "GIT_HASH")
|
||||
try:
|
||||
git_hash = (
|
||||
subprocess.check_output(
|
||||
["git", "rev-parse", "--short", "HEAD"],
|
||||
cwd=here,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
.decode()
|
||||
.strip()
|
||||
)
|
||||
with open(git_hash_file, "w") as f:
|
||||
f.write(git_hash)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
setup(
|
||||
name="make_post_sell",
|
||||
version="1.1.5",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue