Skip to content

Commit a466ce9

Browse files
committed
Add some basic Python bindings
1 parent 691d41d commit a466ce9

File tree

12 files changed

+899
-2
lines changed

12 files changed

+899
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
libgpgme-dev
2323
libgtest-dev
2424
make
25+
python3-pytest
2526
valgrind
2627
env:
2728
DEBIAN_FRONTEND: noninteractive

.github/workflows/python.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: Python Packaging
3+
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
tags: ['*']
7+
workflow_dispatch:
8+
9+
jobs:
10+
sdist:
11+
runs-on: ubuntu-24.04
12+
steps:
13+
- uses: actions/checkout@v5
14+
- run: python -m pip install -U build
15+
- run: python -m build --sdist
16+
- uses: actions/upload-artifact@v4
17+
with:
18+
name: sdist
19+
path: dist/*.tar.gz
20+
wheel:
21+
strategy:
22+
matrix:
23+
include:
24+
- os: ubuntu-24.04
25+
arch: x86_64
26+
- os: ubuntu-24.04-arm
27+
arch: aarch64
28+
runs-on: ${{ matrix.os }}
29+
steps:
30+
- uses: actions/checkout@v5
31+
- uses: pypa/[email protected]
32+
- uses: actions/upload-artifact@v4
33+
with:
34+
name: ${{ matrix.arch }}
35+
path: ./wheelhouse/*.whl

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
/build
1+
/build/
2+
/dist/
3+
/wheelhouse/
24
.*.swp

CMakeLists.txt

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
cmake_minimum_required(VERSION 3.15)
22

33
project(createrepo-agent C)
44

@@ -35,6 +35,7 @@ target_link_libraries(createrepo-cache PUBLIC
3535
target_compile_definitions(createrepo-cache PRIVATE
3636
-DG_LOG_DOMAIN="CREATEREPO_CACHE")
3737
set_target_properties(createrepo-cache PROPERTIES
38+
POSITION_INDEPENDENT_CODE ON
3839
SOVERSION ${CRA_VERSION_MAJOR}
3940
VERSION ${CRA_VERSION})
4041

@@ -60,6 +61,8 @@ target_link_libraries(createrepo-agent-lib PUBLIC
6061
glib-2.0)
6162
target_compile_definitions(createrepo-agent-lib PRIVATE
6263
-DG_LOG_DOMAIN="CREATEREPO_AGENT")
64+
set_target_properties(createrepo-agent-lib PROPERTIES
65+
POSITION_INDEPENDENT_CODE ON)
6366

6467
# Executable
6568
add_executable(${PROJECT_NAME}
@@ -75,6 +78,73 @@ install(TARGETS ${PROJECT_NAME}
7578
RUNTIME DESTINATION bin
7679
COMPONENT bin)
7780

81+
# Python bindings
82+
cmake_policy(SET CMP0094 NEW)
83+
set(Python_FIND_UNVERSIONED_NAMES FIRST
84+
CACHE STRING "Defines how the generic names will be searched for Python")
85+
if(CMAKE_VERSION VERSION_LESS "3.18")
86+
set(Python_COMPONENTS Interpreter Development)
87+
else()
88+
set(Python_COMPONENTS Interpreter Development.Module)
89+
endif()
90+
find_package(Python 3 QUIET COMPONENTS ${Python_COMPONENTS})
91+
option(WITH_PYTHON "Build Python bindings" ${Python_FOUND})
92+
if(WITH_PYTHON)
93+
# Find Python again, this time REQUIRED
94+
find_package(Python 3 REQUIRED COMPONENTS ${Python_COMPONENTS})
95+
96+
python_add_library(createrepo_agent MODULE
97+
src/python/client.c
98+
src/python/init.c
99+
src/python/server.c)
100+
target_link_libraries(createrepo_agent PRIVATE
101+
createrepo-agent-lib)
102+
103+
if(SKBUILD)
104+
set(PYTHON_INSTALL_DIR ${SKBUILD_PLATLIB_DIR})
105+
else()
106+
# Determine package installation location
107+
string(JOIN "; " PYTHON_INSTALL_DIR_CMD
108+
"from os.path import sep"
109+
"from sys import stdout"
110+
"from sysconfig import get_path"
111+
"stdout.write(get_path('platlib', vars={'base': '', 'platbase': ''}).lstrip(sep))"
112+
)
113+
execute_process(COMMAND ${Python_EXECUTABLE} -c "${PYTHON_INSTALL_DIR_CMD}"
114+
OUTPUT_VARIABLE PYTHON_INSTALL_DIR)
115+
116+
set(DISTINFO_NAME "createrepo_agent-${CRA_VERSION}.dist-info")
117+
set(DISTINFO_DIR "${CMAKE_CURRENT_BINARY_DIR}/${DISTINFO_NAME}")
118+
file(GENERATE
119+
OUTPUT "${DISTINFO_DIR}/INSTALLER"
120+
CONTENT "cmake\n")
121+
file(GENERATE
122+
OUTPUT "${DISTINFO_DIR}/METADATA"
123+
CONTENT "Metadata-Version: 1.1\nName: createrepo-agent\nVersion: ${CRA_VERSION}\n")
124+
string(JOIN "\n" RECORD_CONTENT
125+
"$<TARGET_FILE_NAME:createrepo_agent>,,"
126+
"${DISTINFO_NAME}/INSTALLER,,"
127+
"${DISTINFO_NAME}/METADATA,,"
128+
"${DISTINFO_NAME}/RECORD,,"
129+
"${DISTINFO_NAME}/top_level.txt,,"
130+
)
131+
file(GENERATE
132+
OUTPUT "${DISTINFO_DIR}/RECORD"
133+
CONTENT "${RECORD_CONTENT}\n")
134+
file(GENERATE
135+
OUTPUT "${DISTINFO_DIR}/top_level.txt"
136+
CONTENT "createrepo_agent\n")
137+
install(DIRECTORY ${DISTINFO_DIR}
138+
DESTINATION ${PYTHON_INSTALL_DIR}
139+
COMPONENT python)
140+
endif()
141+
142+
install(TARGETS createrepo_agent
143+
RUNTIME DESTINATION ${PYTHON_INSTALL_DIR}
144+
LIBRARY DESTINATION ${PYTHON_INSTALL_DIR}
145+
COMPONENT python)
146+
endif()
147+
78148
add_subdirectory(doc)
79149

80150
set(MEMORYCHECK_SUPPRESSIONS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/test/valgrind.supp"

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"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "createrepo-agent"
7+
dynamic = ["version"]
8+
9+
[project.optional-dependencies]
10+
test = [
11+
"pytest",
12+
]
13+
14+
[tool.scikit-build]
15+
install.components = ["python"]
16+
sdist.exclude = [
17+
".editorconfig",
18+
".github",
19+
".gitignore",
20+
"CONTRIBUTING.md",
21+
]
22+
wheel.packages = []
23+
24+
[tool.scikit-build.cmake.define]
25+
BUILD_TESTING = false
26+
WITH_PYTHON = true
27+
28+
[tool.scikit-build.metadata.version]
29+
provider = "scikit_build_core.metadata.regex"
30+
input = "CMakeLists.txt"
31+
regex = '''
32+
set\(CRA_VERSION_MAJOR\s+(?P<major>\d+)\)
33+
set\(CRA_VERSION_MINOR\s+(?P<minor>\d+)\)
34+
set\(CRA_VERSION_PATCH\s+(?P<patch>\d+)\)
35+
'''
36+
result = "{major}.{minor}.{patch}"
37+
38+
[tool.cibuildwheel]
39+
skip = "*-musllinux_*"
40+
test-extras = ["test"]
41+
test-command = [
42+
"python -m pytest {project}/test",
43+
]
44+
45+
[tool.cibuildwheel.linux]
46+
before-all = "dnf install -y createrepo_c-devel glib2-devel gpgme-devel libassuan-devel libgpg-error-devel"

0 commit comments

Comments
 (0)