From 67e5904a04b6fb559bea59a27895d175d2054df7 Mon Sep 17 00:00:00 2001 From: Florian Idelberger Date: Wed, 17 Apr 2024 01:14:38 +0200 Subject: [PATCH] Add source distribution for Python package (#415) Also improves setup.py and moves it to the repo's root directory. --- .github/workflows/python-release.yml | 27 +++++++++++++- .github/workflows/python-tests.yml | 34 ++++++++++++++++++ MANIFEST.in | 10 ++++++ bindings/python/Makefile | 7 ++-- bindings/python/setup.py | 29 --------------- setup.py | 53 ++++++++++++++++++++++++++++ 6 files changed, 125 insertions(+), 35 deletions(-) create mode 100644 MANIFEST.in delete mode 100644 bindings/python/setup.py create mode 100644 setup.py diff --git a/.github/workflows/python-release.yml b/.github/workflows/python-release.yml index 6ab204d..223d9a4 100644 --- a/.github/workflows/python-release.yml +++ b/.github/workflows/python-release.yml @@ -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 + diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 583d657..4cfc2ca 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -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 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..dde3b01 --- /dev/null +++ b/MANIFEST.in @@ -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 diff --git a/bindings/python/Makefile b/bindings/python/Makefile index c6bd222..2e5e385 100644 --- a/bindings/python/Makefile +++ b/bindings/python/Makefile @@ -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 diff --git a/bindings/python/setup.py b/bindings/python/setup.py deleted file mode 100644 index 332f459..0000000 --- a/bindings/python/setup.py +++ /dev/null @@ -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() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a45eac7 --- /dev/null +++ b/setup.py @@ -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()