From d720537eecd8e409f2a518d72b376896f0a8a63f Mon Sep 17 00:00:00 2001 From: jurra Date: Tue, 1 Aug 2023 16:47:41 +0200 Subject: [PATCH 1/3] setup project as it is in pybind11 examples --- .github/workflows/pip.yml | 72 ++++++++++++++++++++++++++++++ .github/workflows/python-tests.yml | 17 ++++--- pyproject.toml | 24 ++++++++-- 3 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/pip.yml diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml new file mode 100644 index 0000000..5dfb445 --- /dev/null +++ b/.github/workflows/pip.yml @@ -0,0 +1,72 @@ +name: Pip + +on: + workflow_dispatch: + pull_request: + push: + branches: + - '*' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + strategy: + fail-fast: false + matrix: + platform: [windows-latest, macos-latest, ubuntu-latest] + python-version: ["3.7", "3.11"] + + runs-on: ${{ matrix.platform }} + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Add requirements + run: python -m pip install --upgrade wheel setuptools + + - name: Build and install + run: pip install --verbose . + + - name: Test + run: | + pip install pytest + pytest + + build-mingw64: + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + steps: + - uses: msys2/setup-msys2@v2 + with: + update: true + install: >- + mingw-w64-x86_64-gcc + mingw-w64-x86_64-python-pip + mingw-w64-x86_64-python-wheel + + - uses: actions/checkout@v3 + + - name: Install pybind11 + # This is required because --no-build-isolation disable dependences + # installation + run: pip install pybind11 + + - name: Build and install + # --no-build-isolation is required because the vanilla setuptool does not + # support Mingw64.See patches here: + # https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-python-setuptools + # Without those patches build_ext fails with: + # error: --plat-name must be one of ('win32', 'win-amd64', 'win-arm32', 'win-arm64') + run: pip install --no-build-isolation . + + - name: Test + run: python tests/test.py diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 43fa772..91bf8fe 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -43,24 +43,23 @@ jobs: with: python-version: 3.8 - # - name: Install dependencies - # run: | - # pip install . - # pip install pytest + - name: Install dependencies + run: | + pip install . + pip install pytest - name: Install package run: | python -m pip install --upgrade pip python -m pip install . - # - name: Add Python to PATH - # run: | - # echo "::add-path::C:\path\to\python" - # echo "::add-path::C:\path\to\python\Scripts" + - name: Add Python to PATH + run: | + echo "::add-path::C:\path\to\python" + echo "::add-path::C:\path\to\python\Scripts" - name: Run tests run: pytest - test_macos: name: Run Tests on macOS runs-on: macos-latest # Use GitHub-hosted runner for macOS diff --git a/pyproject.toml b/pyproject.toml index 59edcf0..a8518ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,28 @@ [build-system] requires = [ "setuptools>=42", - "wheel", "pybind11>=2.10.0", "gitpython>=2.1.0", ] build-backend = "setuptools.build_meta" +[tool.cibuildwheel] +test-command = "python {project}/tests/test.py" +test-skip = "*universal2:arm64" + +[tool.ruff] +extend-select = [ + "B", # flake8-bugbear + "I", # isort + "PGH", # pygrep-hooks + "RUF", # Ruff-specific + "UP", # pyupgrade +] +extend-ignore = [ + "E501", # Line too long +] +target-version = "py37" + [project] name = "pymurtree" version = "0.0.1" @@ -15,9 +31,9 @@ dependencies =[ "numpy>=1.18.0", ] -[project.dynamic] -description = 'Python wrapper for the MurTree project' -authors = 'Jose Urra and Yasel Quintero' +# [project.dynamic] +# description = 'Python wrapper for the MurTree project' +# authors = 'Jose Urra and Yasel Quintero' classifiers = [ "Programming Language :: Python :: 3", From 93bd82dcd29337dd7bfe84401a4f8972aecffe30 Mon Sep 17 00:00:00 2001 From: jurra Date: Mon, 18 Sep 2023 14:58:34 +0200 Subject: [PATCH 2/3] added wheels to the workflow for package distribution --- .github/workflows/pip.yml | 2 + .github/workflows/python-tests.yml | 91 ------------------------------ .github/workflows/wheels.yml | 83 +++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 91 deletions(-) delete mode 100644 .github/workflows/python-tests.yml create mode 100644 .github/workflows/wheels.yml diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index 5dfb445..55517fb 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -1,3 +1,5 @@ +# This provided workflow file is focused on testing a Python project using pip, the package installer for Python. +# There's also a specialized job for building and testing the package in a Mingw64 environment on Windows. name: Pip on: diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml deleted file mode 100644 index c172e8a..0000000 --- a/.github/workflows/python-tests.yml +++ /dev/null @@ -1,91 +0,0 @@ -name: Run Tests - -on: - push: - branches: ['*'] - pull_request: - branches: ['develop', 'main'] - - workflow_dispatch: - - -jobs: - test_ubuntu: - name: Run Tests for Ubuntu - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up GCC - run: sudo apt-get update && sudo apt-get install -y g++-10 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - pip install . - pip install pytest - - - name: Run tests - run: pytest - test_windows: - name: Run Tests on Windows - runs-on: windows-latest # Use GitHub-hosted runner for Windows - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - pip install . - pip install pytest - - - name: Install package - run: | - python -m pip install --upgrade pip - python -m pip install . - - - name: Add Python to PATH - run: | - echo "::add-path::C:\path\to\python" - echo "::add-path::C:\path\to\python\Scripts" - - - name: Run tests - run: pytest - test_macos: - name: Run Tests on macOS - runs-on: macos-latest # Use GitHub-hosted runner for macOS - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - pip install . - pip install pytest - - - name: Install GCC for C++14 on macOS - if: runner.os == 'macOS' - run: | - brew update - brew install gcc@10 - - - name: Run tests - run: pytest diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml new file mode 100644 index 0000000..fbe9aea --- /dev/null +++ b/.github/workflows/wheels.yml @@ -0,0 +1,83 @@ +# This workflow, labeled "Wheels", is focused on building and distributing Python packages. +# Specifically, it builds source distributions (sdist) and binary wheel distributions, +# and uploads them to the Python Package Index (PyPI) when a new release is published on GitHub. +name: Wheels + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + release: + types: + - published + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build_sdist: + name: Build SDist + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Build SDist0 + run: pipx run build --sdist + + - name: Check metadata + run: pipx run twine check dist/* + + - uses: actions/upload-artifact@v3 + with: + path: dist/*.tar.gz + + + build_wheels: + name: Wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + + steps: + - uses: actions/checkout@v3 + + - uses: pypa/cibuildwheel@v2.14 + env: + CIBW_ARCHS_MACOS: auto universal2 + CIBW_PRERELEASE_PYTHONS: true + + - name: Verify clean directory + run: git diff --exit-code + shell: bash + + - name: Upload wheels + uses: actions/upload-artifact@v3 + with: + path: wheelhouse/*.whl + + + upload_all: + name: Upload if release + needs: [build_wheels, build_sdist] + runs-on: ubuntu-latest + if: github.event_name == 'release' && github.event.action == 'published' + + steps: + - uses: actions/setup-python@v4 + with: + python-version: "3.x" + + - uses: actions/download-artifact@v3 + with: + name: artifact + path: dist + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.pypi_password }} \ No newline at end of file From b1656bfb1f338927969a5af2ec398809476a73a6 Mon Sep 17 00:00:00 2001 From: jurra Date: Mon, 18 Sep 2023 14:58:34 +0200 Subject: [PATCH 3/3] added wheels to the workflow for package distribution --- .github/workflows/pip.yml | 2 + .github/workflows/python-tests.yml | 91 ------------------------------ .github/workflows/wheels.yml | 82 +++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 91 deletions(-) delete mode 100644 .github/workflows/python-tests.yml create mode 100644 .github/workflows/wheels.yml diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index 5dfb445..55517fb 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -1,3 +1,5 @@ +# This provided workflow file is focused on testing a Python project using pip, the package installer for Python. +# There's also a specialized job for building and testing the package in a Mingw64 environment on Windows. name: Pip on: diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml deleted file mode 100644 index c172e8a..0000000 --- a/.github/workflows/python-tests.yml +++ /dev/null @@ -1,91 +0,0 @@ -name: Run Tests - -on: - push: - branches: ['*'] - pull_request: - branches: ['develop', 'main'] - - workflow_dispatch: - - -jobs: - test_ubuntu: - name: Run Tests for Ubuntu - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up GCC - run: sudo apt-get update && sudo apt-get install -y g++-10 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - pip install . - pip install pytest - - - name: Run tests - run: pytest - test_windows: - name: Run Tests on Windows - runs-on: windows-latest # Use GitHub-hosted runner for Windows - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - pip install . - pip install pytest - - - name: Install package - run: | - python -m pip install --upgrade pip - python -m pip install . - - - name: Add Python to PATH - run: | - echo "::add-path::C:\path\to\python" - echo "::add-path::C:\path\to\python\Scripts" - - - name: Run tests - run: pytest - test_macos: - name: Run Tests on macOS - runs-on: macos-latest # Use GitHub-hosted runner for macOS - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - pip install . - pip install pytest - - - name: Install GCC for C++14 on macOS - if: runner.os == 'macOS' - run: | - brew update - brew install gcc@10 - - - name: Run tests - run: pytest diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml new file mode 100644 index 0000000..f540840 --- /dev/null +++ b/.github/workflows/wheels.yml @@ -0,0 +1,82 @@ +# This workflow, labeled "Wheels", is focused on building and distributing Python packages. +# Specifically, it builds source distributions (sdist) and binary wheel distributions, +# and uploads them to the Python Package Index (PyPI) when a new release is published on GitHub. +name: Wheels + +on: + workflow_dispatch: + pull_request: + push: + branches: [ '*' ] + release: + types: + - published + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build_sdist: + name: Build SDist + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Build SDist0 + run: pipx run build --sdist + + - name: Check metadata + run: pipx run twine check dist/* + + - uses: actions/upload-artifact@v3 + with: + path: dist/*.tar.gz + + + build_wheels: + name: Wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + + steps: + - uses: actions/checkout@v3 + + - uses: pypa/cibuildwheel@v2.14 + env: + CIBW_ARCHS_MACOS: auto universal2 + CIBW_PRERELEASE_PYTHONS: true + + - name: Verify clean directory + run: git diff --exit-code + shell: bash + + - name: Upload wheels + uses: actions/upload-artifact@v3 + with: + path: wheelhouse/*.whl + + + upload_all: + name: Upload if release + needs: [build_wheels, build_sdist] + runs-on: ubuntu-latest + if: github.event_name == 'release' && github.event.action == 'published' + + steps: + - uses: actions/setup-python@v4 + with: + python-version: "3.x" + + - uses: actions/download-artifact@v3 + with: + name: artifact + path: dist + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.pypi_password }} \ No newline at end of file