From e2e81a477fd31ae548a340b5f0f380594d3d0ad6 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 20 Oct 2023 18:40:54 +0200 Subject: [PATCH] Move to pyproject.toml; CI python 3.12. --- .github/workflows/build.yml | 6 +- MANIFEST.in | 1 + README.rst | 2 - pyproject.toml | 20 +++++++ setup.py | 88 +++++++++++++++++++++++++++-- setupext.py | 110 ------------------------------------ 6 files changed, 108 insertions(+), 119 deletions(-) create mode 100644 MANIFEST.in create mode 100644 pyproject.toml delete mode 100644 setupext.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e7b37be..36ea911 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,11 +12,11 @@ jobs: matrix: include: - {os: ubuntu-latest, python-version: "3.7"} - - {os: ubuntu-latest, python-version: "3.11"} + - {os: ubuntu-latest, python-version: "3.12"} - {os: macos-latest, python-version: "3.9"} - - {os: macos-latest, python-version: "3.11"} + - {os: macos-latest, python-version: "3.12"} - {os: windows-latest, python-version: "3.6"} - - {os: windows-latest, python-version: "3.11"} + - {os: windows-latest, python-version: "3.12"} fail-fast: false runs-on: ${{ matrix.os }} steps: diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..727c868 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +graft dds diff --git a/README.rst b/README.rst index d73188d..af4c1ef 100644 --- a/README.rst +++ b/README.rst @@ -44,8 +44,6 @@ not from the releases), and run, from the directory containing the archive, ``python -mpip install --user --upgrade redeal-main.zip`` (or whatever name it has). -Directly running ``setup.py`` is **not** supported in either case. - Now, run ``python -mredeal --help``, or ``python -mredeal`` to get a few hands, or ``python -mredeal examples/deal1.py`` for an example simulation. In the ``examples`` directory (which you can extract from the zip archive), ``python diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8ceb498 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,20 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "redeal" +description = "A reimplementation of Thomas Andrews' Deal in Python." +readme = "README.rst" +authors = [{name = "Antony Lee"}] +urls = {Repository = "https://github.com/anntzer/redeal"} +license = {file = "LICENSE.txt"} +version = "0.2.0" +requires-python = ">=3.6" +dependencies = ["colorama>=0.2.4"] + +[project.scripts] +redeal = "redeal.__main__:console_entry" + +[project.gui-scripts] +redeal-gui = "redeal.__main__:gui_entry" diff --git a/setup.py b/setup.py index 7e1ce22..5d49790 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,88 @@ +import contextlib +from contextlib import ExitStack +import os +from pathlib import Path +from tempfile import TemporaryDirectory +import shutil +import subprocess import sys +import urllib.request -if sys.version_info <= (3, 6): - sys.exit("Python>=3.6 is required, but your version is:\n%s" % sys.version) +import setuptools.command.build_ext -import setupext -setupext.main() +@contextlib.contextmanager +def patched_path(path, old, new): + contents = path.read_text() + if old not in contents: + raise Exception(f"Invalid patch: {old}") + try: + path.write_text(contents.replace(old, new)) + yield + finally: + path.write_text(contents) + + +patches = [ + ("Makefiles/Makefile_linux_shared", + "$(COMPILE_FLAGS)", "$(COMPILE_FLAGS) $(CFLAGS)"), + ("Makefiles/Makefile_Mac_clang_shared", + "$(COMPILE_FLAGS)", "$(COMPILE_FLAGS) $(CFLAGS)"), + ("Makefiles/Makefile_Mac_clang_shared", + "-Wextra", "-Wextra -Wno-deprecated-declarations -Wno-sign-conversion"), + ("Makefiles/Makefile_Mac_clang_shared", + "$(LINK_FLAGS)", "$(LINK_FLAGS) -lc++"), +] + + +class build_ext(setuptools.command.build_ext.build_ext): + def finalize_options(self): + super().finalize_options() + # Needs to be computed here because setuptools patches out inplace. + self.__dest_dir = Path(self.get_ext_fullpath("redeal._")).parent + + def build_extensions(self): + self.distribution.ext_modules[:] = [] + super().build_extensions() + if os.name == "posix": + dds_src = Path(__file__).resolve().parent / "dds/src" + if not dds_src.exists(): + sys.exit("""\ +DDS sources are missing. + +If you are using a git checkout, run + git submodule init && git submodule update + +On a Unix system, do not use the zip archives from github.""") + with ExitStack() as stack: + for name, old, new in patches: + stack.enter_context(patched_path(dds_src / name, old, new)) + if sys.platform.startswith("linux"): + subprocess.check_call( + ["make", "-f", "Makefiles/Makefile_linux_shared", + "THREADING=", "THREAD_LINK="], cwd=dds_src) + elif sys.platform == "darwin": + subprocess.check_call( + ["make", "-f", "Makefiles/Makefile_Mac_clang_shared", + "CC=gcc", "THREADING=", "THREAD_LINK="], cwd=dds_src) + shutil.copy2(dds_src / "libdds.so", self.__dest_dir) + elif os.name == "nt": + url = "https://privat.bahnhof.se/wb758135/bridge/dds290-dll.zip" + with TemporaryDirectory() as tmpdir: + tmppath = Path(tmpdir) + zip_path = tmppath / "dds290-dll.zip" + with urllib.request.urlopen(url) as req: + zip_path.write_bytes(req.read()) + shutil.unpack_archive(str(zip_path), tmpdir) # str() for Py36. + arch = "x64" if sys.maxsize > 2 ** 32 else "win32" + shutil.unpack_archive( + str(tmppath / f"dds290-dll/dds-290-multi-{arch}-dll.zip"), + tmppath) + shutil.copy2(tmppath / "dds.dll", self.__dest_dir) + + +setuptools.setup( + cmdclass={"build_ext": build_ext}, + ext_modules=[setuptools.Extension("", [])], + packages=["redeal"], +) diff --git a/setupext.py b/setupext.py deleted file mode 100644 index bd7696b..0000000 --- a/setupext.py +++ /dev/null @@ -1,110 +0,0 @@ -import contextlib -from contextlib import ExitStack -import os -from pathlib import Path -from tempfile import TemporaryDirectory -import shutil -import subprocess -import sys -import urllib.request - -try: - from setuptools import setup -except ImportError: - sys.exit("Please install setuptools by following the instructions at\n" - " https://pypi.python.org/pypi/setuptools") - -from setuptools import Extension -from setuptools.command.build_ext import build_ext - - -@contextlib.contextmanager -def patched_path(path, old, new): - contents = path.read_text() - if old not in contents: - raise Exception(f"Invalid patch: {old}") - try: - path.write_text(contents.replace(old, new)) - yield - finally: - path.write_text(contents) - - -patches = [ - ("Makefiles/Makefile_linux_shared", - "$(COMPILE_FLAGS)", "$(COMPILE_FLAGS) $(CFLAGS)"), - ("Makefiles/Makefile_Mac_clang_shared", - "$(COMPILE_FLAGS)", "$(COMPILE_FLAGS) $(CFLAGS)"), - ("Makefiles/Makefile_Mac_clang_shared", - "-Wextra", "-Wextra -Wno-deprecated-declarations -Wno-sign-conversion"), - ("Makefiles/Makefile_Mac_clang_shared", - "$(LINK_FLAGS)", "$(LINK_FLAGS) -lc++"), -] - - -class build_ext(build_ext): - def finalize_options(self): - super().finalize_options() - # Needs to be computed here because setuptools patches out inplace. - self.__dest_dir = Path(self.get_ext_fullpath("redeal._")).parent - - def build_extensions(self): - self.distribution.ext_modules[:] = [] - super().build_extensions() - if os.name == "posix": - dds_src = Path(__file__).resolve().parent / "dds/src" - if not dds_src.exists(): - sys.exit("""\ -DDS sources are missing. - -If you are using a git checkout, run - git submodule init && git submodule update - -On a Unix system, do not use the zip archives from github.""") - with ExitStack() as stack: - for name, old, new in patches: - stack.enter_context(patched_path(dds_src / name, old, new)) - if sys.platform.startswith("linux"): - subprocess.check_call( - ["make", "-f", "Makefiles/Makefile_linux_shared", - "THREADING=", "THREAD_LINK="], cwd=dds_src) - elif sys.platform == "darwin": - subprocess.check_call( - ["make", "-f", "Makefiles/Makefile_Mac_clang_shared", - "CC=gcc", "THREADING=", "THREAD_LINK="], cwd=dds_src) - shutil.copy2(dds_src / "libdds.so", self.__dest_dir) - elif os.name == "nt": - url = "https://privat.bahnhof.se/wb758135/bridge/dds290-dll.zip" - with TemporaryDirectory() as tmpdir: - tmppath = Path(tmpdir) - zip_path = tmppath / "dds290-dll.zip" - with urllib.request.urlopen(url) as req: - zip_path.write_bytes(req.read()) - shutil.unpack_archive(str(zip_path), tmpdir) # str() for Py36. - arch = "x64" if sys.maxsize > 2 ** 32 else "win32" - shutil.unpack_archive( - str(tmppath / f"dds290-dll/dds-290-multi-{arch}-dll.zip"), - tmppath) - shutil.copy2(tmppath / "dds.dll", self.__dest_dir) - - -def main(): - setup( - cmdclass={"build_ext": build_ext}, - name="redeal", - version="0.2.0", - author="Antony Lee", - author_email="anntzer.lee@gmail.com", - packages=["redeal"], - entry_points={ - "console_scripts": ["redeal = redeal.__main__:console_entry"], - "gui_scripts": ["redeal-gui = redeal.__main__:gui_entry"], - }, - url="http://github.com/anntzer/redeal", - license="LICENSE.txt", - description="A reimplementation of Thomas Andrews' Deal in Python.", - long_description=Path("README.rst").read_text(encoding="utf-8"), - python_requires=">=3.6", - install_requires=["colorama>=0.2.4"], - ext_modules=[Extension("", [])] - )