Skip to content

Commit e3fc86b

Browse files
Cleanup code a little more (#7)
* a little more cleanup * format yaml * cleanup cpp * remove unused definition
1 parent 34e5efd commit e3fc86b

7 files changed

Lines changed: 154 additions & 210 deletions

File tree

.github/workflows/test.yml

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
pull_request:
66
schedule:
7-
- cron: "14 3 15 * *" # Runs at 03:14 UTC on the 15th of every month
7+
- cron: "14 3 15 * *" # Runs at 03:14 UTC on the 15th of every month
88
push:
99
branches:
1010
- main
@@ -20,80 +20,80 @@ jobs:
2020
runs-on: ${{ matrix.os }}
2121

2222
steps:
23-
- uses: actions/checkout@v4
24-
25-
- name: Cache dependencies
26-
id: cache-vcpkg-deps
27-
uses: actions/cache@v4
28-
with:
29-
path: vcpkg_installed
30-
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}
31-
32-
- name: Export vcpkg host triplet for compilation
33-
shell: bash
34-
run: |
35-
if [[ "$RUNNER_OS" == "Windows" ]]; then
36-
VCPKG_HOST_TRIPLET=x64-windows-static-md
37-
elif [[ "$RUNNER_OS" == "Linux" ]]; then
38-
VCPKG_HOST_TRIPLET=x64-linux
39-
elif [[ "$RUNNER_OS" == "macOS" ]]; then
40-
VCPKG_HOST_TRIPLET=arm64-osx
41-
fi
42-
echo VCPKG_HOST_TRIPLET="$VCPKG_HOST_TRIPLET" >> $GITHUB_ENV
43-
echo $VCPKG_HOST_TRIPLET
44-
45-
- name: Acquire vcpkg
46-
if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true'
47-
uses: actions/checkout@v4
48-
with:
49-
repository: "Microsoft/vcpkg"
50-
path: vcpkg
51-
ref: c9c17dcea3016bc241df0422e82b8aea212dcb93
52-
53-
- name: Install libraries with vcpkg.json
54-
if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true'
55-
shell: bash
56-
run: |
57-
./vcpkg/bootstrap-vcpkg.sh
58-
./vcpkg/vcpkg install --host-triplet="$VCPKG_HOST_TRIPLET"
59-
60-
- uses: actions/setup-python@v5
61-
with:
62-
python-version: ${{ matrix.python-version }}
63-
64-
- name: Install uv
65-
uses: astral-sh/setup-uv@v5
66-
with:
67-
cache-dependency-glob: "**/pyproject.toml"
68-
69-
- name: Build pybmds
70-
if: runner.os != 'Windows'
71-
run: |
72-
uv pip install pybind11==3.0.0 --target=./pybind11
73-
74-
uv venv --python=${{ matrix.python-version }}
75-
76-
source .venv/bin/activate
77-
78-
export CMAKE_PREFIX_PATH=${{ github.workspace }}/pybind11/pybind11/share/cmake
79-
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)
80-
81-
uv pip install -v -e ".[dev]"
82-
83-
py.test
84-
85-
- name: Build pybmds
86-
if: runner.os == 'Windows'
87-
run: |
88-
uv pip install pybind11==3.0.0 --target=./pybind11
89-
90-
uv venv --python=${{ matrix.python-version }}
91-
92-
.venv/Scripts/activate
93-
94-
$env:CMAKE_PREFIX_PATH="${{ github.workspace }}\pybind11\pybind11\share\cmake"
95-
$env:CMAKE_BUILD_PARALLEL_LEVEL = [Environment]::ProcessorCount
96-
97-
uv pip install -v -e ".[dev]"
98-
99-
py.test
23+
- uses: actions/checkout@v4
24+
25+
- name: Cache dependencies
26+
id: cache-vcpkg-deps
27+
uses: actions/cache@v4
28+
with:
29+
path: vcpkg_installed
30+
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}
31+
32+
- name: Export vcpkg host triplet for compilation
33+
shell: bash
34+
run: |
35+
if [[ "$RUNNER_OS" == "Windows" ]]; then
36+
VCPKG_HOST_TRIPLET=x64-windows-static-md
37+
elif [[ "$RUNNER_OS" == "Linux" ]]; then
38+
VCPKG_HOST_TRIPLET=x64-linux
39+
elif [[ "$RUNNER_OS" == "macOS" ]]; then
40+
VCPKG_HOST_TRIPLET=arm64-osx
41+
fi
42+
echo VCPKG_HOST_TRIPLET="$VCPKG_HOST_TRIPLET" >> $GITHUB_ENV
43+
echo $VCPKG_HOST_TRIPLET
44+
45+
- name: Acquire vcpkg
46+
if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true'
47+
uses: actions/checkout@v4
48+
with:
49+
repository: "Microsoft/vcpkg"
50+
path: vcpkg
51+
ref: c9c17dcea3016bc241df0422e82b8aea212dcb93
52+
53+
- name: Install libraries with vcpkg.json
54+
if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true'
55+
shell: bash
56+
run: |
57+
./vcpkg/bootstrap-vcpkg.sh
58+
./vcpkg/vcpkg install --host-triplet="$VCPKG_HOST_TRIPLET"
59+
60+
- uses: actions/setup-python@v5
61+
with:
62+
python-version: ${{ matrix.python-version }}
63+
64+
- name: Install uv
65+
uses: astral-sh/setup-uv@v5
66+
with:
67+
cache-dependency-glob: "**/pyproject.toml"
68+
69+
- name: Build pybmds
70+
if: runner.os != 'Windows'
71+
run: |
72+
uv pip install pybind11==3.0.0 --target=./pybind11
73+
74+
uv venv --python=${{ matrix.python-version }}
75+
76+
source .venv/bin/activate
77+
78+
export CMAKE_PREFIX_PATH=${{ github.workspace }}/pybind11/pybind11/share/cmake
79+
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)
80+
81+
uv pip install -v -e ".[dev]"
82+
83+
py.test
84+
85+
- name: Build pybmds
86+
if: runner.os == 'Windows'
87+
run: |
88+
uv pip install pybind11==3.0.0 --target=./pybind11
89+
90+
uv venv --python=${{ matrix.python-version }}
91+
92+
.venv/Scripts/activate
93+
94+
$env:CMAKE_PREFIX_PATH="${{ github.workspace }}\pybind11\pybind11\share\cmake"
95+
$env:CMAKE_BUILD_PARALLEL_LEVEL = [Environment]::ProcessorCount
96+
97+
uv pip install -v -e ".[dev]"
98+
99+
py.test

.github/workflows/wheels.yml

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ on:
44
workflow_dispatch:
55
pull_request:
66
schedule:
7-
- cron: "14 3 15 * *" # Runs at 03:14 UTC on the 15th of every month
7+
- cron: "14 3 15 * *" # Runs at 03:14 UTC on the 15th of every month
88
push:
99
branches:
10-
- main
10+
- main
1111

1212
jobs:
1313
build_wheels:
@@ -19,61 +19,61 @@ jobs:
1919
os: [ubuntu-24.04, windows-2022, macos-14]
2020

2121
steps:
22-
- uses: actions/checkout@v4
22+
- uses: actions/checkout@v4
2323

24-
- name: Cache dependencies
25-
id: cache-vcpkg-deps
26-
uses: actions/cache@v4
27-
with:
28-
path: vcpkg_installed
29-
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}
24+
- name: Cache dependencies
25+
id: cache-vcpkg-deps
26+
uses: actions/cache@v4
27+
with:
28+
path: vcpkg_installed
29+
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}
3030

31-
- name: Acquire vcpkg
32-
uses: actions/checkout@v4
33-
with:
34-
repository: "Microsoft/vcpkg"
35-
path: vcpkg
36-
ref: c9c17dcea3016bc241df0422e82b8aea212dcb93
31+
- name: Acquire vcpkg
32+
uses: actions/checkout@v4
33+
with:
34+
repository: "Microsoft/vcpkg"
35+
path: vcpkg
36+
ref: c9c17dcea3016bc241df0422e82b8aea212dcb93
3737

38-
- name: Export vcpkg host triplet for compilation
39-
shell: bash
40-
run: |
41-
if [[ "$RUNNER_OS" == "Windows" ]]; then
42-
VCPKG_HOST_TRIPLET=x64-windows-static-md
43-
elif [[ "$RUNNER_OS" == "Linux" ]]; then
44-
VCPKG_HOST_TRIPLET=x64-linux
45-
elif [[ "$RUNNER_OS" == "macOS" ]]; then
46-
VCPKG_HOST_TRIPLET=arm64-osx
47-
fi
48-
echo VCPKG_HOST_TRIPLET="$VCPKG_HOST_TRIPLET" >> $GITHUB_ENV
49-
echo $VCPKG_HOST_TRIPLET
38+
- name: Export vcpkg host triplet for compilation
39+
shell: bash
40+
run: |
41+
if [[ "$RUNNER_OS" == "Windows" ]]; then
42+
VCPKG_HOST_TRIPLET=x64-windows-static-md
43+
elif [[ "$RUNNER_OS" == "Linux" ]]; then
44+
VCPKG_HOST_TRIPLET=x64-linux
45+
elif [[ "$RUNNER_OS" == "macOS" ]]; then
46+
VCPKG_HOST_TRIPLET=arm64-osx
47+
fi
48+
echo VCPKG_HOST_TRIPLET="$VCPKG_HOST_TRIPLET" >> $GITHUB_ENV
49+
echo $VCPKG_HOST_TRIPLET
5050
51-
- uses: pypa/cibuildwheel@v3.1.3
52-
env:
53-
CIBW_BUILD: "cp313-*"
54-
CIBW_SKIP: "*musllinux* *win32*"
55-
CIBW_TEST_COMMAND: pytest {project}/tests
56-
CIBW_TEST_EXTRAS: dev
51+
- uses: pypa/cibuildwheel@v3.1.3
52+
env:
53+
CIBW_BUILD: "cp313-*"
54+
CIBW_SKIP: "*musllinux* *win32*"
55+
CIBW_TEST_COMMAND: pytest {project}/tests
56+
CIBW_TEST_EXTRAS: dev
5757

58-
CIBW_BEFORE_BUILD: rm -rf {project}/build
59-
CIBW_BEFORE_ALL_WINDOWS: bash tools\cibw_before.sh
60-
CIBW_ENVIRONMENT_WINDOWS: "CMAKE_PREFIX_PATH=D:/a/pycpp/pycpp/pybind11/pybind11/share/cmake"
58+
CIBW_BEFORE_BUILD: rm -rf {project}/build
59+
CIBW_BEFORE_ALL_WINDOWS: bash tools\cibw_before.sh
60+
CIBW_ENVIRONMENT_WINDOWS: "CMAKE_PREFIX_PATH=D:/a/pycpp/pycpp/pybind11/pybind11/share/cmake"
6161

62-
CIBW_ENVIRONMENT_PASS_LINUX: "VCPKG_HOST_TRIPLET RUNNER_OS"
63-
CIBW_BEFORE_ALL_LINUX: "source tools/cibw_before.sh"
64-
CIBW_ENVIRONMENT_LINUX: "CMAKE_PREFIX_PATH=/project/pybind11/pybind11/share/cmake"
62+
CIBW_ENVIRONMENT_PASS_LINUX: "VCPKG_HOST_TRIPLET RUNNER_OS"
63+
CIBW_BEFORE_ALL_LINUX: "source tools/cibw_before.sh"
64+
CIBW_ENVIRONMENT_LINUX: "CMAKE_PREFIX_PATH=/project/pybind11/pybind11/share/cmake"
6565

66-
CIBW_BEFORE_ALL_MACOS: "source tools/cibw_before.sh"
67-
CIBW_ENVIRONMENT_MACOS: "CMAKE_PREFIX_PATH=${{ github.workspace }}/pybind11/pybind11/share/cmake"
68-
MACOSX_DEPLOYMENT_TARGET: "14.0"
66+
CIBW_BEFORE_ALL_MACOS: "source tools/cibw_before.sh"
67+
CIBW_ENVIRONMENT_MACOS: "CMAKE_PREFIX_PATH=${{ github.workspace }}/pybind11/pybind11/share/cmake"
68+
MACOSX_DEPLOYMENT_TARGET: "14.0"
6969

70-
- uses: actions/upload-artifact@v4
71-
with:
72-
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
73-
path: ./wheelhouse/*.whl
70+
- uses: actions/upload-artifact@v4
71+
with:
72+
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
73+
path: ./wheelhouse/*.whl
7474

7575
merge_wheels:
76-
runs-on: ubuntu-22.04
76+
runs-on: ubuntu-24.04
7777
needs: build_wheels
7878
steps:
7979
- name: Merge Artifacts

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ _generate/
77
*.egg-info
88
*env*
99

10-
cfg/
1110
pybind11/
1211
vcpkg/
1312
vcpkg_installed/

CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,3 @@ target_include_directories(cppcore PRIVATE ${NLOPT_DIR_INCLUDE_DIR})
4141
target_link_libraries(cppcore PRIVATE ${NLOPT_LIB})
4242
target_link_libraries(cppcore PRIVATE ${GSL_LIB})
4343
target_link_libraries(cppcore PRIVATE ${GSLCBLAS_LIB})
44-
45-
target_compile_definitions(
46-
cppcore
47-
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO}
48-
)

setup.py

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from setuptools import Extension, setup
66
from setuptools.command.build_ext import build_ext
77

8-
# Convert distutils Windows platform specifiers to CMake -A arguments
98
PLAT_TO_CMAKE = {
109
"win32": "Win32",
1110
"win-amd64": "x64",
@@ -14,25 +13,20 @@
1413
}
1514

1615

17-
# A CMakeExtension needs a sourcedir instead of a file list.
18-
# The name must be the _single_ output extension from the CMake build.
19-
# If you need multiple extensions, see scikit-build.
2016
class CMakeExtension(Extension):
2117
def __init__(self, name: str, sourcedir: str = "") -> None:
2218
super().__init__(name, sources=[])
23-
self.sourcedir = os.fspath(Path(sourcedir).resolve())
19+
self.sourcedir = str(Path(sourcedir).resolve())
2420

2521

2622
class CMakeBuild(build_ext):
2723
def build_extension(self, ext: CMakeExtension) -> None:
28-
# Must be in this form due to bug in .resolve() only fixed in Python 3.10+
29-
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
30-
extdir = ext_fullpath.parent.resolve()
24+
ext_fullpath = Path(self.get_ext_fullpath(ext.name)).resolve()
25+
extdir = ext_fullpath.parent
3126

3227
debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
3328
cfg = "Debug" if debug else "Release"
3429

35-
cmake_generator = os.environ.get("CMAKE_GENERATOR", "")
3630
cmake_args = [
3731
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
3832
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
@@ -41,35 +35,16 @@ def build_extension(self, ext: CMakeExtension) -> None:
4135
if "CMAKE_ARGS" in os.environ:
4236
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]
4337

44-
if self.compiler.compiler_type != "msvc":
45-
if not cmake_generator or cmake_generator == "Ninja":
46-
try:
47-
import ninja
48-
49-
ninja_executable_path = Path(ninja.BIN_DIR) / "ninja"
50-
cmake_args += [
51-
"-GNinja",
52-
f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}",
53-
]
54-
except ImportError:
55-
pass
56-
57-
else:
58-
single_config = any(x in cmake_generator for x in {"NMake", "Ninja"})
59-
contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})
60-
61-
if not single_config and not contains_arch:
62-
cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]
63-
64-
if not single_config:
65-
cmake_args += [
66-
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}"
67-
]
68-
build_args += ["--config", cfg]
38+
if self.compiler.compiler_type == "msvc":
39+
cmake_args += [
40+
"-A",
41+
PLAT_TO_CMAKE[self.plat_name],
42+
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}",
43+
]
44+
build_args += ["--config", cfg]
6945

7046
build_temp = Path(self.build_temp) / ext.name
71-
if not build_temp.exists():
72-
build_temp.mkdir(parents=True)
47+
build_temp.mkdir(parents=True, exist_ok=True)
7348

7449
subprocess.run(
7550
["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True

0 commit comments

Comments
 (0)