cascadio 0.2.0rc1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. cascadio-0.2.0rc1/.gitignore +179 -0
  2. cascadio-0.2.0rc1/.gitmodules +9 -0
  3. cascadio-0.2.0rc1/CMakeLists.txt +183 -0
  4. cascadio-0.2.0rc1/LICENSE/LICENSE-cascadio.md +21 -0
  5. cascadio-0.2.0rc1/LICENSE/LICENSE-opencascade.md +502 -0
  6. cascadio-0.2.0rc1/LICENSE/LICENSE-zstd.md +30 -0
  7. cascadio-0.2.0rc1/LICENSE/README.md +3 -0
  8. cascadio-0.2.0rc1/Makefile +162 -0
  9. cascadio-0.2.0rc1/PKG-INFO +181 -0
  10. cascadio-0.2.0rc1/README.md +153 -0
  11. cascadio-0.2.0rc1/cmake/toolchain.cmake +60 -0
  12. cascadio-0.2.0rc1/examples/show_brep.py +53 -0
  13. cascadio-0.2.0rc1/extensions/TM_brep_faces/README.md +128 -0
  14. cascadio-0.2.0rc1/extensions/TM_brep_faces/example.png +0 -0
  15. cascadio-0.2.0rc1/extensions/TM_brep_faces/schema/mesh.primitive.TM_brep_faces.schema.json +314 -0
  16. cascadio-0.2.0rc1/pyproject.toml +138 -0
  17. cascadio-0.2.0rc1/scripts/audit_wheel.py +58 -0
  18. cascadio-0.2.0rc1/scripts/build_occt.py +125 -0
  19. cascadio-0.2.0rc1/scripts/fuzz.py +165 -0
  20. cascadio-0.2.0rc1/scripts/gen_schema.py +571 -0
  21. cascadio-0.2.0rc1/scripts/test_occt_master.sh +26 -0
  22. cascadio-0.2.0rc1/scripts/test_readonly.py +65 -0
  23. cascadio-0.2.0rc1/scripts/test_system_occt.sh +20 -0
  24. cascadio-0.2.0rc1/src/cascadio/__init__.py +47 -0
  25. cascadio-0.2.0rc1/src/cascadio/deprecated.py +185 -0
  26. cascadio-0.2.0rc1/src/cascadio/extension.py +57 -0
  27. cascadio-0.2.0rc1/src/cascadio/primitives.py +274 -0
  28. cascadio-0.2.0rc1/src/cascadio/py.typed +0 -0
  29. cascadio-0.2.0rc1/src/convert.hpp +219 -0
  30. cascadio-0.2.0rc1/src/glb.hpp +45 -0
  31. cascadio-0.2.0rc1/src/gltf_writer.hpp +100 -0
  32. cascadio-0.2.0rc1/src/inject.hpp +153 -0
  33. cascadio-0.2.0rc1/src/load.hpp +300 -0
  34. cascadio-0.2.0rc1/src/main.cpp +436 -0
  35. cascadio-0.2.0rc1/src/primitives.hpp +117 -0
  36. cascadio-0.2.0rc1/src/process.hpp +646 -0
  37. cascadio-0.2.0rc1/src/request.hpp +141 -0
  38. cascadio-0.2.0rc1/src/sandbox.hpp +636 -0
  39. cascadio-0.2.0rc1/src/substance.hpp +124 -0
  40. cascadio-0.2.0rc1/src/trace.hpp +33 -0
  41. cascadio-0.2.0rc1/src/windows_text.hpp +26 -0
  42. cascadio-0.2.0rc1/src/worker.cpp +120 -0
  43. cascadio-0.2.0rc1/src/zstd.hpp +61 -0
  44. cascadio-0.2.0rc1/tests/conftest.py +52 -0
  45. cascadio-0.2.0rc1/tests/models/colored.step +636 -0
  46. cascadio-0.2.0rc1/tests/models/colored.step.zst +0 -0
  47. cascadio-0.2.0rc1/tests/models/cuboid_yup.step +234 -0
  48. cascadio-0.2.0rc1/tests/models/cuboid_zup.step +234 -0
  49. cascadio-0.2.0rc1/tests/models/featuretype.STEP +3083 -0
  50. cascadio-0.2.0rc1/tests/models/material.stp +250 -0
  51. cascadio-0.2.0rc1/tests/models/microstrip.igs +302 -0
  52. cascadio-0.2.0rc1/tests/models/microstrip.igs.zst +0 -0
  53. cascadio-0.2.0rc1/tests/models/multibody.step +10542 -0
  54. cascadio-0.2.0rc1/tests/models/two_materials.step +470 -0
  55. cascadio-0.2.0rc1/tests/models/written_by_0.1.1_featuretype.glb +0 -0
  56. cascadio-0.2.0rc1/tests/models/written_by_0.1.1_material.glb +0 -0
  57. cascadio-0.2.0rc1/tests/test_convert.py +716 -0
  58. cascadio-0.2.0rc1/tests/test_limits.py +494 -0
  59. cascadio-0.2.0rc1/tests/test_load.py +188 -0
  60. cascadio-0.2.0rc1/tests/test_schema.py +370 -0
  61. cascadio-0.2.0rc1/uv.lock +820 -0
@@ -0,0 +1,179 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+ *~
9
+
10
+ # Distribution / packaging
11
+ .Python
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ wheels/
24
+ wheelhouse/
25
+ share/python-wheels/
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+ MANIFEST
30
+
31
+ # PyInstaller
32
+ # Usually these files are written by a python script from a template
33
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
34
+ *.manifest
35
+ *.spec
36
+
37
+ # Installer logs
38
+ pip-log.txt
39
+ pip-delete-this-directory.txt
40
+
41
+ # Unit test / coverage reports
42
+ htmlcov/
43
+ .tox/
44
+ .nox/
45
+ .coverage
46
+ .coverage.*
47
+ .cache
48
+ nosetests.xml
49
+ coverage.xml
50
+ *.cover
51
+ *.py,cover
52
+ .hypothesis/
53
+ .pytest_cache/
54
+ cover/
55
+
56
+ # Translations
57
+ *.mo
58
+ *.pot
59
+
60
+ # Django stuff:
61
+ *.log
62
+ local_settings.py
63
+ db.sqlite3
64
+ db.sqlite3-journal
65
+
66
+ # Flask stuff:
67
+ instance/
68
+ .webassets-cache
69
+
70
+ # Scrapy stuff:
71
+ .scrapy
72
+
73
+ # Sphinx documentation
74
+ docs/_build/
75
+
76
+ # PyBuilder
77
+ .pybuilder/
78
+ target/
79
+
80
+ # Jupyter Notebook
81
+ .ipynb_checkpoints
82
+
83
+ # IPython
84
+ profile_default/
85
+ ipython_config.py
86
+
87
+ # pyenv
88
+ # For a library or package, you might want to ignore these files since the code is
89
+ # intended to run in multiple environments; otherwise, check them in:
90
+ .python-version
91
+
92
+ # pipenv
93
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
95
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
96
+ # install all needed dependencies.
97
+ #Pipfile.lock
98
+
99
+ # poetry
100
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
101
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
102
+ # commonly ignored for libraries.
103
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
104
+ #poetry.lock
105
+
106
+ # pdm
107
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
108
+ #pdm.lock
109
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
110
+ # in version control.
111
+ # https://pdm.fming.dev/#use-with-ide
112
+ .pdm.toml
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ .idea/
163
+
164
+ # Static OpenCASCADE built by scripts/build_occt.py
165
+ occt_install/
166
+
167
+ # written from uv.lock during wheel builds
168
+ build-constraints.txt
169
+
170
+ # GTAGS
171
+ GPATH
172
+ GRTAGS
173
+ GTAGS
174
+
175
+ # CMake
176
+ CMakeCache.txt
177
+ CMakeFiles/
178
+ wheelhouse/
179
+ fuzz-findings/
@@ -0,0 +1,9 @@
1
+ [submodule "OCCT"]
2
+ path = upstream/OCCT
3
+ url = https://github.com/Open-Cascade-SAS/OCCT.git
4
+ [submodule "upstream/rapidjson"]
5
+ path = upstream/rapidjson
6
+ url = https://github.com/Tencent/rapidjson.git
7
+ [submodule "upstream/zstd"]
8
+ path = upstream/zstd
9
+ url = https://github.com/facebook/zstd.git
@@ -0,0 +1,183 @@
1
+ cmake_minimum_required(VERSION 3.29)
2
+
3
+ # Use the same compiler, linker and flags as the OpenCASCADE build
4
+ # unless the caller brought their own toolchain.
5
+ if(NOT CMAKE_TOOLCHAIN_FILE)
6
+ set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/cmake/toolchain.cmake")
7
+ endif()
8
+
9
+ # scikit-build-core passes the version twice: numbers only for CMake, and
10
+ # in full (for example 0.2.0rc0) for the module's __version__.
11
+ if(NOT SKBUILD_PROJECT_VERSION)
12
+ set(SKBUILD_PROJECT_VERSION 0.0.0) # building with plain cmake
13
+ set(SKBUILD_PROJECT_VERSION_FULL 0.0.0)
14
+ endif()
15
+ project(cascadio VERSION ${SKBUILD_PROJECT_VERSION} LANGUAGES C CXX)
16
+
17
+ set(CMAKE_CXX_STANDARD 17)
18
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
19
+ if(NOT CMAKE_BUILD_TYPE)
20
+ set(CMAKE_BUILD_TYPE Release)
21
+ endif()
22
+
23
+ find_package(Python 3.12 REQUIRED
24
+ COMPONENTS Interpreter Development.Module
25
+ OPTIONAL_COMPONENTS Development.SABIModule)
26
+ find_package(nanobind CONFIG REQUIRED)
27
+
28
+ # OpenCASCADE: the static build from scripts/build_occt.py when it exists,
29
+ # otherwise whatever the system provides (distribution packages, sdist).
30
+ set(OCCT_MINIMUM 7.9) # first release where our glTF writer hooks exist
31
+ if(DEFINED ENV{CASCADIO_OCCT_PREFIX})
32
+ set(vendored_occt "$ENV{CASCADIO_OCCT_PREFIX}")
33
+ else()
34
+ set(vendored_occt "${CMAKE_CURRENT_LIST_DIR}/occt_install")
35
+ endif()
36
+ if(EXISTS "${vendored_occt}")
37
+ find_package(OpenCASCADE CONFIG REQUIRED PATHS "${vendored_occt}" NO_DEFAULT_PATH)
38
+ else()
39
+ find_package(OpenCASCADE CONFIG)
40
+ endif()
41
+ if(NOT OpenCASCADE_FOUND)
42
+ message(FATAL_ERROR
43
+ "OpenCASCADE was not found. From a git checkout run "
44
+ "`python scripts/build_occt.py` first. Otherwise install the "
45
+ "OpenCASCADE ${OCCT_MINIMUM}+ development files (plus RapidJSON and zstd) "
46
+ "and point CMAKE_PREFIX_PATH at them if they are not found.")
47
+ elseif(OpenCASCADE_VERSION VERSION_LESS OCCT_MINIMUM)
48
+ message(FATAL_ERROR
49
+ "cascadio needs OpenCASCADE ${OCCT_MINIMUM} or newer, "
50
+ "found ${OpenCASCADE_VERSION} in ${OpenCASCADE_INSTALL_PREFIX}")
51
+ endif()
52
+ message(STATUS "Using OpenCASCADE ${OpenCASCADE_VERSION} from ${OpenCASCADE_INSTALL_PREFIX}")
53
+
54
+ if(WIN32)
55
+ # keep <windows.h> from defining min/max macros and pulling in the world
56
+ add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN)
57
+ endif()
58
+
59
+ # Two binaries:
60
+ # cascadio-worker a plain program that does one conversion; all of
61
+ # OpenCASCADE is in here and Python is not
62
+ # _core the Python module, which starts the worker for every
63
+ # conversion and enforces the time and memory limits
64
+ # They share src/request.hpp (the request and the exit codes) and, on
65
+ # Windows, src/windows_text.hpp; neither of those has OpenCASCADE or Python.
66
+
67
+ add_executable(cascadio-worker src/worker.cpp)
68
+ target_include_directories(cascadio-worker SYSTEM PRIVATE "${OpenCASCADE_INCLUDE_DIR}")
69
+ # Only what src/ uses directly; these targets bring their own dependencies.
70
+ target_link_libraries(cascadio-worker PRIVATE
71
+ TKDESTEP TKDEIGES TKDEGLTF TKXCAF TKMesh)
72
+
73
+ # The code that writes TM_brep_faces JSON is generated from the extension's
74
+ # schema on every build, so the two cannot disagree.
75
+ set(brep_schema "${CMAKE_CURRENT_LIST_DIR}/extensions/TM_brep_faces/schema/mesh.primitive.TM_brep_faces.schema.json")
76
+ set(brep_header "${CMAKE_CURRENT_BINARY_DIR}/generated/tm_brep_faces.hpp")
77
+ add_custom_command(
78
+ OUTPUT "${brep_header}"
79
+ COMMAND Python::Interpreter "${CMAKE_CURRENT_LIST_DIR}/scripts/gen_schema.py"
80
+ header "${brep_header}"
81
+ DEPENDS "${brep_schema}" "${CMAKE_CURRENT_LIST_DIR}/scripts/gen_schema.py"
82
+ VERBATIM)
83
+ target_sources(cascadio-worker PRIVATE "${brep_header}")
84
+ target_include_directories(cascadio-worker PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/generated")
85
+ # the schema ships in the package for anyone who wants to validate output
86
+ install(FILES "${brep_schema}" DESTINATION cascadio RENAME schema.json)
87
+
88
+ # RapidJSON is header-only: vendored copy if checked out, else the system one.
89
+ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/upstream/rapidjson/include/rapidjson")
90
+ target_include_directories(cascadio-worker SYSTEM PRIVATE upstream/rapidjson/include)
91
+ else()
92
+ find_package(RapidJSON REQUIRED)
93
+ target_include_directories(cascadio-worker SYSTEM PRIVATE ${RapidJSON_INCLUDE_DIRS} ${RAPIDJSON_INCLUDE_DIRS})
94
+ endif()
95
+
96
+ # Zstandard, to accept compressed input. Only the decompressor is built from
97
+ # the vendored copy (about 100 KB); otherwise the system library is used.
98
+ set(zstd_source "${CMAKE_CURRENT_LIST_DIR}/upstream/zstd/lib")
99
+ if(EXISTS "${zstd_source}/zstd.h")
100
+ file(GLOB zstd_files "${zstd_source}/common/*.c" "${zstd_source}/decompress/*.c")
101
+ add_library(zstd_decompress STATIC ${zstd_files})
102
+ target_include_directories(zstd_decompress PUBLIC "${zstd_source}")
103
+ # no assembly (one less language to set up) and no pre-1.0 formats
104
+ target_compile_definitions(zstd_decompress PRIVATE ZSTD_DISABLE_ASM ZSTD_LEGACY_SUPPORT=0)
105
+ target_link_libraries(cascadio-worker PRIVATE zstd_decompress)
106
+ else()
107
+ find_path(ZSTD_INCLUDE_DIR zstd.h REQUIRED)
108
+ find_library(ZSTD_LIBRARY zstd REQUIRED)
109
+ target_include_directories(cascadio-worker SYSTEM PRIVATE "${ZSTD_INCLUDE_DIR}")
110
+ target_link_libraries(cascadio-worker PRIVATE "${ZSTD_LIBRARY}")
111
+ endif()
112
+
113
+ # Drop every function the worker never reaches. With a static
114
+ # OpenCASCADE this is what keeps the wheel small.
115
+ if(APPLE)
116
+ target_link_options(cascadio-worker PRIVATE -Wl,-dead_strip)
117
+ elseif(MSVC)
118
+ target_link_options(cascadio-worker PRIVATE /OPT:REF /OPT:ICF)
119
+ else()
120
+ target_link_options(cascadio-worker PRIVATE -Wl,--gc-sections)
121
+ if(CMAKE_LINKER_TYPE STREQUAL "LLD")
122
+ # fold identical functions, which OCCT's templates produce in bulk
123
+ target_link_options(cascadio-worker PRIVATE -Wl,--icf=safe)
124
+ endif()
125
+ if(CMAKE_BUILD_TYPE STREQUAL "Release")
126
+ target_link_options(cascadio-worker PRIVATE -s) # no symbol table
127
+ endif()
128
+ endif()
129
+ find_package(Threads REQUIRED)
130
+ target_link_libraries(cascadio-worker PRIVATE Threads::Threads)
131
+
132
+ # STABLE_ABI: one wheel serves every regular CPython from 3.12 on.
133
+ # FREE_THREADED: on free-threaded CPython (which has no stable ABI yet, so it
134
+ # gets its own wheel) declare that the module is safe without the GIL.
135
+ # It is: the module keeps no state, each call talks to its own process.
136
+ nanobind_add_module(_core STABLE_ABI FREE_THREADED src/main.cpp)
137
+ target_compile_definitions(_core PRIVATE VERSION_INFO=${SKBUILD_PROJECT_VERSION_FULL})
138
+ target_link_libraries(_core PRIVATE ${CMAKE_DL_LIBS})
139
+ if(WIN32)
140
+ # GetProcessMemoryInfo, to check the worker's memory (process.hpp)
141
+ target_link_libraries(_core PRIVATE psapi)
142
+ endif()
143
+
144
+ # Our own code is compiled with every reasonable warning on. OpenCASCADE,
145
+ # RapidJSON and zstd headers are included as SYSTEM, so they stay quiet.
146
+ # CASCADIO_STRICT=ON (set by the Makefile and by CI) turns warnings into
147
+ # errors; it is off by default so a packager's newer compiler cannot break
148
+ # the build over a warning we have not seen yet.
149
+ if(MSVC)
150
+ set(strict_warnings /W4)
151
+ set(warnings_as_errors /WX)
152
+ else()
153
+ set(strict_warnings -Wall -Wextra -Wpedantic -Wshadow -Wconversion
154
+ -Wsign-conversion -Wold-style-cast -Wcast-qual -Wnon-virtual-dtor
155
+ -Woverloaded-virtual -Wnull-dereference -Wdouble-promotion -Wformat=2
156
+ -Wimplicit-fallthrough)
157
+ set(warnings_as_errors -Werror)
158
+ endif()
159
+ # nanobind is built as part of this project, so its headers (and Python's,
160
+ # which it brings along) would be held to our warnings; mark it SYSTEM.
161
+ get_target_property(core_libraries _core LINK_LIBRARIES)
162
+ foreach(library ${core_libraries})
163
+ if(TARGET ${library} AND library MATCHES "nanobind")
164
+ set_target_properties(${library} PROPERTIES SYSTEM TRUE)
165
+ endif()
166
+ endforeach()
167
+ foreach(target cascadio-worker _core)
168
+ target_compile_options(${target} PRIVATE ${strict_warnings})
169
+ if("$ENV{CASCADIO_STRICT}")
170
+ target_compile_options(${target} PRIVATE ${warnings_as_errors})
171
+ endif()
172
+ endforeach()
173
+
174
+ install(TARGETS cascadio-worker RUNTIME DESTINATION cascadio)
175
+ install(TARGETS _core LIBRARY DESTINATION cascadio)
176
+
177
+ # Type stubs are generated from the compiled module so they cannot go stale.
178
+ nanobind_add_stub(_core_stub
179
+ MODULE _core
180
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_core.pyi"
181
+ PYTHON_PATH $<TARGET_FILE_DIR:_core>
182
+ DEPENDS _core)
183
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/_core.pyi" DESTINATION cascadio)
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Michael Dawson-Haggerty
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.