Skip to content

Commit

Permalink
Move to pyproject.toml; CI python 3.12.
Browse files Browse the repository at this point in the history
  • Loading branch information
anntzer committed Oct 20, 2023
1 parent f09526a commit e2e81a4
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 119 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graft dds
2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
88 changes: 84 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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"],
)
110 changes: 0 additions & 110 deletions setupext.py

This file was deleted.

0 comments on commit e2e81a4

Please sign in to comment.