From ef4f30978da3bc2347bacf3ef872c95344d7ba99 Mon Sep 17 00:00:00 2001 From: Gaetan Perrot Date: Tue, 13 Aug 2024 18:18:22 +0900 Subject: [PATCH] test pypi --- .../workflows/build-test-publish-python.yml | 92 +++++++++++++++++++ .github/workflows/build-test-python.yml | 41 --------- csp_moonlight/__init__.py | 1 + manifest.in | 2 + pyproject.toml | 3 + setup.py | 23 +++++ 6 files changed, 121 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/build-test-publish-python.yml delete mode 100644 .github/workflows/build-test-python.yml create mode 100644 csp_moonlight/__init__.py create mode 100644 manifest.in create mode 100644 pyproject.toml create mode 100644 setup.py diff --git a/.github/workflows/build-test-publish-python.yml b/.github/workflows/build-test-publish-python.yml new file mode 100644 index 000000000..2bf7e04b2 --- /dev/null +++ b/.github/workflows/build-test-publish-python.yml @@ -0,0 +1,92 @@ +name: Build and test python +on: [push, pull_request] +jobs: + build-test-python: + strategy: + fail-fast: false + matrix: + os: + - ubuntu-24.04 + arch: + - posix + buildsystem: + - cmake + runs-on: ${{ matrix.os }} + steps: + - name: Setup packages on Linux + run: | + sudo apt-get update + sudo apt-get install libzmq3-dev libsocketcan-dev + + - name: Setup build system packages on Linux + run: | + sudo apt-get install ninja-build cmake + + - name: Checkout + uses: actions/checkout@v4 + + - name: Build libcsp examples + run: python3 examples/buildall.py ${{ matrix.arch }} --build-system=${{ matrix.buildsystem }} + + - name: Build libcsp with python binding + run: | + cmake -GNinja -B buildBinding -DCSP_ENABLE_PYTHON3_BINDINGS=1 -DCSP_USE_RTABLE=1 -DCMAKE_POSITION_INDEPENDENT_CODE=ON && ninja -C buildBinding + + - name: Run ZMQ Python binding Test + run: | + build/examples/zmqproxy & + LD_LIBRARY_PATH=buildBinding PYTHONPATH=buildBinding python3 examples/python_bindings_example_server.py & + LD_LIBRARY_PATH=buildBinding PYTHONPATH=buildBinding python3 examples/python_bindings_example_client.py -z localhost -s 27 -a 2 + pkill zmqproxy + + - name: Prepare Python binding for packaging + run: | + ls + cp buildBinding/libcsp_py3*.so csp_moonlight/libcsp_py3-${{ matrix.os }}.so + ls -l csp_moonlight/ + + - name: Set up Python environment + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Create and activate virtual environment + run: | + python -m venv venv + source venv/bin/activate + python -m pip install --upgrade pip + python -m pip install setuptools wheel build + + - name: Build the Python package + run: | + source venv/bin/activate + ls -l csp_moonlight/ + python3 -m build + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} + repository-url: https://test.pypi.org/legacy/ + if: github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/') + + # Install the package from PyPI and run tests again + - name: Install package from PyPI + run: | + source venv/bin/activate + pip install -i https://test.pypi.org/simple/ csp-moonlight + # Verify the package installation + pip show csp-moonlight + # Verify that .py files are present + ls venv/lib/python*/site-packages/ + ls -l venv/lib/python*/site-packages/csp_moonlight-2.0.2.dist-info + # Test import in Python + python -c "import csp_moonlight; print('csp_moonlight imported successfully')" + python -c "import csp_moonlight; csp_moonlight.init(2,'model','1.2.3')" + # Run again tests to test the uploaded package + #- name: Run ZMQ Python binding test with PyPI package + # run: | + # build/examples/zmqproxy & + # python3 examples/python_bindings_example_server.py & + # python3 examples/python_bindings_example_client.py -z localhost -s 27 -a 2 + # pkill zmqproxy \ No newline at end of file diff --git a/.github/workflows/build-test-python.yml b/.github/workflows/build-test-python.yml deleted file mode 100644 index bf9e647dd..000000000 --- a/.github/workflows/build-test-python.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Build and test python -on: [push, pull_request] -jobs: - abi-check: - strategy: - fail-fast: false - matrix: - os: - - ubuntu-24.04 - arch: - - posix - buildsystem: - - cmake - runs-on: ${{ matrix.os }} - steps: - - name: Setup packages on Linux - run: | - sudo apt-get update - sudo apt-get install libzmq3-dev libsocketcan-dev - - - name: Setup build system packages on Linux - run: | - sudo apt-get install ninja-build cmake - - - name: Checkout - uses: actions/checkout@v4 - - - name: Build libcsp examples - run: python3 examples/buildall.py ${{ matrix.arch }} --build-system=${{ matrix.buildsystem }} - - - name: Build libcsp with python binding - run: | - cmake -GNinja -B buildBinding -DCSP_ENABLE_PYTHON3_BINDINGS=1 -DCSP_USE_RTABLE=1 -DCMAKE_POSITION_INDEPENDENT_CODE=ON && ninja -C buildBinding - ls -l - ls -l build/ - - name: Run ZMQ Python binding Test - run: | - build/examples/zmqproxy & - LD_LIBRARY_PATH=buildBinding PYTHONPATH=buildBinding python3 examples/python_bindings_example_server.py & - LD_LIBRARY_PATH=buildBinding PYTHONPATH=buildBinding python3 examples/python_bindings_example_client.py -z localhost -s 27 -a 2 - pkill zmqproxy \ No newline at end of file diff --git a/csp_moonlight/__init__.py b/csp_moonlight/__init__.py new file mode 100644 index 000000000..c870a7065 --- /dev/null +++ b/csp_moonlight/__init__.py @@ -0,0 +1 @@ +from csp_moonlight import * \ No newline at end of file diff --git a/manifest.in b/manifest.in new file mode 100644 index 000000000..04f196ac7 --- /dev/null +++ b/manifest.in @@ -0,0 +1,2 @@ +include README.md +include LICENSE diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..8fe2f47af --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..faa176b71 --- /dev/null +++ b/setup.py @@ -0,0 +1,23 @@ +from setuptools import setup, find_packages + +setup( + name='csp_moonlight', + version='2.0.3', + description='CSP Python bindings', + long_description=open('README.md').read(), + long_description_content_type='text/markdown', + license='MIT', + license_files=('LICENSE',), + author='moonlight83340', + author_email='gaetan.perrot@spacecubics.com', + url='https://github.com/moonlight83340/libcsp', + packages=find_packages(), # Automatically finds packages in libcsp_py3 + data_files=[('csp_moonlight', ['csp_moonlight/libcsp_py3-ubuntu-24.04.so'])], # Specifies the .so file + include_package_data=True, + classifiers=[ + 'Programming Language :: Python :: 3', + 'License :: OSI Approved :: MIT License', + 'Operating System :: POSIX :: Linux', + ], + python_requires='>=3.5', +)