diff --git a/.github/workflows/build-golang-macos.yaml b/.github/workflows/build-golang-macos.yaml index a883704..1d845c8 100644 --- a/.github/workflows/build-golang-macos.yaml +++ b/.github/workflows/build-golang-macos.yaml @@ -43,7 +43,7 @@ jobs: # FIXME: Add more caching - name: Configure gopy / dependencies, and build wheel run: | - ./ci-build.sh + ./build-scripts/ci-build.sh # - uses: ./.github/workflows/platform-integration-test.yaml # with: diff --git a/.github/workflows/build-golang-ubuntu.yaml b/.github/workflows/build-golang-ubuntu.yaml index fc94e03..6a95be4 100644 --- a/.github/workflows/build-golang-ubuntu.yaml +++ b/.github/workflows/build-golang-ubuntu.yaml @@ -39,7 +39,7 @@ jobs: # FIXME: Add more caching - name: Configure gopy / dependencies, and build wheel run: | - ./ci-build.sh + ./build-scripts/ci-build.sh - uses: actions/cache/restore@v4 with: diff --git a/ci-build.sh b/build-scripts/ci-build.sh similarity index 81% rename from ci-build.sh rename to build-scripts/ci-build.sh index 4dadc46..474037a 100755 --- a/ci-build.sh +++ b/build-scripts/ci-build.sh @@ -2,6 +2,11 @@ set -eou pipefail +# Based on: https://stackoverflow.com/a/246128 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +BUILD_ROOT="${SCRIPT_DIR}/.." +cd "${BUILD_ROOT}" || { echo "Unable to change to build root directory" ; exit 1; } + printf """ ✨✨✨ Configure gopy / dependencies, and build wheel ✨✨✨ diff --git a/make_and_validate_script.sh b/build-scripts/make_and_validate_script.sh similarity index 85% rename from make_and_validate_script.sh rename to build-scripts/make_and_validate_script.sh index 2010d0e..b051c52 100755 --- a/make_and_validate_script.sh +++ b/build-scripts/make_and_validate_script.sh @@ -6,6 +6,11 @@ set -eou pipefail # Ensure we aren't in a virtual environment deactivate || { echo "Not currently in a virtual environment" ; } +# Based on: https://stackoverflow.com/a/246128 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +BUILD_ROOT="${SCRIPT_DIR}/.." +cd "${BUILD_ROOT}" || { echo "Unable to change to build root directory" ; exit 1; } + SKIP_TESTS="${1:-NO}" # Cleanup diff --git a/build-scripts/uv_make_and_validate_script.sh b/build-scripts/uv_make_and_validate_script.sh new file mode 100755 index 0000000..657517e --- /dev/null +++ b/build-scripts/uv_make_and_validate_script.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +set -x +set -eou pipefail + +loud_print(){ + printf """ + + ======================================== + $1 + + + ======================================== + + """ +} + +# Based on: https://stackoverflow.com/a/246128 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +BUILD_ROOT="${SCRIPT_DIR}/.." +cd "${BUILD_ROOT}" || { echo "Unable to change to build root directory" ; exit 1; } + +SKIP_TESTS="${1:-NO}" + +# Cleanup +rm -rf .venv-wheel/ +rm -rf .venv/ +rm -rf dist/ + +# PY_TYPE="--python-preference=only-system" +PY_TYPE="--python-preference=only-managed" + +loud_print "Creating virtual environment" +# Install python deps +uv venv .venv --python 3.12 "$PY_TYPE" +source "${BUILD_ROOT}/.venv/bin/activate" + +loud_print "Installing dependencies" +uv pip install wheel pybindgen + +if ! [ -d ".venv" ]; then + echo "Unable to locate virtual environment directory" + exit 1 +fi + +loud_print "Activating virtual environment" +source "${BUILD_ROOT}/.venv/bin/activate" + +loud_print "Installing goimports" +go install golang.org/x/tools/cmd/goimports@latest +loud_print "Installing gopy" +go install github.com/go-python/gopy@v0.4.10 + +# For every step below, 'which python' should return '.venv/bin/python' +loud_print "Executing gopy" +PATH="$PATH:$HOME/go/bin" gopy build --output=otdf_python -vm=python3 . + +loud_print "Installing setuptools" +uv pip install --upgrade setuptools + +# Build the 'dist/' folder (wheel) +loud_print "Running 'setup.py bdist_wheel'" +python setup.py bdist_wheel + +deactivate + +# Prove that the wheel can be installed +loud_print "Installing wheel" + +uv venv .venv-wheel --python 3.12 "$PY_TYPE" +source "${BUILD_ROOT}/.venv-wheel/bin/activate" +pip install pybindgen +pip install dist/otdf_python-0.1.14-py3-none-any.whl + +if [[ "$SKIP_TESTS" == "-s" || "$SKIP_TESTS" == "--skip-tests" ]]; then + echo "Build is complete, skipping tests." +else + # Validate functionality + echo "Build is complete, running tests." + python validate_otdf_python.py +fi diff --git a/poetry.lock b/poetry.lock index 1e27ba9..c51f402 100644 --- a/poetry.lock +++ b/poetry.lock @@ -81,13 +81,13 @@ dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments [[package]] name = "wheel" -version = "0.45.0" +version = "0.45.1" description = "A built-package format for Python" optional = false python-versions = ">=3.8" files = [ - {file = "wheel-0.45.0-py3-none-any.whl", hash = "sha256:52f0baa5e6522155090a09c6bd95718cc46956d1b51d537ea5454249edb671c7"}, - {file = "wheel-0.45.0.tar.gz", hash = "sha256:a57353941a3183b3d5365346b567a260a0602a0f8a635926a7dede41b94c674a"}, + {file = "wheel-0.45.1-py3-none-any.whl", hash = "sha256:708e7481cc80179af0e556bbf0cc00b8444c7321e2700b8d8580231d13017248"}, + {file = "wheel-0.45.1.tar.gz", hash = "sha256:661e1abd9198507b1409a20c02106d9670b2576e916d58f520316666abca6729"}, ] [package.extras] @@ -96,4 +96,4 @@ test = ["pytest (>=6.0.0)", "setuptools (>=65)"] [metadata] lock-version = "2.0" python-versions = ">=3.11,<3.14" -content-hash = "f533e1b4b9591bdee5510c86e4da50bf86f664d9240fb61ce6e0d02325be666c" +content-hash = "2ce122d5f23a9bd0d885da6a0d4e5ecf37f5f071f327b2c26f14ac50845ca54e" diff --git a/pyproject.toml b/pyproject.toml index 2f86ba7..cc0395c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,23 @@ -[tool.poetry] +[project] name = "otdf-python" # Should match 'setup.py' version number (used for gopy/pybindgen) version = "0.1.14" description = "Unofficial OpenTDF SDK for Python." -authors = ["b-long "] +authors = [ + {name="b-long", email="b-long@users.noreply.github.com"} +] readme = "README.md" +requires-python = ">=3.11" + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[dependencies] +wheel = "^0.45.0" +pybindgen = "^0.22.1" + +[tool.poetry] package-mode = false [tool.poetry.dependencies] @@ -12,10 +25,5 @@ python = ">=3.11,<3.14" wheel = "^0.45.0" pybindgen = "^0.22.1" - [tool.poetry.group.dev.dependencies] -pytest = "^8.0.0" - -[build-system] -requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api" +pytest = ">=8.1" diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..453ce33 --- /dev/null +++ b/uv.lock @@ -0,0 +1,7 @@ +version = 1 +requires-python = ">=3.11" + +[[package]] +name = "otdf-python" +version = "0.1.14" +source = { editable = "." }