Skip to content

Commit

Permalink
Merge pull request #10 from karlosss/antoine-fixes
Browse files Browse the repository at this point in the history
Antoine fixes
  • Loading branch information
karlosss authored Oct 20, 2024
2 parents f828d7c + fe7f8d8 commit 7286512
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 70 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/create_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 24 additions & 4 deletions .github/workflows/pr_to_master.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check PR
name: Check PR to master

on:
pull_request:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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
14 changes: 12 additions & 2 deletions .github/workflows/push_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
34 changes: 8 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
37 changes: 7 additions & 30 deletions src/bindings.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <iostream>
#include <set>
#include <vector>

namespace py = pybind11;

struct Player {
std::string id;
std::set<std::string> 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<Match> create_matches(const std::vector<Player>& players, bool powerPairing);
namespace py = pybind11;

std::vector<Match> create_matches(const std::vector<Player> &players,
bool powerPairing);

PYBIND11_MODULE(_swisspair, m) {
m.doc() = "Swiss pairing algorithm for not only Magic: The Gathering";
Expand All @@ -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.");
}
}
2 changes: 1 addition & 1 deletion src/swisspair_cpp

0 comments on commit 7286512

Please sign in to comment.