Skip to content

Commit 649e100

Browse files
committed
Enable 'uv' build & managed Python
1 parent 8ee0217 commit 649e100

8 files changed

Lines changed: 116 additions & 35 deletions

File tree

.github/workflows/build-golang-macos.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
# FIXME: Add more caching
4444
- name: Configure gopy / dependencies, and build wheel
4545
run: |
46-
./ci-build.sh
46+
./build-scripts/ci-build.sh
4747
4848
# - uses: ./.github/workflows/platform-integration-test.yaml
4949
# with:

.github/workflows/build-golang-ubuntu.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
# FIXME: Add more caching
4040
- name: Configure gopy / dependencies, and build wheel
4141
run: |
42-
./ci-build.sh
42+
./build-scripts/ci-build.sh
4343
4444
- uses: actions/cache/restore@v4
4545
with:

ci-build.sh renamed to build-scripts/ci-build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
set -eou pipefail
44

5+
# Based on: https://stackoverflow.com/a/246128
6+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
7+
BUILD_ROOT="${SCRIPT_DIR}/.."
8+
cd "${BUILD_ROOT}" || { echo "Unable to change to build root directory" ; exit 1; }
9+
510
printf """
611
712
✨✨✨ Configure gopy / dependencies, and build wheel ✨✨✨
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ set -eou pipefail
66
# Ensure we aren't in a virtual environment
77
deactivate || { echo "Not currently in a virtual environment" ; }
88

9+
# Based on: https://stackoverflow.com/a/246128
10+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
11+
BUILD_ROOT="${SCRIPT_DIR}/.."
12+
cd "${BUILD_ROOT}" || { echo "Unable to change to build root directory" ; exit 1; }
13+
914
SKIP_TESTS="${1:-NO}"
1015

1116
# Cleanup
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
set -x
4+
set -eou pipefail
5+
6+
loud_print(){
7+
printf """
8+
9+
========================================
10+
$1
11+
12+
13+
========================================
14+
15+
"""
16+
}
17+
18+
# Based on: https://stackoverflow.com/a/246128
19+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
20+
BUILD_ROOT="${SCRIPT_DIR}/.."
21+
cd "${BUILD_ROOT}" || { echo "Unable to change to build root directory" ; exit 1; }
22+
23+
SKIP_TESTS="${1:-NO}"
24+
25+
# Cleanup
26+
rm -rf .venv-wheel/
27+
rm -rf .venv/
28+
rm -rf dist/
29+
30+
# PY_TYPE="--python-preference=only-system"
31+
PY_TYPE="--python-preference=only-managed"
32+
33+
loud_print "Creating virtual environment"
34+
# Install python deps
35+
uv venv .venv --python 3.12 "$PY_TYPE"
36+
source "${BUILD_ROOT}/.venv/bin/activate"
37+
38+
loud_print "Installing dependencies"
39+
uv pip install wheel pybindgen
40+
41+
if ! [ -d ".venv" ]; then
42+
echo "Unable to locate virtual environment directory"
43+
exit 1
44+
fi
45+
46+
loud_print "Activating virtual environment"
47+
source "${BUILD_ROOT}/.venv/bin/activate"
48+
49+
loud_print "Installing goimports"
50+
go install golang.org/x/tools/cmd/goimports@latest
51+
loud_print "Installing gopy"
52+
go install github.com/go-python/gopy@v0.4.10
53+
54+
# For every step below, 'which python' should return '.venv/bin/python'
55+
loud_print "Executing gopy"
56+
PATH="$PATH:$HOME/go/bin" gopy build --output=otdf_python -vm=python3 .
57+
58+
loud_print "Installing setuptools"
59+
uv pip install --upgrade setuptools
60+
61+
# Build the 'dist/' folder (wheel)
62+
loud_print "Running 'setup.py bdist_wheel'"
63+
python setup.py bdist_wheel
64+
65+
deactivate
66+
67+
# Prove that the wheel can be installed
68+
loud_print "Installing wheel"
69+
70+
uv venv .venv-wheel --python 3.12 "$PY_TYPE"
71+
source "${BUILD_ROOT}/.venv-wheel/bin/activate"
72+
pip install pybindgen
73+
pip install dist/otdf_python-0.1.14-py3-none-any.whl
74+
75+
if [[ "$SKIP_TESTS" == "-s" || "$SKIP_TESTS" == "--skip-tests" ]]; then
76+
echo "Build is complete, skipping tests."
77+
else
78+
# Validate functionality
79+
echo "Build is complete, running tests."
80+
python validate_otdf_python.py
81+
fi

poetry.lock

Lines changed: 1 addition & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1-
[tool.poetry]
1+
[project]
22
name = "otdf-python"
33
# Should match 'setup.py' version number (used for gopy/pybindgen)
44
version = "0.1.14"
55
description = "Unofficial OpenTDF SDK for Python."
6-
authors = ["b-long <b-long@users.noreply.github.com>"]
6+
authors = [
7+
{name="b-long", email="b-long@users.noreply.github.com"}
8+
]
79
readme = "README.md"
10+
requires-python = ">=3.11"
11+
12+
[tool.poetry]
813
package-mode = false
914

10-
[tool.poetry.dependencies]
11-
python = ">=3.11,<3.14"
15+
16+
[dependencies]
1217
wheel = "^0.45.0"
1318
pybindgen = "^0.22.1"
1419

1520

21+
[tool.poetry.dependencies]
22+
python = ">=3.11,<3.14"
23+
1624
[tool.poetry.group.dev.dependencies]
17-
pytest = "^8.0.0"
25+
pytest = ">=8.1"
1826

1927
[build-system]
20-
requires = ["poetry-core"]
21-
build-backend = "poetry.core.masonry.api"
28+
requires = ["hatchling"]
29+
build-backend = "hatchling.build"

uv.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)