Skip to content

Commit 1ad3f8e

Browse files
committed
Ensure cffi is available for the setup script.
The setup script will now crash instead of printing a warning which mostly gets ignored by pip. Add missing build-backend to pyproject.toml.
1 parent 47353dc commit 1ad3f8e

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ v2.0.0
88

99
Unreleased
1010
------------------
11+
Fixed
12+
- The setup script should no longer fail silently when cffi is not available.
1113

1214
12.5.0 - 2021-05-21
1315
-------------------

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ requires = [
55
"cffi~=1.13",
66
"pycparser>=2.14",
77
]
8+
build-backend = "setuptools.build-meta"
89

910
[tool.black]
1011
line-length = 79

setup.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/usr/bin/env python3
22

3-
import sys
43
import os
5-
6-
from setuptools import setup
7-
8-
from subprocess import check_output
94
import platform
5+
import sys
106
import warnings
7+
from subprocess import CalledProcessError, check_output
8+
from typing import List
9+
10+
from setuptools import setup
1111

1212
SDL_VERSION_NEEDED = (2, 0, 5)
1313

1414

15-
def get_version():
15+
def get_version() -> str:
1616
"""Get the current version from a git tag, or by reading tcod/version.py"""
1717
try:
1818
tag = check_output(
@@ -31,27 +31,28 @@ def get_version():
3131
version += ".dev%i" % commits_since_tag
3232

3333
# update tcod/version.py
34-
with open("tcod/version.py", "w") as f:
35-
f.write('__version__ = "%s"\n' % version)
34+
with open("tcod/version.py", "w") as version_file:
35+
version_file.write('__version__ = "%s"\n' % version)
3636
return version
37-
except:
37+
except CalledProcessError:
3838
try:
39-
exec(open("tcod/version.py").read(), globals())
40-
return __version__
39+
__version__ = "0.0.0"
40+
with open("tcod/version.py") as version_file:
41+
exec(version_file.read(), globals()) # Update __version__
4142
except FileNotFoundError:
4243
warnings.warn(
4344
"Unknown version: "
4445
"Not in a Git repository and not from a sdist bundle or wheel."
4546
)
46-
return "0.0.0"
47+
return __version__
4748

4849

4950
is_pypy = platform.python_implementation() == "PyPy"
5051

5152

52-
def get_package_data():
53+
def get_package_data() -> List[str]:
5354
"""get data files which will be included in the main tcod/ directory"""
54-
BITSIZE, LINKAGE = platform.architecture()
55+
BITSIZE, _ = platform.architecture()
5556
files = [
5657
"py.typed",
5758
"lib/LIBTCOD-CREDITS.txt",
@@ -68,13 +69,13 @@ def get_package_data():
6869
return files
6970

7071

71-
def get_long_description():
72+
def get_long_description() -> str:
7273
"""Return this projects description."""
73-
with open("README.rst", "r") as f:
74-
return f.read()
74+
with open("README.rst", "r") as readme_file:
75+
return readme_file.read()
7576

7677

77-
def check_sdl_version():
78+
def check_sdl_version() -> None:
7879
"""Check the local SDL version on Linux distributions."""
7980
if not sys.platform.startswith("linux"):
8081
return
@@ -127,13 +128,17 @@ def check_sdl_version():
127128
packages=["tcod", "tcod.__pyinstaller"],
128129
package_data={"tcod": get_package_data()},
129130
python_requires=">=3.6",
131+
setup_requires=[
132+
*pytest_runner,
133+
"cffi~=1.13",
134+
"pycparser>=2.14",
135+
],
130136
install_requires=[
131137
"cffi~=1.13", # Also required by pyproject.toml.
132138
"numpy~=1.10" if not is_pypy else "",
133139
"typing_extensions",
134140
],
135141
cffi_modules=["build_libtcod.py:ffi"],
136-
setup_requires=pytest_runner,
137142
tests_require=["pytest", "pytest-cov", "pytest-benchmark"],
138143
classifiers=[
139144
"Development Status :: 5 - Production/Stable",

0 commit comments

Comments
 (0)