Add source distribution for Python package (#415)

Also improves setup.py and moves it to the repo's root directory.
This commit is contained in:
Florian Idelberger 2024-04-17 01:14:38 +02:00 committed by GitHub
parent 1ef67c17bf
commit 67e5904a04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 125 additions and 35 deletions

View File

@ -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
@ -93,3 +117,4 @@ jobs:
with:
password: ${{ secrets.PYPI_PASSWORD }}
packages-dir: wheelhouse

View File

@ -7,6 +7,10 @@ on:
branches:
- main
defaults:
run:
shell: bash
jobs:
tests:
runs-on: ubuntu-latest
@ -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
MANIFEST.in Normal file
View File

@ -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

View File

@ -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

View File

@ -1,29 +0,0 @@
from setuptools import setup, Extension
from pathlib import Path
this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()
def main():
setup(
name="ckzg",
version="1.0.0",
author="Ethereum Foundation",
author_email="security@ethereum.org",
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=["ckzg.c", "../../src/c_kzg_4844.c"],
include_dirs=["../../inc", "../../src"],
library_dirs=["../../lib"],
libraries=["blst"])])
if __name__ == "__main__":
main()

53
setup.py Normal file
View File

@ -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="security@ethereum.org",
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()