Skip to content

Commit

Permalink
Use the existence of .git to determine if git-describe is used.
Browse files Browse the repository at this point in the history
Fixes installation errors if Git is missing.

Switch some string formatting to use f-strings.
  • Loading branch information
HexDecimal committed Jun 15, 2021
1 parent 08934cd commit e1e2012
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ v2.0.0

Unreleased
------------------
Fixed
- Git is no longer required to install from source.

12.6.1 - 2021-06-09
-------------------
Expand Down
17 changes: 7 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit e1e2012

Please sign in to comment.