From ab212acc4e8ff21df0e7446a882f6bf2243ca5c5 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Mon, 28 Jul 2025 10:37:04 -0400 Subject: [PATCH 1/3] wheel setup --- .../workflows/_build-pyobjcryst-package.yml | 147 ++++++++++++++++++ .../workflows/build-wheel-release-upload.yml | 2 - MANIFEST.in | 1 + requirements/pip.txt | 1 + setup.py | 44 ++++-- 5 files changed, 179 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/_build-pyobjcryst-package.yml diff --git a/.github/workflows/_build-pyobjcryst-package.yml b/.github/workflows/_build-pyobjcryst-package.yml new file mode 100644 index 0000000..0172f25 --- /dev/null +++ b/.github/workflows/_build-pyobjcryst-package.yml @@ -0,0 +1,147 @@ +name: Build wheel and sdist for a non-pure Python package + +on: + push: + +jobs: + build_sdist: + defaults: + run: + shell: bash -l {0} + + name: Build sdist + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v4 + + - name: Initialize miniconda + uses: conda-incubator/setup-miniconda@v3 + with: + activate-environment: sdist + channels: conda-forge + auto-update-conda: true + auto-activate-base: false + python-version: 3.13 + + - name: Conda config + run: >- + conda config --set always_yes yes + --set changeps1 no + + - name: Build sdist + run: | + pip install --upgrade build + python -m build --sdist + + - uses: actions/upload-artifact@v4 + with: + name: cibw-sdist + path: ./dist/*.tar.gz + + build-wheels: + needs: [build_sdist] + defaults: + run: + shell: bash -l {0} + + name: cibw-wheels-${{ matrix.python }}-${{ matrix.buildplat }} + runs-on: ${{ matrix.buildplat }} + strategy: + fail-fast: false + matrix: + buildplat: + - ubuntu-latest + - macos-13 + - macos-14 + - windows-latest + python: + - "3.11" + - "3.12" + - "3.13" + + steps: + - name: Check out + uses: actions/checkout@v4 + + - name: Initialize miniconda + uses: conda-incubator/setup-miniconda@v3 + with: + activate-environment: build + channels: conda-forge + auto-update-conda: true + auto-activate-base: false + python-version: ${{ matrix.python }} + + - name: Conda config + run: >- + conda config --set always_yes yes + --set changeps1 no + + - name: Install requirements + run: | + conda install --file requirements/conda.txt + conda install --file requirements/pip.txt + pip install --upgrade build + python -m pip wheel --no-deps --wheel-dir ./dist . + + - name: Upload wheels to GitHub + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.python }}-${{ matrix.buildplat }}.whl + path: ./dist/*.whl + + test-wheels: + needs: [build-wheels] + defaults: + run: + shell: bash -l {0} + + name: test-wheels-${{ matrix.python }}-${{ matrix.buildplat }} + runs-on: ${{ matrix.buildplat }} + strategy: + fail-fast: false + matrix: + buildplat: + - ubuntu-latest + - macos-13 + - macos-14 + - windows-latest + python: + - "3.11" + - "3.12" + - "3.13" + + steps: + - name: Check out + uses: actions/checkout@v4 + + - name: Download wheels + uses: actions/download-artifact@v4 + with: + name: ${{ matrix.python }}-${{ matrix.buildplat }}.whl + path: ./dist + + - name: Initialize miniconda + uses: conda-incubator/setup-miniconda@v3 + with: + activate-environment: test + channels: conda-forge + auto-update-conda: true + auto-activate-base: false + python-version: ${{ matrix.python }} + + - name: Conda config + run: >- + conda config --set always_yes yes + --set changeps1 no + + - name: Install requirements + run: | + conda install --file requirements/conda.txt + conda install --file requirements/tests.txt + + - name: Install wheel and test + run: | + pip install ./dist/*.whl + pytest diff --git a/.github/workflows/build-wheel-release-upload.yml b/.github/workflows/build-wheel-release-upload.yml index 7a69e2f..a290ab1 100644 --- a/.github/workflows/build-wheel-release-upload.yml +++ b/.github/workflows/build-wheel-release-upload.yml @@ -3,8 +3,6 @@ name: Release (GitHub/PyPI) and Deploy Docs on: workflow_dispatch: push: - branches: - - "**" tags: - "*" # Trigger on all tags initially, but tag and release privilege are verified in _build-wheel-release-upload.yml diff --git a/MANIFEST.in b/MANIFEST.in index d26fd26..00d47e0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -11,3 +11,4 @@ global-exclude .DS_Store # Exclude Mac filesystem artifacts. global-exclude __pycache__ # Exclude Python cache directories. global-exclude .git* # Exclude git files and directories. global-exclude .idea # Exclude PyCharm project settings. +global-exclude SConscript.configure SConscript # SCons build scripts diff --git a/requirements/pip.txt b/requirements/pip.txt index 24ce15a..a85739e 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -1 +1,2 @@ +setuptools numpy diff --git a/setup.py b/setup.py index cec2b8a..373f224 100644 --- a/setup.py +++ b/setup.py @@ -20,14 +20,31 @@ def get_boost_libraries(): - base_lib = "boost_python" - major, minor = str(sys.version_info[0]), str(sys.version_info[1]) - tags = [f"{major}{minor}", major, ""] - mttags = ["", "-mt"] - candidates = [base_lib + tag for tag in tags for mt in mttags] + [base_lib] - for lib in candidates: - if find_library(lib): - return [lib] + # the names we'll search for + major, minor = sys.version_info[:2] + candidates = [ + f"boost_python{major}{minor}", + f"boost_python{major}", + "boost_python", + ] + + conda_prefix = os.environ.get("CONDA_PREFIX") + if conda_prefix: + libdir = os.path.join(conda_prefix, "lib") + for name in candidates: + so = f"lib{name}.so" + if os.path.isfile(os.path.join(libdir, so)): + # return the plain "boost_python311" etc (no "lib" prefix or ".so") + return [name] + + # fallback to ldconfig + for name in candidates: + found = find_library(name) + if found: + # find_library may return "libboost_python3.so.1.74.0" etc + # strip off lib*.so.* if you like, or just return name + return [name] + raise RuntimeError("Cannot find a suitable Boost.Python library.") @@ -91,11 +108,10 @@ def create_extensions(): ) return [ext] - -setup_args = dict( - ext_modules=[], -) +def ext_modules(): + if set(sys.argv) & {"build_ext", "bdist_wheel", "install"}: + return create_extensions() + return [] if __name__ == "__main__": - setup_args["ext_modules"] = create_extensions() - setup(**setup_args) + setup(ext_modules=ext_modules()) From 7095b339609149dfc53557372423b5a9bfae2617 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Mon, 28 Jul 2025 10:43:02 -0400 Subject: [PATCH 2/3] remove obsolete workflow file --- .../workflows/_build-pyobjcryst-package.yml | 147 ------------------ 1 file changed, 147 deletions(-) delete mode 100644 .github/workflows/_build-pyobjcryst-package.yml diff --git a/.github/workflows/_build-pyobjcryst-package.yml b/.github/workflows/_build-pyobjcryst-package.yml deleted file mode 100644 index 0172f25..0000000 --- a/.github/workflows/_build-pyobjcryst-package.yml +++ /dev/null @@ -1,147 +0,0 @@ -name: Build wheel and sdist for a non-pure Python package - -on: - push: - -jobs: - build_sdist: - defaults: - run: - shell: bash -l {0} - - name: Build sdist - runs-on: ubuntu-latest - steps: - - name: Check out - uses: actions/checkout@v4 - - - name: Initialize miniconda - uses: conda-incubator/setup-miniconda@v3 - with: - activate-environment: sdist - channels: conda-forge - auto-update-conda: true - auto-activate-base: false - python-version: 3.13 - - - name: Conda config - run: >- - conda config --set always_yes yes - --set changeps1 no - - - name: Build sdist - run: | - pip install --upgrade build - python -m build --sdist - - - uses: actions/upload-artifact@v4 - with: - name: cibw-sdist - path: ./dist/*.tar.gz - - build-wheels: - needs: [build_sdist] - defaults: - run: - shell: bash -l {0} - - name: cibw-wheels-${{ matrix.python }}-${{ matrix.buildplat }} - runs-on: ${{ matrix.buildplat }} - strategy: - fail-fast: false - matrix: - buildplat: - - ubuntu-latest - - macos-13 - - macos-14 - - windows-latest - python: - - "3.11" - - "3.12" - - "3.13" - - steps: - - name: Check out - uses: actions/checkout@v4 - - - name: Initialize miniconda - uses: conda-incubator/setup-miniconda@v3 - with: - activate-environment: build - channels: conda-forge - auto-update-conda: true - auto-activate-base: false - python-version: ${{ matrix.python }} - - - name: Conda config - run: >- - conda config --set always_yes yes - --set changeps1 no - - - name: Install requirements - run: | - conda install --file requirements/conda.txt - conda install --file requirements/pip.txt - pip install --upgrade build - python -m pip wheel --no-deps --wheel-dir ./dist . - - - name: Upload wheels to GitHub - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.python }}-${{ matrix.buildplat }}.whl - path: ./dist/*.whl - - test-wheels: - needs: [build-wheels] - defaults: - run: - shell: bash -l {0} - - name: test-wheels-${{ matrix.python }}-${{ matrix.buildplat }} - runs-on: ${{ matrix.buildplat }} - strategy: - fail-fast: false - matrix: - buildplat: - - ubuntu-latest - - macos-13 - - macos-14 - - windows-latest - python: - - "3.11" - - "3.12" - - "3.13" - - steps: - - name: Check out - uses: actions/checkout@v4 - - - name: Download wheels - uses: actions/download-artifact@v4 - with: - name: ${{ matrix.python }}-${{ matrix.buildplat }}.whl - path: ./dist - - - name: Initialize miniconda - uses: conda-incubator/setup-miniconda@v3 - with: - activate-environment: test - channels: conda-forge - auto-update-conda: true - auto-activate-base: false - python-version: ${{ matrix.python }} - - - name: Conda config - run: >- - conda config --set always_yes yes - --set changeps1 no - - - name: Install requirements - run: | - conda install --file requirements/conda.txt - conda install --file requirements/tests.txt - - - name: Install wheel and test - run: | - pip install ./dist/*.whl - pytest From 9fc29ac453391dc7e032a1b093d4632f3989112b Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Mon, 28 Jul 2025 10:44:14 -0400 Subject: [PATCH 3/3] pcmt --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 373f224..243ed54 100644 --- a/setup.py +++ b/setup.py @@ -108,10 +108,12 @@ def create_extensions(): ) return [ext] + def ext_modules(): if set(sys.argv) & {"build_ext", "bdist_wheel", "install"}: return create_extensions() return [] + if __name__ == "__main__": setup(ext_modules=ext_modules())