From 1b704f545f265f2fcf5cb6fb5fb04fea8f16961c Mon Sep 17 00:00:00 2001 From: "russell@unturf.com" Date: Sat, 7 Feb 2026 19:54:57 -0500 Subject: [PATCH] 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. --- .gitignore | 2 ++ make_post_sell/views/version.py | 20 +++++++------------- setup.py | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 2550ca7..d0b1c0b 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ monero-wallet-cli.log monero-wallet-rpc.log monero-wallet-rpc.log* +GIT_HASH + diff --git a/make_post_sell/views/version.py b/make_post_sell/views/version.py index be2e2d2..030a132 100644 --- a/make_post_sell/views/version.py +++ b/make_post_sell/views/version.py @@ -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): diff --git a/setup.py b/setup.py index 9ee2de8..27131f0 100644 --- a/setup.py +++ b/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",