Tweak __version__ handling in setup.py

This commit is contained in:
Kodi Arfer 2016-11-27 09:22:31 -08:00
parent 1fc3507115
commit 6e7e94dd8e

View File

@ -22,7 +22,9 @@
import os import os
import re import re
import sys import sys
import runpy
import subprocess import subprocess
from distutils.spawn import find_executable
from setuptools import find_packages, setup from setuptools import find_packages, setup
@ -30,14 +32,16 @@ os.chdir(os.path.split(os.path.abspath(__file__))[0])
PKG = "hy" PKG = "hy"
VERSIONFILE = os.path.join(PKG, "version.py") VERSIONFILE = os.path.join(PKG, "version.py")
try: if os.path.exists('.git') and find_executable('git'):
__version__ = (subprocess.check_output __version__ = (subprocess.check_output
(["git", "describe", "--tags", "--dirty"]) (["git", "describe", "--tags", "--dirty"])
.decode('ASCII').strip() .decode('ASCII').strip()
.replace('-', '+', 1).replace('-', '.')) .replace('-', '+', 1).replace('-', '.'))
with open(VERSIONFILE, "wt") as o: with open(VERSIONFILE, "wt") as o:
o.write("__version__ = {!r}\n".format(__version__)) o.write("__version__ = {!r}\n".format(__version__))
except subprocess.CalledProcessError: elif os.path.exists(VERSIONFILE):
__version__ = runpy.run_path(VERSIONFILE)['__version__']
else:
__version__ = "unknown" __version__ = "unknown"
long_description = """Hy is a Python <--> Lisp layer. It helps long_description = """Hy is a Python <--> Lisp layer. It helps