Skip to content

Commit e1e2012

Browse files
committed
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.
1 parent 08934cd commit e1e2012

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

CHANGELOG.rst

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ v2.0.0
88

99
Unreleased
1010
------------------
11+
Fixed
12+
- Git is no longer required to install from source.
1113

1214
12.6.1 - 2021-06-09
1315
-------------------

setup.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import pathlib
55
import platform
66
import re
7+
import subprocess
78
import sys
89
import warnings
9-
from subprocess import CalledProcessError, check_output
1010
from typing import List
1111

1212
from setuptools import setup # type: ignore
@@ -18,25 +18,22 @@
1818

1919
def get_version() -> str:
2020
"""Get the current version from a git tag, or by reading tcod/version.py"""
21-
try:
22-
tag = check_output(["git", "describe", "--abbrev=0"], universal_newlines=True).strip()
21+
if (PATH / ".git").exists():
22+
tag = subprocess.check_output(["git", "describe", "--abbrev=0"], universal_newlines=True).strip()
2323
assert not tag.startswith("v")
2424
version = tag
2525

2626
# add .devNN if needed
27-
log = check_output(
28-
["git", "log", "%s..HEAD" % tag, "--oneline"],
29-
universal_newlines=True,
30-
)
27+
log = subprocess.check_output(["git", "log", f"{tag}..HEAD", "--oneline"], universal_newlines=True)
3128
commits_since_tag = log.count("\n")
3229
if commits_since_tag:
3330
version += ".dev%i" % commits_since_tag
3431

3532
# update tcod/version.py
3633
with open(PATH / "tcod/version.py", "w") as version_file:
37-
version_file.write('__version__ = "%s"\n' % version)
34+
version_file.write(f'__version__ = "{version}"\n')
3835
return version
39-
except CalledProcessError:
36+
else: # Not a Git respotitory.
4037
try:
4138
with open(PATH / "tcod/version.py") as version_file:
4239
match = re.match(r'__version__ = "(\S+)"', version_file.read())
@@ -81,7 +78,7 @@ def check_sdl_version() -> None:
8178
return
8279
needed_version = "%i.%i.%i" % SDL_VERSION_NEEDED
8380
try:
84-
sdl_version_str = check_output(["sdl2-config", "--version"], universal_newlines=True).strip()
81+
sdl_version_str = subprocess.check_output(["sdl2-config", "--version"], universal_newlines=True).strip()
8582
except FileNotFoundError:
8683
raise RuntimeError(
8784
"libsdl2-dev or equivalent must be installed on your system"

0 commit comments

Comments
 (0)