Skip to content

Commit

Permalink
#16: bindings: Try pip build and PyPI publish from CI
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrepebay committed Oct 21, 2023
1 parent 7f5337c commit abef303
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 15 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Pip

on:
workflow_dispatch:
pull_request:
push:

jobs:
build:
name: Build with Pip
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform: [windows-latest, macos-latest, ubuntu-latest]
python-version: ["3.8", "3.9"]

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Set min macOS version
if: runner.os == 'macOS'
run: |
echo "MACOS_DEPLOYMENT_TARGET=10.14" >> $GITHUB_ENV
- name: Build and install
run:
# python -m pip install pytest
pip install --verbose .

# - name: Test
# run: python -m pytest
78 changes: 78 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Wheels

on:
workflow_dispatch:
pull_request:
push:

jobs:
build_sdist:
name: Build SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Build SDist
run: pipx run build --sdist

- name: Check metadata
run: pipx run twine check dist/*

- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz


build_wheels:
name: Wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: pypa/[email protected]
env:
# Cross-compile on macOS
CIBW_ARCHS_MACOS: x86_64 arm64

# Temporary: use pre-release Python 3.12 for stable ABI builds
CIBW_PRERELEASE_PYTHONS: True

- name: Verify clean directory
run: git diff --exit-code
shell: bash

- name: Upload wheels
uses: actions/upload-artifact@v3
with:
path: wheelhouse/*.whl


upload_all:
name: Upload to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/vt-tv
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing

steps:
- uses: actions/setup-python@v4

- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
9 changes: 0 additions & 9 deletions bindings/python/setup.py

This file was deleted.

10 changes: 5 additions & 5 deletions bindings/python/tv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace vt::tv::bindings::python {

void process_json(std::string& input) {
auto j = nlohmann::json::parse(input);
void tv_from_json(const std::string& input_json_str, const std::string& input_yaml_params_str) {
auto j = nlohmann::json::parse(input_json_str, const std::string& input_yaml_params_str);
fmt::print("JSON: {}\n", j.dump(2));
// Read the json file
// using json = nlohmann::json;
Expand Down Expand Up @@ -120,7 +120,7 @@ void process_json(std::string& input) {
// assert(to.is_number());

// // fmt::print(" From: {}, to: {}\n", from_id, to_id);

json_str
// // Object on this rank sent data
// if (objects.find(from_id) != objects.end()) {
// objects.at(from_id).addSentCommunications(to_id, bytes);
Expand Down Expand Up @@ -148,8 +148,8 @@ void process_json(std::string& input) {
namespace nb = nanobind;
using namespace nb::literals;

NB_MODULE(tv, m) {
m.def("process_json", &process_json);
NB_MODULE(vttv, m) {
m.def("tv_from_json", &tv_from_json);
}

} /* end namespace vt::tv::bindings::python */
2 changes: 1 addition & 1 deletion bindings/python/tv.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

namespace vt::tv::bindings::python {

void process_json(std::string&);
void tv_from_json(const std::string&, const std::string&);

} /* end namespace vt::tv::bindings::python */

Expand Down
1 change: 1 addition & 0 deletions bindings/python/vt-tv/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .vttv import tv_from_json
33 changes: 33 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[build-system]
requires = ["setuptools>=42", "wheel", "nanobind>=1.3.2"]
build-backend = "setuptools.build_meta"

[project]
name = "vt-tv"
version = "0.0.1"
description = "vt-tv test"
readme = "README.md"
requires-python = ">=3.8"
authors = [
{ name = "Jonathan Lifflander"},
{ name = "Pierre Pebay"}
]
classifiers = [
"License :: OSI Approved :: BSD License",
]

[project.urls]
Homepage = "https://github.com/DARMA-tasking/vt-tv"


[tool.cibuildwheel]
# Necessary to see build output from the actual compilation
build-verbosity = 1

# # Run pytest to ensure that the package was correctly built
# test-command = "pytest {project}/tests"
# test-requires = "pytest"

# Needed for full C++17 support
[tool.cibuildwheel.macos.environment]
MACOSX_DEPLOYMENT_TARGET = "10.14"

0 comments on commit abef303

Please sign in to comment.