From 74d74e24d5c9ec362c3bb0dc4ebfbaa75f674c24 Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Thu, 30 Nov 2023 14:04:28 +0900 Subject: [PATCH 01/12] Update build script. --- .github/workflows/macos.yml | 80 ++++++++++------------------------- .github/workflows/ubuntu.yml | 77 +++++++++++---------------------- .github/workflows/windows.yml | 28 +++++++++--- build.py => build_exts.py | 3 -- pyproject.toml | 34 ++++++++------- 5 files changed, 88 insertions(+), 134 deletions(-) rename build.py => build_exts.py (92%) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index e189129..21edd29 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -9,31 +9,28 @@ on: tags: - v* -env: - BUILD_TYPE: Release - GNU_CC: /usr/local/bin/gcc-9 - GNU_CXX: /usr/local/bin/g++-9 - LLVM_CC: /usr/local/opt/llvm/bin/clang - LLVM_CXX: /usr/local/opt/llvm/bin/clang++ - jobs: macos: runs-on: macos-latest strategy: matrix: - compiler: [clang] - # compiler: [gcc, clang] + python-version-major: 3 + python-version-minor: [8, 9, 10, 11, 12] + + env: + BUILD_TYPE: Release + python-version: ${{ format('{0}.{1}', matrix.python-version-major, matrix.python-version-minor) }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: submodules: true - name: Set up Python version - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: ${{ env.python-version }} - name: Install Poetry run: | @@ -50,20 +47,6 @@ jobs: restore-keys: | ${{ runner.os }}-poetry-${{ hashFiles('**/pyproject.toml') }} - - name: Install GNU C/C++ compiler - if: ${{ matrix.compiler == 'gcc' }} - run: | - brew install gcc@9 - export GNU_CC=gcc-9 - export GNU_CXX=g++-9 - - - name: Install LLVM Clang - if: ${{ matrix.compiler == 'clang' }} - run: | - brew install llvm - export LLVM_CC=clang-10 - export LLVM_CXX=clang++-10 - - name: Install Google Test env: C_COMPILER: ${{ matrix.compiler }} @@ -73,20 +56,7 @@ jobs: mkdir build cd build - if [ "$C_COMPILER" = "gcc" ]; then - cmake .. \ - -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ - -DCMAKE_C_COMPILER=$GNU_CC \ - -DCMAKE_CXX_COMPILER=$GNU_CXX - fi - - if [ "$C_COMPILER" = "clang" ]; then - cmake .. \ - -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ - -DCMAKE_C_COMPILER=$LLVM_CC \ - -DCMAKE_CXX_COMPILER=$LLVM_CXX - fi - + cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE cmake --build . --config $BUILD_TYPE --parallel 2 cmake --build . --target install @@ -97,23 +67,10 @@ jobs: cmake -E make_directory ${{runner.workspace}}/build cd ${{runner.workspace}}/build - if [ "$C_COMPILER" = "gcc" ]; then - cmake $GITHUB_WORKSPACE \ - -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ - -DCMAKE_C_COMPILER=$GNU_CC \ - -DCMAKE_CXX_COMPILER=$GNU_CXX \ - -DBUILD_EXAMPLES=ON \ - -DBUILD_TESTS=ON - fi - - if [ "$C_COMPILER" = "clang" ]; then - cmake $GITHUB_WORKSPACE \ - -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ - -DCMAKE_C_COMPILER=$LLVM_CC \ - -DCMAKE_CXX_COMPILER=$LLVM_CXX \ - -DBUILD_EXAMPLES=ON \ - -DBUILD_TESTS=ON - fi + cmake $GITHUB_WORKSPACE \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ + -DBUILD_EXAMPLES=ON \ + -DBUILD_TESTS=ON cmake --build . --config $BUILD_TYPE --parallel 2 @@ -126,7 +83,16 @@ jobs: if: steps.pipenv-cache.outputs.cache-hit != 'true' run: | poetry install + poetry build -f wheel - name: Python module test run: | poetry run pytest -s tests + + - name: Create release + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: ./dist/*.whl + draft: false + prerelease: false diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index fa33d1e..b2145e1 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -9,30 +9,28 @@ on: tags: - v* -env: - BUILD_TYPE: Release - GNU_CC: gcc-9 - GNU_CXX: g++-9 - LLVM_CC: clang-11 - LLVM_CXX: clang++-11 - jobs: ubuntu: runs-on: ubuntu-latest strategy: matrix: - compiler: [gcc, clang] + python-version-major: 3 + python-version-minor: [8, 9, 10, 11, 12] + + env: + BUILD_TYPE: Release + python-version: ${{ format('{0}.{1}', matrix.python-version-major, matrix.python-version-minor) }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: submodules: true - name: Set up Python version - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: ${{ env.python-version }} - name: Install Poetry run: | @@ -50,18 +48,10 @@ jobs: ${{ runner.os }}-poetry-${{ hashFiles('**/pyproject.toml') }} - name: Install GNU C/C++ compiler - if: ${{ matrix.compiler == 'gcc' }} run: | sudo apt-get install -y gcc-9 g++-9 - export GNU_CC=gcc-9 - export GNU_CXX=g++-9 - - - name: Install LLVM Clang - if: ${{ matrix.compiler == 'clang' }} - run: | - sudo apt-get install -y clang-11 clang++-11 - export LLVM_CC=clang-11 - export LLVM_CXX=clang++-11 + export CC=gcc-9 + export CXX=g++-9 - name: Install Google Test env: @@ -72,20 +62,7 @@ jobs: mkdir build cd build - if [ "$C_COMPILER" = "gcc" ]; then - cmake .. \ - -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ - -DCMAKE_C_COMPILER=$GNU_CC \ - -DCMAKE_CXX_COMPILER=$GNU_CXX - fi - - if [ "$C_COMPILER" = "clang" ]; then - cmake .. \ - -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ - -DCMAKE_C_COMPILER=$LLVM_CC \ - -DCMAKE_CXX_COMPILER=$LLVM_CXX - fi - + cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE cmake --build . --config $BUILD_TYPE --parallel 2 sudo cmake --build . --target install @@ -96,23 +73,10 @@ jobs: cmake -E make_directory ${{runner.workspace}}/build cd ${{runner.workspace}}/build - if [ "$C_COMPILER" = "gcc" ]; then - cmake $GITHUB_WORKSPACE \ - -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ - -DCMAKE_C_COMPILER=$GNU_CC \ - -DCMAKE_CXX_COMPILER=$GNU_CXX \ - -DBUILD_EXAMPLES=ON \ - -DBUILD_TESTS=ON - fi - - if [ "$C_COMPILER" = "clang" ]; then - cmake $GITHUB_WORKSPACE \ - -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ - -DCMAKE_C_COMPILER=$LLVM_CC \ - -DCMAKE_CXX_COMPILER=$LLVM_CXX \ - -DBUILD_EXAMPLES=ON \ - -DBUILD_TESTS=ON - fi + cmake $GITHUB_WORKSPACE \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ + -DBUILD_EXAMPLES=ON \ + -DBUILD_TESTS=ON cmake --build . --config $BUILD_TYPE --parallel 2 @@ -125,7 +89,16 @@ jobs: if: steps.pipenv-cache.outputs.cache-hit != 'true' run: | poetry install + poetry build -f wheel - name: Python module test run: | poetry run pytest -s tests + + - name: Create release + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: ./dist/*.whl + draft: false + prerelease: false diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index b59763b..543567e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -9,21 +9,28 @@ on: tags: - v* -env: - BUILD_TYPE: Release - jobs: windows: runs-on: windows-latest + + strategy: + matrix: + python-version-major: 3 + python-version-minor: [8, 9, 10, 11, 12] + + env: + BUILD_TYPE: Release + python-version: ${{ format('{0}.{1}', matrix.python-version-major, matrix.python-version-minor) }} + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: submodules: true - name: Set up Python version - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: ${{ env.python-version }} - name: Install Poetry run: | @@ -73,7 +80,16 @@ jobs: if: steps.pipenv-cache.outputs.cache-hit != 'true' run: | poetry install + poetry build -f wheel - name: Python module test run: | poetry run pytest -s tests + + - name: Create release + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: ./dist/*.whl + draft: false + prerelease: false diff --git a/build.py b/build_exts.py similarity index 92% rename from build.py rename to build_exts.py index fbcce01..5c16fa9 100644 --- a/build.py +++ b/build_exts.py @@ -28,9 +28,6 @@ '-std=c++17', '-mmacosx-version-min=10.15', ]) - # extra_link_args.extend([ - # '-lstdc++fs', - # ]) else: extra_compile_args.extend([ '-std=c++17', diff --git a/pyproject.toml b/pyproject.toml index fe1b5bd..967bdfb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=42", "poetry_core>=1.0.0", "pybind11~=2.6.1"] +requires = ["setuptools>=42", "poetry_core>=1.0.0", "pybind11>=2.0.0"] build-backend = "poetry.core.masonry.api" [tool.poetry] @@ -15,23 +15,25 @@ repository = "https://github.com/tatsy/tinymesh" homepage = "https://github.com/tatsy/tinymesh" keywords = ['graphics', 'geometry'] - -build = "build.py" exclude = ["src/*", "tests/*", "cmake/*", "data/*", "figures/*"] +[tool.poetry.build] +script = "build_exts.py" +generate-setup-file = false + [tool.poetry.dependencies] -python = ">=3.9,<3.11" -setuptools = "^57.4.0" -pybind11 = "^2.10.1" +python = ">=3.6,<=3.12" +setuptools = "^57" +pybind11 = "^2" [tool.poetry.group.dev.dependencies] -yapf = "^0.32.0" -flake8 = "^6.0.0" -mypy = "^0.991" -isort = "^5.10.1" -pytest = "^7.2.0" -jupyterlab = "^3.5.0" -scipy = "^1.9.3" -numpy = "^1.23.5" -matplotlib = "^3.6.2" -open3d = "0.16.0" +yapf = "*" +flake8 = "*" +mypy = "*" +isort = "*" +pytest = "*" +jupyterlab = "*" +scipy = "*" +numpy = "*" +matplotlib = "*" +open3d = "^0.15" From d9956b0c95cc5bd70a6c3c33dfaf29a9937c5dfd Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Thu, 30 Nov 2023 14:05:59 +0900 Subject: [PATCH 02/12] Update Github Actions. --- .github/workflows/macos.yml | 2 +- .github/workflows/ubuntu.yml | 2 +- .github/workflows/windows.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 21edd29..5139c38 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - python-version-major: 3 + python-version-major: [3] python-version-minor: [8, 9, 10, 11, 12] env: diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index b2145e1..7574643 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - python-version-major: 3 + python-version-major: [3] python-version-minor: [8, 9, 10, 11, 12] env: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 543567e..6fff32a 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - python-version-major: 3 + python-version-major: [3] python-version-minor: [8, 9, 10, 11, 12] env: From 38e42a21c24b9e52cb142e7f76426ac68880762c Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Thu, 30 Nov 2023 14:45:22 +0900 Subject: [PATCH 03/12] Update build script. --- .github/workflows/macos.yml | 3 +- .github/workflows/ubuntu.yml | 3 +- .github/workflows/windows.yml | 3 +- build_exts.py | 109 ++++++++++++++++++++------------ examples/python/construct.ipynb | 21 +++--- pyproject.toml | 28 ++++++-- setup.cfg | 30 --------- 7 files changed, 110 insertions(+), 87 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 5139c38..5229c6c 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -82,11 +82,12 @@ jobs: - name: Install Python modules if: steps.pipenv-cache.outputs.cache-hit != 'true' run: | - poetry install + poetry install --only-root poetry build -f wheel - name: Python module test run: | + poetry run pip install pytest poetry run pytest -s tests - name: Create release diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 7574643..e1e63ea 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -88,11 +88,12 @@ jobs: - name: Install Python modules if: steps.pipenv-cache.outputs.cache-hit != 'true' run: | - poetry install + poetry install --only-root poetry build -f wheel - name: Python module test run: | + poetry run pip install pytest poetry run pytest -s tests - name: Create release diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 6fff32a..d0a61ef 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -79,11 +79,12 @@ jobs: - name: Install Python modules if: steps.pipenv-cache.outputs.cache-hit != 'true' run: | - poetry install + poetry install --only-root poetry build -f wheel - name: Python module test run: | + poetry run pip install pytest poetry run pytest -s tests - name: Create release diff --git a/build_exts.py b/build_exts.py index 5c16fa9..b24fa24 100644 --- a/build_exts.py +++ b/build_exts.py @@ -1,56 +1,83 @@ import re -import pathlib +import glob import platform from pybind11.setup_helpers import Pybind11Extension from setuptools.command.build_ext import build_ext -exclude = ['src/tinymesh/ext'] -sources = pathlib.Path().glob('src/**/*.cpp') -sources = [str(path).replace('\\', '/') for path in sources] + +class TinyMeshBuildExt(build_ext): + def run(self): + try: + build_ext.run(self) + except FileNotFoundError: + raise Exception("File not found. Could not compile C extension") + + def build_extension(self, ext): + for e in self.extensions: + e.define_macros.extend( + [ + ("TINYMESH_PYTHON_MODULE", 1), + ] + ) + + if platform.system() == "Darwin": + for e in self.extensions: + e.extra_compile_args.extend( + [ + "-mmacosx-version-min=10.15", + ] + ) + + if self.compiler.compiler_type == "unix": + for e in self.extensions: + e.extra_compile_args.extend( + [ + "-std=c++17", + ] + ) + e.extra_link_args.extend( + [ + "-lstdc++fs", + ] + ) + elif self.compiler.compiler_type == "msvc": + for e in self.extensions: + e.define_macros.extend( + [ + ("_CRT_SECURE_NO_WARNINGS", 1), + ("_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING", 1), + ] + ) + + +exclude = ["src/tinymesh/ext"] +sources = glob.glob("src/**/*.cpp") +sources = [str(path).replace("\\", "/") for path in sources] sources = [path for path in sources if all([not re.search(e, path) for e in exclude])] -include_dirs = [ - 'src/tinymesh', - 'src/tinymesh/ext/tinyobjloader', - 'src/tinymesh/ext/tinyply/source', - 'src/tinymesh/ext/eigen', - 'src/tinymesh/ext/spectra/include', +include = [ + "src/tinymesh", + "src/tinymesh/ext/tinyobjloader", + "src/tinymesh/ext/tinyply/source", + "src/tinymesh/ext/eigen", + "src/tinymesh/ext/spectra/include", ] -extra_compile_args = [] -extra_link_args = [] -define_macros = [('TINYMESH_PYTHON_MODULE', 1)] -if platform.system() == "Windows": - define_macros.append(('_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING', 1)) -elif platform.system() == "Darwin": - extra_compile_args.extend([ - '-std=c++17', - '-mmacosx-version-min=10.15', - ]) -else: - extra_compile_args.extend([ - '-std=c++17', - ]) - extra_link_args.extend([ - '-lstdc++fs', - ]) - ext_modules = [ - Pybind11Extension('tinymesh', - sources, - language='c++', - include_dirs=include_dirs, - extra_compile_args=extra_compile_args, - extra_link_args=extra_link_args, - define_macros=define_macros) + Pybind11Extension( + "tinymesh", + sources, + language="c++", + include_dirs=include, + ) ] def build(setup_kwargs): - setup_kwargs.update({ - 'ext_modules': ext_modules, - 'cmdclass': { - 'build_ext': build_ext - }, - }) + setup_kwargs.update( + { + "ext_modules": ext_modules, + "cmdclass": {"build_ext": TinyMeshBuildExt}, + } + ) diff --git a/examples/python/construct.ipynb b/examples/python/construct.ipynb index 63a1b44..0f20a2e 100644 --- a/examples/python/construct.ipynb +++ b/examples/python/construct.ipynb @@ -17,8 +17,11 @@ "source": [ "import os\n", "import numpy as np\n", - "import open3d as o3d\n", - "from IPython.display import display, Markdown" + "from IPython.display import display, Markdown\n", + "try:\n", + " import open3d as o3d\n", + "except ImportError:\n", + " raise ImportError(\"This notebook requires Open3D. Install it first!\")\n" ] }, { @@ -29,7 +32,7 @@ "outputs": [], "source": [ "from tinymesh import Mesh\n", - "from viewer import Viewer" + "from viewer import Viewer\n" ] }, { @@ -49,7 +52,7 @@ "source": [ "models_dir = \"../../data/models/\"\n", "filename = os.path.join(models_dir, \"bunny.ply\")\n", - "assert os.path.exists(filename), \"file does not exist: %s\" % filename" + "assert os.path.exists(filename), \"file does not exist: %s\" % filename\n" ] }, { @@ -75,7 +78,7 @@ "ply = o3d.io.read_triangle_mesh(filename)\n", "verts = np.asarray(ply.vertices, dtype=\"float32\")\n", "faces = np.asarray(ply.triangles, dtype=\"uint32\")\n", - "display(Markdown(\"**verts:** {:d}, **faces:** {:d}\".format(len(verts), len(faces))))" + "display(Markdown(\"**verts:** {:d}, **faces:** {:d}\".format(len(verts), len(faces))))\n" ] }, { @@ -99,7 +102,7 @@ "viewer = Viewer(1200, 800)\n", "viewer.lookat(2, 3, 4, 0, 0, 0, 0, 1, 0)\n", "viewer.perspective(45, viewer.aspect, 1, 100)\n", - "viewer.visualization(verts, faces)" + "viewer.visualization(verts, faces)\n" ] }, { @@ -119,7 +122,7 @@ "source": [ "mesh = Mesh(verts, faces.reshape(-1)) # tinymesh uses flatten face indices\n", "verts = mesh.get_vertices()\n", - "faces = mesh.get_vertex_indices()" + "faces = mesh.get_vertex_indices()\n" ] }, { @@ -158,7 +161,7 @@ "faces = np.asarray(faces, dtype=\"uint32\").reshape((-1, 3))\n", "\n", "display(Markdown(\"### #verts, #faces are decreased by remove redudant vertices/faces!\"))\n", - "display(Markdown(\"**verts:** {:d}, **faces:** {:d}\".format(len(verts), len(faces))))" + "display(Markdown(\"**verts:** {:d}, **faces:** {:d}\".format(len(verts), len(faces))))\n" ] }, { @@ -179,7 +182,7 @@ } ], "source": [ - "viewer.mesh_visualization(mesh)" + "viewer.mesh_visualization(mesh)\n" ] }, { diff --git a/pyproject.toml b/pyproject.toml index 967bdfb..bc1a02e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,12 +22,12 @@ script = "build_exts.py" generate-setup-file = false [tool.poetry.dependencies] -python = ">=3.6,<=3.12" +python = ">=3.8,<=3.12" setuptools = "^57" -pybind11 = "^2" +pybind11 = "^2.0" [tool.poetry.group.dev.dependencies] -yapf = "*" +black = "*" flake8 = "*" mypy = "*" isort = "*" @@ -36,4 +36,24 @@ jupyterlab = "*" scipy = "*" numpy = "*" matplotlib = "*" -open3d = "^0.15" + +[tool.isort] +profile = "black" +length_sort = "True" +line_length = 120 + +[tool.mypy] +python_version = 3.9 +follow_imports = "silent" +disallow_any_generics = "True" +strict_optional = "True" +check_untyped_defs = "True" +allow_redefinition = "True" + +[tool.flake8] +max-line-length = 120 +ignore = "Q000,E127,E203,E402,W503,W504" + +[tool.black] +target-version = ["py39", "py310", "py311"] +line-length = 120 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 8332e91..0000000 --- a/setup.cfg +++ /dev/null @@ -1,30 +0,0 @@ -[isort] -length_sort = true -line_length = 120 - -[mypy] -python_version = 3.9 -follow_imports = silent -disallow_any_generics = True -strict_optional = True -check_untyped_defs = True -allow_redefinition = True - -[flake8] -max-line-length = 120 -ignore = Q000,E127,E203,W503,W504 - -[yapf] -BASED_ON_STYLE = pep8 -COLUMN_LIMIT = 120 -INDENT_WIDTH = 4 - -ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT = True -ALLOW_MULTILINE_LAMBDAS = False -ALLOW_SPLIT_BEFORE_DICT_VALUE = False -BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = False -CONTINUATION_ALIGN_STYLE = SPACE -COALESCE_BRACKETS = False -DEDENT_CLOSING_BRACKETS = False -DISABLE_ENDING_COMMA_HEURISTIC = False -INDENT_DICTIONARY_VALUE = True From 2433f0ebb6ace1a0668db8fc38d7824375e0f2bd Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Thu, 30 Nov 2023 15:03:46 +0900 Subject: [PATCH 04/12] Update build script. --- .github/workflows/macos.yml | 3 +-- .github/workflows/ubuntu.yml | 3 +-- .github/workflows/windows.yml | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 5229c6c..9719b0b 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -82,12 +82,11 @@ jobs: - name: Install Python modules if: steps.pipenv-cache.outputs.cache-hit != 'true' run: | - poetry install --only-root poetry build -f wheel + poetry install - name: Python module test run: | - poetry run pip install pytest poetry run pytest -s tests - name: Create release diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index e1e63ea..1775128 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -88,12 +88,11 @@ jobs: - name: Install Python modules if: steps.pipenv-cache.outputs.cache-hit != 'true' run: | - poetry install --only-root poetry build -f wheel + poetry install - name: Python module test run: | - poetry run pip install pytest poetry run pytest -s tests - name: Create release diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d0a61ef..4e5ca37 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -79,12 +79,11 @@ jobs: - name: Install Python modules if: steps.pipenv-cache.outputs.cache-hit != 'true' run: | - poetry install --only-root poetry build -f wheel + poetry install - name: Python module test run: | - poetry run pip install pytest poetry run pytest -s tests - name: Create release From 1e771be955ba5ff919711000897a4eccf426c715 Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Thu, 30 Nov 2023 15:11:12 +0900 Subject: [PATCH 05/12] Minor update. --- CHANGELOG.md | 5 +++++ build_exts.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b3327b..2fe8381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +v0.2.4 +--- +* Update CI scripts to build wheels for 5 latest Python versions. + + v0.2.3 --- * Update some method names (e.g., `isStatic` -> `isLocked`) diff --git a/build_exts.py b/build_exts.py index b24fa24..553962a 100644 --- a/build_exts.py +++ b/build_exts.py @@ -1,5 +1,5 @@ import re -import glob +import pathlib import platform from pybind11.setup_helpers import Pybind11Extension @@ -52,7 +52,7 @@ def build_extension(self, ext): exclude = ["src/tinymesh/ext"] -sources = glob.glob("src/**/*.cpp") +sources = pathlib.Path().glob("src/**/*.cpp") sources = [str(path).replace("\\", "/") for path in sources] sources = [path for path in sources if all([not re.search(e, path) for e in exclude])] From 0f7eb179e24a6ebe16139503c3829c7847798d25 Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Thu, 30 Nov 2023 15:38:45 +0900 Subject: [PATCH 06/12] Minor update. --- build_exts.py | 16 ++++++++++++++-- pyproject.toml | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/build_exts.py b/build_exts.py index 553962a..cba8f4d 100644 --- a/build_exts.py +++ b/build_exts.py @@ -2,14 +2,19 @@ import pathlib import platform -from pybind11.setup_helpers import Pybind11Extension +from setuptools.errors import CCompilerError, PackageDiscoveryError from setuptools.command.build_ext import build_ext +try: + from pybind11.setup_helpers import Pybind11Extension +except ImportError: + from setuptools import Extension as Pybind11Extension + class TinyMeshBuildExt(build_ext): def run(self): try: - build_ext.run(self) + super(TinyMeshBuildExt, self).run() except FileNotFoundError: raise Exception("File not found. Could not compile C extension") @@ -41,8 +46,10 @@ def build_extension(self, ext): "-lstdc++fs", ] ) + elif self.compiler.compiler_type == "msvc": for e in self.extensions: + e.extra_compile_args.extend(["/utf-8"]) e.define_macros.extend( [ ("_CRT_SECURE_NO_WARNINGS", 1), @@ -50,6 +57,11 @@ def build_extension(self, ext): ] ) + try: + super(TinyMeshBuildExt, self).build_extension(ext) + except (CCompilerError, PackageDiscoveryError, ValueError): + raise Exception("Could not compile C extension") + exclude = ["src/tinymesh/ext"] sources = pathlib.Path().glob("src/**/*.cpp") diff --git a/pyproject.toml b/pyproject.toml index bc1a02e..e336e23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=42", "poetry_core>=1.0.0", "pybind11>=2.0.0"] +requires = ["setuptools", "poetry_core>=1.5.0", "pybind11>=2.0.0"] build-backend = "poetry.core.masonry.api" [tool.poetry] @@ -19,7 +19,7 @@ exclude = ["src/*", "tests/*", "cmake/*", "data/*", "figures/*"] [tool.poetry.build] script = "build_exts.py" -generate-setup-file = false +generate-setup-file = true [tool.poetry.dependencies] python = ">=3.8,<=3.12" From 1bce516b8ce3ec987137728b5e3394d03748f65f Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Thu, 30 Nov 2023 15:40:24 +0900 Subject: [PATCH 07/12] Minor update. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e336e23..ebee69c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ exclude = ["src/*", "tests/*", "cmake/*", "data/*", "figures/*"] [tool.poetry.build] script = "build_exts.py" -generate-setup-file = true +generate-setup-file = false [tool.poetry.dependencies] python = ">=3.8,<=3.12" From 189cfb238a9491628f10627499a845b6e5c8b88d Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Thu, 30 Nov 2023 15:46:21 +0900 Subject: [PATCH 08/12] Minor update. --- pyproject.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ebee69c..60bc647 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,9 +34,13 @@ isort = "*" pytest = "*" jupyterlab = "*" scipy = "*" -numpy = "*" matplotlib = "*" +numpy = [ + { version = "~1.26.0", python = "^3.12" }, + { version = "*", python = ">=3.8,<3.12" }, +] + [tool.isort] profile = "black" length_sort = "True" From 4a7646ab9b40985d6ccf2753093af502b57dbc8b Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Thu, 30 Nov 2023 15:51:40 +0900 Subject: [PATCH 09/12] Minor update. --- pyproject.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 60bc647..aa73208 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,6 @@ mypy = "*" isort = "*" pytest = "*" jupyterlab = "*" -scipy = "*" matplotlib = "*" numpy = [ @@ -41,6 +40,11 @@ numpy = [ { version = "*", python = ">=3.8,<3.12" }, ] +scipy = [ + { version = "~1.6.1", python = "^3.12" }, + { version = "*", python = ">=3.8,<3.12" }, +] + [tool.isort] profile = "black" length_sort = "True" From 87c768d7ade459a48c63f7ebe5520e8c0c867e5c Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Thu, 30 Nov 2023 15:57:14 +0900 Subject: [PATCH 10/12] Minor update. --- build_exts.py | 19 ++++++++++++++++--- pyproject.toml | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/build_exts.py b/build_exts.py index cba8f4d..f8c7296 100644 --- a/build_exts.py +++ b/build_exts.py @@ -19,6 +19,7 @@ def run(self): raise Exception("File not found. Could not compile C extension") def build_extension(self, ext): + # common settings for e in self.extensions: e.define_macros.extend( [ @@ -26,6 +27,7 @@ def build_extension(self, ext): ] ) + # OS specific settings if platform.system() == "Darwin": for e in self.extensions: e.extra_compile_args.extend( @@ -34,22 +36,32 @@ def build_extension(self, ext): ] ) - if self.compiler.compiler_type == "unix": + elif platform.system() == "Linux": for e in self.extensions: e.extra_compile_args.extend( [ - "-std=c++17", + "-fopenmp", ] ) e.extra_link_args.extend( [ + "-fopenmp", "-lstdc++fs", ] ) + # compiler specific settings + if self.compiler.compiler_type == "unix": + for e in self.extensions: + e.extra_compile_args.extend( + [ + "-std=c++17", + ] + ) + elif self.compiler.compiler_type == "msvc": for e in self.extensions: - e.extra_compile_args.extend(["/utf-8"]) + e.extra_compile_args.extend(["/utf-8", "/openmp"]) e.define_macros.extend( [ ("_CRT_SECURE_NO_WARNINGS", 1), @@ -57,6 +69,7 @@ def build_extension(self, ext): ] ) + # building try: super(TinyMeshBuildExt, self).build_extension(ext) except (CCompilerError, PackageDiscoveryError, ValueError): diff --git a/pyproject.toml b/pyproject.toml index aa73208..42b81b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ exclude = ["src/*", "tests/*", "cmake/*", "data/*", "figures/*"] [tool.poetry.build] script = "build_exts.py" -generate-setup-file = false +generate-setup-file = true [tool.poetry.dependencies] python = ">=3.8,<=3.12" From 6730dd1e47ba1f7ba1b7410fbb12d42ce579608a Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Thu, 30 Nov 2023 16:05:29 +0900 Subject: [PATCH 11/12] Minor update. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 42b81b2..02cff5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ numpy = [ ] scipy = [ - { version = "~1.6.1", python = "^3.12" }, + { version = "~1.6.2", python = "^3.12" }, { version = "*", python = ">=3.8,<3.12" }, ] From e218648dee7ec04b4719118acc34a30d92619692 Mon Sep 17 00:00:00 2001 From: Tatsuya Yatagawa Date: Thu, 30 Nov 2023 17:24:42 +0900 Subject: [PATCH 12/12] Minor update. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 02cff5c..3edc6d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ numpy = [ ] scipy = [ - { version = "~1.6.2", python = "^3.12" }, + { version = "~1.11.2", python = "^3.12" }, { version = "*", python = ">=3.8,<3.12" }, ]