Skip to content

Commit f9587ca

Browse files
Update to a scikit-build build. (#33)
Using scikit-build-core for the full build. It still needs libgd and its dependencies -- works fine with conda-forge, but still working on other sources of libs. * removed old setup.py Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent df8657c commit f9587ca

9 files changed

Lines changed: 163 additions & 177 deletions

File tree

.github/workflows/conda_test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Run tests with miniforge
22
on: [push]
33

4+
concurrency:
5+
group: ${{ github.workflow }}-${{ github.ref }}
6+
cancel-in-progress: true
7+
48
jobs:
59
test:
610
name: Miniconda ${{ matrix.os }} Py${{ matrix.pyver }}
@@ -15,10 +19,8 @@ jobs:
1519
- uses: conda-incubator/setup-miniconda@v3
1620
with:
1721
auto-update-conda: true
18-
activate-environment: test
1922
miniforge-version: latest
2023
python-version: ${{ matrix.pyver }}
21-
auto-activate-base: false
2224
conda-remove-defaults: true
2325

2426
- name: Setup environment
@@ -49,10 +51,8 @@ jobs:
4951
- uses: conda-incubator/setup-miniconda@v3
5052
with:
5153
auto-update-conda: true
52-
activate-environment: test
5354
miniforge-version: latest
5455
python-version: "3.10"
55-
auto-activate-base: false
5656
conda-remove-defaults: true
5757
- name: Lint
5858
shell: bash -l {0}

.github/workflows/static_docs.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Simple workflow for deploying static content to GitHub Pages
22
name: Deploy static content to Pages
33

4+
concurrency:
5+
group: ${{ github.workflow }}-${{ github.ref }}
6+
cancel-in-progress: true
7+
48
on:
5-
# Runs on pushes targeting the default branch
69
push:
710
branches: ["main"]
8-
9-
# Allows you to run this workflow manually from the Actions tab
1011
workflow_dispatch:
1112

1213
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
@@ -15,12 +16,6 @@ permissions:
1516
pages: write
1617
id-token: write
1718

18-
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19-
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20-
concurrency:
21-
group: "pages"
22-
cancel-in-progress: false
23-
2419
jobs:
2520
# Single deploy job since we're just deploying
2621
deploy:
@@ -45,5 +40,6 @@ jobs:
4540
# Upload entire repository
4641
path: 'docs/build/html'
4742
- name: Deploy to GitHub Pages
43+
# if: github.ref == 'refs/heads/main'
4844
id: deployment
4945
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#specific to this repo:
22

3+
# generated by cython
34
py_gd/py_gd.c
4-
# docs/examples/*.png
5-
# docs/examples/*.gif
65

6+
# generated by cibuildwheel for the libs
7+
install/
8+
libgd/
9+
build-libgd/
10+
libpng/
11+
build-libpng/
712

813
# mac files
914
.DS_Store
@@ -37,3 +42,4 @@ var/
3742

3843
#Test Files
3944
test_images_output/
45+
wheelhouse/

CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
cmake_minimum_required(VERSION 3.24...4.0)
2+
project(${SKBUILD_PROJECT_NAME} LANGUAGES C)
3+
4+
option(BUILD_DEPS OFF)
5+
6+
find_package(
7+
Python
8+
COMPONENTS Interpreter Development.Module NumPy
9+
REQUIRED)
10+
11+
include(UseCython)
12+
include(GNUInstallDirs)
13+
14+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
15+
16+
if(ENV{VCPKG_ROOT})
17+
message(STATUS "VCPKG_ROOT: $ENV{VCPKG_ROOT}")
18+
set(CMAKE_TOOLCHAIN_FILE "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
19+
endif()
20+
21+
# We do not use FetchContent because the CMakeLists of GD is terrible
22+
if(BUILD_DEPS)
23+
include(BuildGD)
24+
else()
25+
find_package(GD MODULE REQUIRED)
26+
endif()
27+
28+
cython_transpile(py_gd/py_gd.pyx LANGUAGE C OUTPUT_VARIABLE py_gd_c)
29+
python_add_library(py_gd MODULE "${py_gd_c}" WITH_SOABI)
30+
target_link_libraries(py_gd PUBLIC GD::GD Python::NumPy)
31+
install(TARGETS py_gd DESTINATION py_gd)
32+
33+
get_filename_component(GD_LIBRARY_DIR "${GD_LIBRARIES}" DIRECTORY)
34+
set_target_properties(py_gd PROPERTIES INSTALL_RPATH "${GD_LIBRARY_DIR}")
35+
36+
cython_transpile(py_gd/spline.pyx LANGUAGE C OUTPUT_VARIABLE spline_c)
37+
python_add_library(spline MODULE "${spline_c}" WITH_SOABI)
38+
target_link_libraries(spline PUBLIC Python::NumPy)
39+
install(TARGETS spline DESTINATION py_gd)
40+
41+

cmake/FindGD.cmake

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
find_package(PkgConfig)
2+
if(PKG_CONFIG_FOUND)
3+
pkg_check_modules(PC_GD QUIET GD)
4+
endif()
5+
6+
find_path(GD_INCLUDE_DIR
7+
NAMES gd.h
8+
HINTS "${PC_GD_INCLUDE_DIRS}"
9+
)
10+
11+
find_library(GD_LIBRARY
12+
NAMES gd
13+
HINTS "${PC_GD_INCLUDE_DIRS}"
14+
)
15+
16+
cmake_path(ABSOLUTE_PATH GD_LIBRARY)
17+
cmake_path(ABSOLUTE_PATH GD_INCLUDE_DIR)
18+
19+
include(FindPackageHandleStandardArgs)
20+
find_package_handle_standard_args(GD
21+
REQUIRED_VARS
22+
GD_LIBRARY
23+
GD_INCLUDE_DIR
24+
VERSION_VAR GD_VERSION
25+
)
26+
27+
if(GD_FOUND)
28+
set(GD_LIBRARIES "${GD_LIBRARY}")
29+
set(GD_INCLUDE_DIRS "${GD_INCLUDE_DIR}")
30+
set(Foo_DEFINITIONS ${PC_GD_CFLAGS_OTHER})
31+
endif()
32+
33+
if(GD_FOUND AND NOT TARGET GD::GD)
34+
add_library(GD::GD UNKNOWN IMPORTED)
35+
set_target_properties(GD::GD PROPERTIES
36+
IMPORTED_LOCATION "${GD_LIBRARY}"
37+
INTERFACE_COMPILE_OPTIONS "${PC_GD_CFLAGS_OTHER}"
38+
INTERFACE_INCLUDE_DIRECTORIES "${GD_INCLUDE_DIR}"
39+
)
40+
endif()
41+
42+
mark_as_advanced(
43+
GD_INCLUDE_DIR
44+
GD_LIBRARY
45+
)
46+

conda_requirements_dev.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ cython>=3
44
pytest
55
sphinx
66
ipython # nice to have, and used to help render the docs
7-
7+
cmake
8+
ninja
9+
scikit-build-core
10+
cython-cmake
11+
python-build

py_gd/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import sys
1414
import os
1515

16-
__version__ = "2.3.2"
16+
__version__ = "2.3.3"
1717

1818
if sys.platform.startswith('win'):
1919
# This only works for Anaconda / miniconda
@@ -33,14 +33,15 @@
3333
# "This kludge is only written to support Anaconda installs")
3434

3535
# alternative ugly kludge: add lib dir to PATH:
36-
if not (os.path.isfile(os.path.join(libpath, 'libpng16.dll')) and
36+
if (os.path.isfile(os.path.join(libpath, 'libpng16.dll')) and
3737
os.path.isfile(os.path.join(libpath, 'zlib.dll')) and
3838
os.path.isfile(os.path.join(libpath, 'libgd.dll'))):
39-
raise RuntimeError("Can't find dlls for libgd, libpng, and libz.\n"
40-
"This kludge is only written to support Anaconda installs\n",
41-
"you may need to add some logic for other library locations",
42-
)
43-
os.environ['PATH'] = libpath + os.pathsep + os.environ['PATH']
39+
os.environ['PATH'] = libpath + os.pathsep + os.environ['PATH']
40+
41+
# raise RuntimeError("Can't find dlls for libgd, libpng, and libz.\n"
42+
# "This kludge is only written to support Anaconda installs\n",
43+
# "you may need to add some logic for other library locations",
44+
# )
4445
try:
4546
from .py_gd import * # noqa: F401
4647

pyproject.toml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[build-system]
2+
requires = ["scikit-build-core", "cython", "numpy", "cython-cmake"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "py-gd"
7+
dynamic = ["version"]
8+
description = "python wrappers around libgd graphics lib"
9+
readme = "README.md"
10+
license = "CC0-1.0"
11+
license-files = ["LICENSE.txt"]
12+
requires-python = ">=3.10"
13+
authors = [
14+
{ name = "Christopher H. Barker", email = "chris.barker@noaa.gov" },
15+
]
16+
keywords = [
17+
"cython",
18+
"drawing",
19+
"graphics",
20+
]
21+
classifiers = [
22+
"Development Status :: 5 - Production/Stable",
23+
"Intended Audience :: Developers",
24+
"Operating System :: OS Independent",
25+
"Programming Language :: Cython",
26+
"Programming Language :: Python :: 3 :: Only",
27+
"Programming Language :: Python :: Implementation :: CPython",
28+
"Topic :: Multimedia :: Graphics",
29+
"Topic :: Utilities",
30+
]
31+
dependencies = ["numpy"]
32+
33+
[project.urls]
34+
Homepage = "https://github.com/NOAA-ORR-ERD/py_gd"
35+
36+
[dependency-groups]
37+
test = ["pytest"]
38+
build = ["scikit-build-core", "cython", "numpy", "cython-cmake"]
39+
dev = [{ include-group = "test" }, { include-group = "build"}, "build"]
40+
41+
[tool.scikit-build]
42+
build-dir = "build"
43+
44+
[tool.scikit-build.metadata.version]
45+
provider = "scikit_build_core.metadata.regex"
46+
input = "py_gd/__init__.py"

0 commit comments

Comments
 (0)