From b812f6f7f2c6c4a08e28888192cb0f5920f5245d Mon Sep 17 00:00:00 2001 From: youben11 Date: Tue, 14 Dec 2021 10:32:01 +0100 Subject: [PATCH] feat(python): version python package from git tag automatic detection of version from git tag and update of the python version file --- .github/workflows/release.yml | 4 +++- compiler/Makefile | 12 ++++++++---- compiler/lib/Bindings/Python/CMakeLists.txt | 1 + compiler/lib/Bindings/Python/zamalang/version.py | 1 + compiler/setup.py | 10 +++++++++- 5 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 compiler/lib/Bindings/Python/zamalang/version.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cc3717be7..7d00dd44b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -113,6 +113,9 @@ jobs: cd ${{ github.workspace }}/concrete/concrete-ffi RUSTFLAGS="-C target-cpu=native" cargo build --release + - name: Update Python Version + run: cd compiler && make update_python_version + - name: Build id: build-wheel-macos run: | @@ -156,4 +159,3 @@ jobs: asset_path: ${{ github.workspace }}/compiler/tarballs/${{ steps.build-mac-tarball.outputs.ASSET_NAME }} asset_name: ${{ steps.build-mac-tarball.outputs.ASSET_NAME }} asset_content_type: application/tar+gzip -# TODO: version python diff --git a/compiler/Makefile b/compiler/Makefile index 11ac83d0a..ea23633e0 100644 --- a/compiler/Makefile +++ b/compiler/Makefile @@ -111,19 +111,22 @@ define build_image_and_copy_wheels docker container run --rm -v ${PWD}/../wheels:/wheels_volume concretefhe-compiler-manylinux:$(1) cp -r /wheels/. /wheels_volume/. endef -package_py38: +package_py38: update_python_version $(call build_image_and_copy_wheels,cp38-cp38) -package_py39: +package_py39: update_python_version $(call build_image_and_copy_wheels,cp39-cp39) -package_py310: +package_py310: update_python_version $(call build_image_and_copy_wheels,cp310-cp310) release_tarballs: docker image build -t concretefhe-compiler-manylinux:linux_x86_64_tarball -f ../builders/Dockerfile.release_tarball_linux_x86_64 .. docker container run --rm -v ${PWD}/../tarballs:/tarballs_volume concretefhe-compiler-manylinux:linux_x86_64_tarball cp -r /tarballs/. /tarballs_volume/. +update_python_version: + echo "__version__ = \"`git describe --tags --abbrev=0 | grep -e '[0-9].*' -o`\"" > lib/Bindings/Python/zamalang/version.py + .PHONY: build-initialized \ build-end-to-end-jit \ zamacompiler \ @@ -142,4 +145,5 @@ release_tarballs: package_py38 \ package_py39 \ package_py310 \ - release_tarballs + release_tarballs \ + update_python_version diff --git a/compiler/lib/Bindings/Python/CMakeLists.txt b/compiler/lib/Bindings/Python/CMakeLists.txt index affe8b286..0ed8a40fc 100644 --- a/compiler/lib/Bindings/Python/CMakeLists.txt +++ b/compiler/lib/Bindings/Python/CMakeLists.txt @@ -28,6 +28,7 @@ declare_mlir_python_sources(ZamalangBindingsPythonSources SOURCES zamalang/__init__.py zamalang/compiler.py + zamalang/version.py zamalang/dialects/__init__.py zamalang/dialects/_ods_common.py) diff --git a/compiler/lib/Bindings/Python/zamalang/version.py b/compiler/lib/Bindings/Python/zamalang/version.py new file mode 100644 index 000000000..b175e4c8c --- /dev/null +++ b/compiler/lib/Bindings/Python/zamalang/version.py @@ -0,0 +1 @@ +__version__ = "0.1.0-rc1" diff --git a/compiler/setup.py b/compiler/setup.py index 7c6c4d38b..edcee428c 100644 --- a/compiler/setup.py +++ b/compiler/setup.py @@ -1,6 +1,7 @@ import os import subprocess import setuptools +import re from setuptools import Extension from setuptools.command.build_ext import build_ext @@ -10,6 +11,13 @@ def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() +def find_version(): + return re.match( + r"__version__ = \"(?P.+)\"", + read("lib/Bindings/Python/zamalang/version.py"), + ).group("version") + + class MakeExtension(Extension): def __init__(self, name, sourcedir=""): Extension.__init__(self, name, sources=[]) @@ -39,7 +47,7 @@ class MakeBuild(build_ext): setuptools.setup( name="concretefhe-compiler", - version="0.1.0", + version=find_version(), author="Zama Team", author_email="hello@zama.ai", description="Concrete Compiler",