Skip to content

Commit

Permalink
Add source distribution for Python package (#415)
Browse files Browse the repository at this point in the history
Also improves setup.py and moves it to the repo's root directory.
  • Loading branch information
step21 authored Apr 16, 2024
1 parent 1ef67c1 commit 67e5904
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 35 deletions.
27 changes: 26 additions & 1 deletion .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,32 @@ jobs:
name: wheels
path: wheelhouse/*

# Build the source distribution under Linux
build-sdist:
name: Source distribution
runs-on: ubuntu-latest

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

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Build source distribution
run: python setup.py sdist

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

publish:
needs: [build-wheels]
needs: [build-wheels, build-sdist]
runs-on: ubuntu-latest
steps:
- name: Download artifacts
Expand All @@ -93,3 +117,4 @@ jobs:
with:
password: ${{ secrets.PYPI_PASSWORD }}
packages-dir: wheelhouse

34 changes: 34 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
branches:
- main

defaults:
run:
shell: bash

jobs:
tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -37,3 +41,33 @@ jobs:
run: |
cd bindings/python
make test
test-sdist:
runs-on: ${{matrix.os}}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyYAML
- name: Build sdist
run: python setup.py sdist
- name: Set up Visual Studio shell
if: runner.os == 'Windows'
uses: egor-tensin/vs-shell@v2
- name: Install via sdist
working-directory: dist
run: pip install ckzg-*.tar.gz
- name: Run tests
run: make -C bindings/python test
10 changes: 10 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This is a manifest for the Python bindings
include bindings/python/ckzg.c
include bindings/python/README.md
recursive-include blst *
recursive-include lib *
recursive-include inc *
recursive-include src *
include setup.py
include LICENSE
include README.md
7 changes: 2 additions & 5 deletions bindings/python/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
.PHONY: all
all: install test

../../src/c_kzg_4844.o:
make -C../../src c_kzg_4844.o

.PHONY: install
install: setup.py ckzg.c ../../src/c_kzg_4844.o
python3 setup.py install
install: ../../setup.py ckzg.c
python3 ../../setup.py install --force

.PHONY: test
test: tests.py
Expand Down
29 changes: 0 additions & 29 deletions bindings/python/setup.py

This file was deleted.

53 changes: 53 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from pathlib import Path
from platform import system
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from subprocess import check_call

this_dir = Path(__file__).parent
long_description = (this_dir / "bindings/python/README.md").read_text()


def f(path_str):
return str(this_dir / path_str)


class CustomBuild(build_ext):
def run(self):
if system() == "Windows":
try:
check_call([f("blst\\build.bat")])
except Exception:
pass
check_call(["make", "-C", f("src"), "c_kzg_4844.o"])
super().run()


def main():
setup(
name="ckzg",
version="1.0.1",
author="Ethereum Foundation",
author_email="[email protected]",
url="https://github.com/ethereum/c-kzg-4844",
description="Python bindings for C-KZG-4844",
long_description=long_description,
long_description_content_type="text/markdown",
license="Apache-2.0",
ext_modules=[
Extension(
"ckzg",
sources=[f("bindings/python/ckzg.c"), f("src/c_kzg_4844.c")],
include_dirs=[f("inc"), f("src")],
library_dirs=[f("lib")],
libraries=["blst"]
)
],
cmdclass={
"build_ext": CustomBuild,
}
)


if __name__ == "__main__":
main()

0 comments on commit 67e5904

Please sign in to comment.