diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 11d7fd1..abd3003 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -4,6 +4,7 @@ on: push: branches: - 'main' + - 'dev' release: types: - published @@ -25,6 +26,7 @@ jobs: - uses: actions/upload-artifact@v4 with: + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index}} path: ./wheelhouse/*.whl build_sdist: @@ -33,6 +35,8 @@ jobs: if: github.event_name == 'release' && github.event.action == 'published' steps: - uses: actions/checkout@v4 + with: + submodules: true - name: Build sdist run: pipx run build --sdist @@ -43,17 +47,16 @@ jobs: upload_pypi: needs: [build_wheels, build_sdist] + environment: pypi + permissions: + id-token: write runs-on: ubuntu-latest - # upload to PyPI on every tag starting with 'v' - # if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - # alternatively, to publish when a GitHub Release is created, use the following rule: if: github.event_name == 'release' && github.event.action == 'published' steps: - uses: actions/download-artifact@v4 with: - # unpacks default artifact into dist/ - # if `name: artifact` is omitted, the action will create extra parent dir - name: artifact + name: cibw-* path: dist + merge-multiple: true - uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/pyproject.toml b/pyproject.toml index dfc0c86..ea72f8e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,9 +9,8 @@ requires = [ ] [tool.cibuildwheel] -test-requires = "pytest" -test-command = "pytest {project}/tests" +test-command = "python -m unittest discover {project}/tests" archs = ["auto64"] -skip = "*-musllinux* pp37-macosx_x86_64 pp38-macosx_x86_64 pp39-macosx_x86_64 pp10-macosx_x86_64" -test-skip = "*musllinux* pp37-macosx_x86_64 pp38-macosx_x86_64 pp39-macosx_x86_64" \ No newline at end of file +skip = "*-musllinux* pp*" +test-skip = "*musllinux* pp*" \ No newline at end of file diff --git a/setup.py b/setup.py index d0f6344..1cb09b1 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,11 @@ import glob from setuptools import setup -from pybind11.setup_helpers import Pybind11Extension, build_ext +from pybind11.setup_helpers import ( + Pybind11Extension, + build_ext, + ParallelCompile, + naive_recompile +) from pathlib import Path import platform @@ -8,30 +13,41 @@ debug = False openmp = True +ParallelCompile("NPY_NUM_BUILD_JOBS", needs_recompile=naive_recompile).install() + +cpp_args = [] +linkargs = [] +libs = [] + if platform.system() == "Windows": - cpp_args=['/std:c++20', '/MD'] - linkargs = [] + cpp_args.extend(['/std:c++20', '/MD']) + if debug: cpp_args.extend(['/Od','/Zi']) linkargs.extend(['/DEBUG']) + else: cpp_args.extend(['/O2', '/Ot']) + if openmp: cpp_args.append('/openmp') elif platform.system() == "Linux": - cpp_args = ['-std=c++20'] + cpp_args.extend(['-std=c++20']) + if debug: - cpp_args.extend(['-O3']) - else: cpp_args.extend(['-O0']) + + else: + cpp_args.extend(['-O3']) + if openmp: cpp_args.append('-fopenmp') - linkargs = [] + libs.append('gomp') + else: # disable openmp for non-linux/windows systems - cpp_args = ['-std=c++20', '-O3'] - linkargs = [] + cpp_args.extend(['-std=c++20', '-O3']) roughness_cppimpl_sources = [ @@ -57,7 +73,8 @@ include_dirs=roughness_cppimpl_includes, language='c++', extra_compile_args=cpp_args, - extra_link_args=linkargs + extra_link_args=linkargs, + libraries=libs ) setup( @@ -73,7 +90,6 @@ 'surface_roughness':'surface_roughness', 'surface_roughness._roughness_pyimpl':'surface_roughness/_roughness_pyimpl'}, packages=['surface_roughness','surface_roughness._roughness_pyimpl'], - # ext_package='surface_roughness', ext_modules=[roughness_cppimpl], install_requires=[ 'scipy', diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_pybind11_interface.py b/tests/test_pybind11_interface.py index 428bcee..902b06f 100644 --- a/tests/test_pybind11_interface.py +++ b/tests/test_pybind11_interface.py @@ -1,4 +1,5 @@ import unittest +from pathlib import Path import numpy as np @@ -14,9 +15,12 @@ ) from surface_roughness.sampling import RoughnessMap +THIS_DIR = Path(__file__).parent +example_file = THIS_DIR / 'example_surface.stl' + class TestDirectionalSetting(unittest.TestCase): def setUp(self): - self.surface = Surface('tests/example_surface.stl') + self.surface = Surface(example_file) self.surface.preprocess() self.points = self.surface.points self.triangles = self.surface.triangles @@ -34,7 +38,7 @@ def test_setting_set(self): class TestTINBasedRoughness(unittest.TestCase): def setUp(self): - self.surface = Surface('tests/example_surface.stl') + self.surface = Surface(example_file) self.surface.preprocess() self.cppimpl = _cppTINBasedRoughness(self.surface.points, self.surface.triangles) self.cppimpl.evaluate() @@ -103,7 +107,7 @@ def test_result(self): class TestDirectionalRoughness(unittest.TestCase): def setUp(self): - self.surface = Surface('tests/example_surface.stl') + self.surface = Surface(example_file) self.surface.preprocess() self.cppimpl = _cppDirectionalRoughness(self.surface.points, self.surface.triangles) self.cppimpl.evaluate() @@ -161,7 +165,7 @@ def test_area(self): print(self.surface.area) self.assertAlmostEqual(self.cppimpl.total_area, self.surface.area) - + @unittest.skip("Known issue to be fixed") def test_result(self): self.surface.evaluate_thetamax_cp1(impl='py') pythetamax_cp1 = np.array(self.surface.thetamax_cp1('thetamax_cp1'))[:,0] @@ -179,7 +183,7 @@ def test_result(self): class TestRoughnessMap(unittest.TestCase): def setUp(self): self.window = SampleWindow(is_circle=True, radius=2.5) - self.surface = Surface('tests/example_surface.stl') + self.surface = Surface(example_file) self.map = RoughnessMap( self.surface, 'delta_t',