From e1e2012c4e918724a029f9e42bb053704deda264 Mon Sep 17 00:00:00 2001 From: Kyle Benesch <4b796c65+github@gmail.com> Date: Tue, 15 Jun 2021 12:11:46 -0700 Subject: [PATCH] Use the existence of .git to determine if git-describe is used. Fixes installation errors if Git is missing. Switch some string formatting to use f-strings. --- CHANGELOG.rst | 2 ++ setup.py | 17 +++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f24b7314..cb6a212b 100755 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,8 @@ v2.0.0 Unreleased ------------------ +Fixed + - Git is no longer required to install from source. 12.6.1 - 2021-06-09 ------------------- diff --git a/setup.py b/setup.py index 9f10b161..aa3ca8cf 100755 --- a/setup.py +++ b/setup.py @@ -4,9 +4,9 @@ import pathlib import platform import re +import subprocess import sys import warnings -from subprocess import CalledProcessError, check_output from typing import List from setuptools import setup # type: ignore @@ -18,25 +18,22 @@ def get_version() -> str: """Get the current version from a git tag, or by reading tcod/version.py""" - try: - tag = check_output(["git", "describe", "--abbrev=0"], universal_newlines=True).strip() + if (PATH / ".git").exists(): + tag = subprocess.check_output(["git", "describe", "--abbrev=0"], universal_newlines=True).strip() assert not tag.startswith("v") version = tag # add .devNN if needed - log = check_output( - ["git", "log", "%s..HEAD" % tag, "--oneline"], - universal_newlines=True, - ) + log = subprocess.check_output(["git", "log", f"{tag}..HEAD", "--oneline"], universal_newlines=True) commits_since_tag = log.count("\n") if commits_since_tag: version += ".dev%i" % commits_since_tag # update tcod/version.py with open(PATH / "tcod/version.py", "w") as version_file: - version_file.write('__version__ = "%s"\n' % version) + version_file.write(f'__version__ = "{version}"\n') return version - except CalledProcessError: + else: # Not a Git respotitory. try: with open(PATH / "tcod/version.py") as version_file: match = re.match(r'__version__ = "(\S+)"', version_file.read()) @@ -81,7 +78,7 @@ def check_sdl_version() -> None: return needed_version = "%i.%i.%i" % SDL_VERSION_NEEDED try: - sdl_version_str = check_output(["sdl2-config", "--version"], universal_newlines=True).strip() + sdl_version_str = subprocess.check_output(["sdl2-config", "--version"], universal_newlines=True).strip() except FileNotFoundError: raise RuntimeError( "libsdl2-dev or equivalent must be installed on your system"