forked from libtcod/python-tcod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·154 lines (135 loc) · 5.52 KB
/
setup.py
File metadata and controls
executable file
·154 lines (135 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python3
from __future__ import annotations
import platform
import re
import subprocess
import sys
import warnings
from pathlib import Path
from typing import List
from setuptools import setup
SDL_VERSION_NEEDED = (2, 0, 5)
SETUP_DIR = Path(__file__).parent # setup.py current directory
def get_version() -> str:
"""Get the current version from a git tag, or by reading tcod/version.py"""
if (SETUP_DIR / ".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 = 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
(SETUP_DIR / "tcod/version.py").write_text(f'__version__ = "{version}"\n', encoding="utf-8")
return version
else: # Not a Git repository.
try:
match = re.match(r'__version__ = "(\S+)"', (SETUP_DIR / "tcod/version.py").read_text(encoding="utf-8"))
assert match
return match.groups()[0]
except FileNotFoundError:
warnings.warn("Unknown version: Not in a Git repository and not from a sdist bundle or wheel.")
return "0.0.0"
is_pypy = platform.python_implementation() == "PyPy"
def get_package_data() -> List[str]:
"""get data files which will be included in the main tcod/ directory"""
BITSIZE, _ = platform.architecture()
files = [
"py.typed",
"lib/LIBTCOD-CREDITS.txt",
"lib/LIBTCOD-LICENSE.txt",
"lib/README-SDL.txt",
]
if "win32" in sys.platform:
if BITSIZE == "32bit":
files += ["x86/SDL2.dll"]
else:
files += ["x64/SDL2.dll"]
if sys.platform == "darwin":
files += ["SDL2.framework/Versions/A/SDL2"]
return files
def check_sdl_version() -> None:
"""Check the local SDL version on Linux distributions."""
if not sys.platform.startswith("linux"):
return
needed_version = "%i.%i.%i" % SDL_VERSION_NEEDED
try:
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"
" and must be at least version %s."
"\nsdl2-config must be on PATH." % (needed_version,)
)
print("Found SDL %s." % (sdl_version_str,))
sdl_version = tuple(int(s) for s in sdl_version_str.split("."))
if sdl_version < SDL_VERSION_NEEDED:
raise RuntimeError("SDL version must be at least %s, (found %s)" % (needed_version, sdl_version_str))
if not (SETUP_DIR / "libtcod/src").exists():
print("Libtcod submodule is uninitialized.")
print("Did you forget to run 'git submodule update --init'?")
sys.exit(1)
check_sdl_version()
needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv)
pytest_runner = ["pytest-runner"] if needs_pytest else []
setup(
name="tcod",
version=get_version(),
author="Kyle Benesch",
author_email="4b796c65+tcod@gmail.com",
description="The official Python port of libtcod.",
long_description=(SETUP_DIR / "README.rst").read_text(encoding="utf-8"),
url="https://github.com/libtcod/python-tcod",
project_urls={
"Documentation": "https://python-tcod.readthedocs.io",
"Changelog": "https://github.com/libtcod/python-tcod/blob/main/CHANGELOG.md",
"Source": "https://github.com/libtcod/python-tcod",
"Tracker": "https://github.com/libtcod/python-tcod/issues",
"Forum": "https://github.com/libtcod/python-tcod/discussions",
},
py_modules=["libtcodpy"],
packages=["tcod", "tcod.sdl", "tcod.__pyinstaller"],
package_data={"tcod": get_package_data()},
python_requires=">=3.7",
setup_requires=[
*pytest_runner,
"cffi>=1.15",
"requests>=2.28.1",
"pycparser>=2.14",
"pcpp==1.30",
],
install_requires=[
"cffi>=1.15", # Also required by pyproject.toml.
"numpy>=1.21.4" if not is_pypy else "",
"typing_extensions",
],
cffi_modules=["build_libtcod.py:ffi"],
tests_require=["pytest", "pytest-cov", "pytest-benchmark"],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Win32 (MS Windows)",
"Environment :: MacOS X",
"Environment :: X11 Applications",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: POSIX",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Games/Entertainment",
"Topic :: Multimedia :: Graphics",
"Topic :: Software Development :: Libraries :: Python Modules",
],
keywords="roguelike cffi Unicode libtcod field-of-view pathfinding",
platforms=["Windows", "MacOS", "Linux"],
license="Simplified BSD License",
)