diff --git a/.github/workflows/create_tag.yml b/.github/workflows/create_tag.yml index b1b0cb2..65392b7 100644 --- a/.github/workflows/create_tag.yml +++ b/.github/workflows/create_tag.yml @@ -34,9 +34,19 @@ jobs: strategy: fail-fast: false matrix: - os: [ ubuntu-latest ] + os: [ ubuntu-latest, macos-13, macos-14 ] steps: + - name: Set MACOSX_DEPLOYMENT_TARGET + run: | + if [[ ${{ matrix.os }} = macos-13 ]] + then + echo "MACOSX_DEPLOYMENT_TARGET=13.0" >> "$GITHUB_ENV" + elif [[ ${{ matrix.os }} = macos-14 ]] + then + echo "MACOSX_DEPLOYMENT_TARGET=14.0" >> "$GITHUB_ENV" + fi + - name: Checkout the repository uses: actions/checkout@v4 with: diff --git a/.github/workflows/pr_to_master.yml b/.github/workflows/pr_to_master.yml index 365cd3b..c2a0abd 100644 --- a/.github/workflows/pr_to_master.yml +++ b/.github/workflows/pr_to_master.yml @@ -1,4 +1,4 @@ -name: Check PR +name: Check PR to master on: pull_request: @@ -12,9 +12,19 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest] + os: [ubuntu-latest, macos-13, macos-14] steps: + - name: Set MACOSX_DEPLOYMENT_TARGET + run: | + if [[ ${{ matrix.os }} = macos-13 ]] + then + echo "MACOSX_DEPLOYMENT_TARGET=13.0" >> "$GITHUB_ENV" + elif [[ ${{ matrix.os }} = macos-14 ]] + then + echo "MACOSX_DEPLOYMENT_TARGET=14.0" >> "$GITHUB_ENV" + fi + - name: Checkout the repository uses: actions/checkout@v4 with: @@ -36,7 +46,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest] + os: [ubuntu-latest, macos-13, macos-14] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: @@ -61,7 +71,17 @@ jobs: run: pip install wheel - name: Install locally - run: pip install "$(echo dist/swisspair*cp"$(tr -d . <<< "${{ matrix.python-version }}")"*manylinux*x86_64*.whl)"[test] + run: | + if [[ ${{ matrix.os }} = ubuntu-latest ]] + then + pip install "$(echo dist/swisspair*cp"$(tr -d . <<< "${{ matrix.python-version }}")"*manylinux*x86_64*.whl)"[test] + elif [[ ${{ matrix.os }} = macos-13 ]] + then + pip install "$(echo dist/swisspair*cp"$(tr -d . <<< "${{ matrix.python-version }}")"*macosx_13_0*x86_64*.whl)"[test] + elif [[ ${{ matrix.os }} = macos-14 ]] + then + pip install "$(echo dist/swisspair*cp"$(tr -d . <<< "${{ matrix.python-version }}")"*macosx_14_0*arm64.whl)"[test] + fi - name: Run tests run: pytest diff --git a/.github/workflows/push_master.yml b/.github/workflows/push_master.yml index 6b66808..7aa710e 100644 --- a/.github/workflows/push_master.yml +++ b/.github/workflows/push_master.yml @@ -56,9 +56,19 @@ jobs: strategy: fail-fast: false matrix: - os: [ ubuntu-latest ] + os: [ ubuntu-latest, macos-13, macos-14 ] steps: + - name: Set MACOSX_DEPLOYMENT_TARGET + run: | + if [[ ${{ matrix.os }} = macos-13 ]] + then + echo "MACOSX_DEPLOYMENT_TARGET=13.0" >> "$GITHUB_ENV" + elif [[ ${{ matrix.os }} = macos-14 ]] + then + echo "MACOSX_DEPLOYMENT_TARGET=14.0" >> "$GITHUB_ENV" + fi + - name: Checkout the repository uses: actions/checkout@v4 with: @@ -114,7 +124,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ ubuntu-latest ] + os: [ ubuntu-latest, macos-13, macos-14 ] python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ] steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index b0c42f1..1ee8f73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,48 +1,30 @@ -# Require CMake 3.15+ (matching scikit-build-core) Use new versions of all -# policies up to CMake 3.27 cmake_minimum_required(VERSION 3.15...3.27) set(CMAKE_CXX_STANDARD 20) -set(CMAKE_INSTALL_RPATH $ORIGIN) - -execute_process ( - COMMAND bash -c "pybind11-config --cmakedir" - OUTPUT_VARIABLE CMAKEDIR -) - -add_definitions(-Dpybind11_DIR="${CMAKEDIR}") - -# Scikit-build-core sets these values for you, or you can just hard-code the -# name and version. project( ${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION} LANGUAGES CXX) -add_link_options(-lgmp) +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(CMAKE_MACOSX_RPATH 1) + set(CMAKE_INSTALL_RPATH @loader_path) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(CMAKE_INSTALL_RPATH $ORIGIN) +endif() + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_subdirectory(src/swisspair_cpp) -add_subdirectory(src/swisspair_cpp/gmpwrap) -add_subdirectory(src/swisspair_cpp/Minimum-Cost-Perfect-Matching) -# Find the module development requirements (requires FindPython from 3.17 or -# scikit-build-core's built-in backport) find_package(Python REQUIRED COMPONENTS Interpreter Development.Module) find_package(pybind11 CONFIG REQUIRED) -# Add a library using FindPython's tooling (pybind11 also provides a helper like -# this) python_add_library(_swisspair MODULE src/bindings.cpp WITH_SOABI) target_link_libraries(_swisspair PRIVATE pybind11::headers) target_link_libraries(_swisspair PRIVATE swisspair) -target_link_libraries(_swisspair PRIVATE gmpwrap) -target_link_libraries(_swisspair PRIVATE mincostpmatch) - -# This is passing in the version as a define just as an example -target_compile_definitions(_swisspair PRIVATE VERSION_INFO=${PROJECT_VERSION}) -# The install directory is the output (wheel) directory install(TARGETS _swisspair DESTINATION swisspair) install(TARGETS swisspair DESTINATION swisspair) install(TARGETS gmpwrap DESTINATION swisspair) diff --git a/README.md b/README.md index 707731d..f1a5e84 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ A python client for https://github.com/karlosss/swisspair - algorithm to pair pl - `pip install swisspair` -At the moment works only on Linux. +At the moment, Linux and MacOS are supported. ### Local installation diff --git a/pyproject.toml b/pyproject.toml index 2a1d657..a3bd780 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,11 +21,6 @@ before-all = """ yum -y install gmp-devel || apk add gmp-dev """ -[tool.cibuildwheel.macos] -before-all = """ -brew install gmp pkg-config -""" - [project.optional-dependencies] test = ["pytest"] diff --git a/src/bindings.cpp b/src/bindings.cpp index c7fc0ff..068ae20 100644 --- a/src/bindings.cpp +++ b/src/bindings.cpp @@ -1,40 +1,17 @@ #include #include + #include #include #include -namespace py = pybind11; - -struct Player { - std::string id; - std::set cannot_be_paired_against_ids; - bool can_get_bye = true; - int points; - int rank; - - std::string to_string() const; - - bool operator==(const Player& other) const; -}; - -struct Match { - Player p1; - Player p2; - bool is_bye; +#include "models/Match.h" +#include "models/Player.h" - Match(const Player & p1, const Player & p2); - Match(const Player & p1); - Match(const Match & other); - - bool operator<(const Match & other) const; - - - std::string to_string() const; -}; - -std::vector create_matches(const std::vector& players, bool powerPairing); +namespace py = pybind11; +std::vector create_matches(const std::vector &players, + bool powerPairing); PYBIND11_MODULE(_swisspair, m) { m.doc() = "Swiss pairing algorithm for not only Magic: The Gathering"; @@ -53,4 +30,4 @@ PYBIND11_MODULE(_swisspair, m) { .def_readonly("is_bye", &Match::is_bye); m.def("create_matches", &create_matches, "Creates a list of matches, ordered by the table number from the highest table. Power pairing guarantees the top 8 players to be paired according to their standing."); -} \ No newline at end of file +} diff --git a/src/swisspair_cpp b/src/swisspair_cpp index f74dd87..a177714 160000 --- a/src/swisspair_cpp +++ b/src/swisspair_cpp @@ -1 +1 @@ -Subproject commit f74dd87156e98b26a067c759b43b1c0648796d5f +Subproject commit a1777143f2707aa66111f616d039318ed13e527c