|
4 | 4 | import pathlib
|
5 | 5 | import platform
|
6 | 6 | import re
|
| 7 | +import subprocess |
7 | 8 | import sys
|
8 | 9 | import warnings
|
9 |
| -from subprocess import CalledProcessError, check_output |
10 | 10 | from typing import List
|
11 | 11 |
|
12 | 12 | from setuptools import setup # type: ignore
|
|
18 | 18 |
|
19 | 19 | def get_version() -> str:
|
20 | 20 | """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() |
23 | 23 | assert not tag.startswith("v")
|
24 | 24 | version = tag
|
25 | 25 |
|
26 | 26 | # 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) |
31 | 28 | commits_since_tag = log.count("\n")
|
32 | 29 | if commits_since_tag:
|
33 | 30 | version += ".dev%i" % commits_since_tag
|
34 | 31 |
|
35 | 32 | # update tcod/version.py
|
36 | 33 | 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') |
38 | 35 | return version
|
39 |
| - except CalledProcessError: |
| 36 | + else: # Not a Git respotitory. |
40 | 37 | try:
|
41 | 38 | with open(PATH / "tcod/version.py") as version_file:
|
42 | 39 | match = re.match(r'__version__ = "(\S+)"', version_file.read())
|
@@ -81,7 +78,7 @@ def check_sdl_version() -> None:
|
81 | 78 | return
|
82 | 79 | needed_version = "%i.%i.%i" % SDL_VERSION_NEEDED
|
83 | 80 | 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() |
85 | 82 | except FileNotFoundError:
|
86 | 83 | raise RuntimeError(
|
87 | 84 | "libsdl2-dev or equivalent must be installed on your system"
|
|
0 commit comments