xcoll 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

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.

Potentially problematic release.


This version of xcoll might be problematic. Click here for more details.

Files changed (324) hide show
  1. xcoll/__init__.py +2 -1
  2. xcoll/beam_elements/__init__.py +7 -1
  3. xcoll/beam_elements/absorber.py +2 -2
  4. xcoll/beam_elements/base.py +105 -67
  5. xcoll/beam_elements/blowup.py +198 -0
  6. xcoll/beam_elements/{collimators_src → elements_src}/black_absorber.h +21 -3
  7. xcoll/beam_elements/{collimators_src → elements_src}/black_crystal.h +20 -2
  8. xcoll/beam_elements/elements_src/blowup.h +42 -0
  9. xcoll/beam_elements/elements_src/emittance_monitor.h +109 -0
  10. xcoll/beam_elements/{collimators_src → elements_src}/everest_block.h +19 -2
  11. xcoll/beam_elements/{collimators_src → elements_src}/everest_collimator.h +19 -3
  12. xcoll/beam_elements/{collimators_src → elements_src}/everest_crystal.h +30 -9
  13. xcoll/beam_elements/everest.py +5 -6
  14. xcoll/beam_elements/monitor.py +428 -0
  15. xcoll/colldb.py +103 -74
  16. xcoll/general.py +4 -4
  17. xcoll/initial_distribution.py +18 -6
  18. xcoll/install.py +3 -1
  19. xcoll/interaction_record/interaction_record.py +126 -80
  20. xcoll/interaction_record/interaction_record_src/interaction_record.h +43 -43
  21. xcoll/line_tools.py +8 -9
  22. xcoll/lossmap.py +48 -38
  23. xcoll/scattering_routines/everest/amorphous.h +4 -11
  24. xcoll/scattering_routines/everest/channeling.h +3 -8
  25. xcoll/scattering_routines/everest/everest.h +4 -1
  26. xcoll/scattering_routines/everest/jaw.h +4 -3
  27. xcoll/scattering_routines/everest/materials.py +35 -15
  28. xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +2 -2
  29. xcoll/scattering_routines/everest/nuclear_interaction.h +1 -1
  30. xcoll/scattering_routines/everest/properties.h +6 -1
  31. xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.a +0 -0
  32. xcoll/scattering_routines/geant4/collimasim/.git +1 -0
  33. xcoll/scattering_routines/geant4/collimasim/.gitignore +12 -0
  34. xcoll/scattering_routines/geant4/collimasim/.gitmodules +3 -0
  35. xcoll/scattering_routines/geant4/collimasim/CMakeLists.txt +26 -0
  36. xcoll/scattering_routines/geant4/collimasim/README.md +21 -0
  37. xcoll/scattering_routines/geant4/collimasim/docs/Makefile +20 -0
  38. xcoll/scattering_routines/geant4/collimasim/docs/make.bat +35 -0
  39. xcoll/scattering_routines/geant4/collimasim/docs/source/collimasim.rst +10 -0
  40. xcoll/scattering_routines/geant4/collimasim/docs/source/conf.py +59 -0
  41. xcoll/scattering_routines/geant4/collimasim/docs/source/index.rst +26 -0
  42. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.appveyor.yml +37 -0
  43. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-format +19 -0
  44. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-tidy +65 -0
  45. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.cmake-format.yaml +73 -0
  46. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.git +1 -0
  47. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CODEOWNERS +9 -0
  48. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CONTRIBUTING.md +386 -0
  49. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/bug-report.yml +45 -0
  50. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/config.yml +8 -0
  51. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/dependabot.yml +16 -0
  52. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler.yml +8 -0
  53. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler_merged.yml +3 -0
  54. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/pull_request_template.md +19 -0
  55. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/ci.yml +969 -0
  56. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/configure.yml +84 -0
  57. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/format.yml +48 -0
  58. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/labeler.yml +16 -0
  59. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/pip.yml +103 -0
  60. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.gitignore +45 -0
  61. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.pre-commit-config.yaml +151 -0
  62. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.readthedocs.yml +3 -0
  63. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/CMakeLists.txt +297 -0
  64. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/LICENSE +29 -0
  65. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/MANIFEST.in +6 -0
  66. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/README.rst +180 -0
  67. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Doxyfile +23 -0
  68. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Makefile +192 -0
  69. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/_static/theme_overrides.css +11 -0
  70. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/chrono.rst +81 -0
  71. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/custom.rst +93 -0
  72. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/eigen.rst +310 -0
  73. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/functional.rst +109 -0
  74. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/index.rst +43 -0
  75. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/overview.rst +171 -0
  76. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/stl.rst +251 -0
  77. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/strings.rst +305 -0
  78. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/classes.rst +1297 -0
  79. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/embedding.rst +262 -0
  80. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/exceptions.rst +396 -0
  81. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/functions.rst +568 -0
  82. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/misc.rst +337 -0
  83. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/index.rst +13 -0
  84. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/numpy.rst +463 -0
  85. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/object.rst +286 -0
  86. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/utilities.rst +155 -0
  87. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/smart_ptrs.rst +174 -0
  88. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/basics.rst +308 -0
  89. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.py +91 -0
  90. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.rst +95 -0
  91. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/changelog.rst +2050 -0
  92. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/classes.rst +542 -0
  93. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/cmake/index.rst +8 -0
  94. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/compiling.rst +648 -0
  95. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/conf.py +381 -0
  96. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/faq.rst +343 -0
  97. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/index.rst +48 -0
  98. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/installing.rst +105 -0
  99. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/limitations.rst +72 -0
  100. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11-logo.png +0 -0
  101. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.png +0 -0
  102. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.svg +427 -0
  103. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.png +0 -0
  104. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.svg +427 -0
  105. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/reference.rst +130 -0
  106. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/release.rst +96 -0
  107. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/requirements.txt +8 -0
  108. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/upgrade.rst +548 -0
  109. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/attr.h +605 -0
  110. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/buffer_info.h +144 -0
  111. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/cast.h +1432 -0
  112. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/chrono.h +213 -0
  113. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/common.h +2 -0
  114. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/complex.h +65 -0
  115. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/class.h +709 -0
  116. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/common.h +1021 -0
  117. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/descr.h +104 -0
  118. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/init.h +346 -0
  119. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/internals.h +467 -0
  120. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h +978 -0
  121. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/typeid.h +55 -0
  122. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eigen.h +606 -0
  123. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/embed.h +284 -0
  124. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eval.h +163 -0
  125. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/functional.h +121 -0
  126. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/gil.h +193 -0
  127. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/iostream.h +275 -0
  128. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/numpy.h +1741 -0
  129. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/operators.h +163 -0
  130. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/options.h +65 -0
  131. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pybind11.h +2497 -0
  132. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pytypes.h +1879 -0
  133. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl/filesystem.h +103 -0
  134. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl.h +375 -0
  135. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl_bind.h +747 -0
  136. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/noxfile.py +88 -0
  137. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__init__.py +11 -0
  138. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__main__.py +52 -0
  139. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.py +12 -0
  140. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.pyi +6 -0
  141. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/commands.py +21 -0
  142. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/py.typed +0 -0
  143. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.py +482 -0
  144. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.pyi +63 -0
  145. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pyproject.toml +41 -0
  146. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.cfg +56 -0
  147. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.py +155 -0
  148. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/CMakeLists.txt +503 -0
  149. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/conftest.py +208 -0
  150. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/constructor_stats.h +275 -0
  151. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/cross_module_gil_utils.cpp +73 -0
  152. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/env.py +33 -0
  153. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/pytest.ini +0 -0
  154. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/test_files.py +279 -0
  155. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/pytest.ini +0 -0
  156. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/test_setuphelper.py +143 -0
  157. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/local_bindings.h +85 -0
  158. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/object.h +179 -0
  159. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_cross_module_tests.cpp +151 -0
  160. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.cpp +91 -0
  161. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.h +85 -0
  162. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pytest.ini +19 -0
  163. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/requirements.txt +12 -0
  164. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.cpp +26 -0
  165. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.py +25 -0
  166. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.cpp +216 -0
  167. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.py +163 -0
  168. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.cpp +286 -0
  169. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.py +536 -0
  170. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.cpp +107 -0
  171. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.py +248 -0
  172. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.cpp +227 -0
  173. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.py +202 -0
  174. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.cpp +84 -0
  175. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.py +210 -0
  176. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.cpp +550 -0
  177. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.py +473 -0
  178. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/CMakeLists.txt +84 -0
  179. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/embed.cpp +21 -0
  180. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +28 -0
  181. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +39 -0
  182. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +46 -0
  183. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/main.cpp +6 -0
  184. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +41 -0
  185. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +35 -0
  186. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +41 -0
  187. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/test.py +10 -0
  188. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.cpp +165 -0
  189. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.py +53 -0
  190. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.cpp +238 -0
  191. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.py +126 -0
  192. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.cpp +141 -0
  193. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.py +117 -0
  194. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.cpp +41 -0
  195. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.py +50 -0
  196. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.cpp +69 -0
  197. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.py +42 -0
  198. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.cpp +348 -0
  199. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.py +771 -0
  200. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/CMakeLists.txt +47 -0
  201. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/catch.cpp +22 -0
  202. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/external_module.cpp +23 -0
  203. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.cpp +326 -0
  204. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.py +15 -0
  205. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.cpp +148 -0
  206. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.py +272 -0
  207. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.cpp +119 -0
  208. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.py +51 -0
  209. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval_call.py +5 -0
  210. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.cpp +285 -0
  211. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.h +12 -0
  212. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.py +265 -0
  213. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.cpp +397 -0
  214. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.py +520 -0
  215. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.cpp +49 -0
  216. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.py +94 -0
  217. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.cpp +125 -0
  218. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.py +331 -0
  219. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.cpp +153 -0
  220. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.py +284 -0
  221. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.cpp +107 -0
  222. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.py +257 -0
  223. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.cpp +412 -0
  224. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.py +517 -0
  225. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.cpp +102 -0
  226. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.py +92 -0
  227. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.cpp +233 -0
  228. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.py +360 -0
  229. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.cpp +472 -0
  230. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.py +593 -0
  231. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.cpp +524 -0
  232. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.py +441 -0
  233. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.cpp +103 -0
  234. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.py +267 -0
  235. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.cpp +73 -0
  236. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.py +59 -0
  237. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.cpp +235 -0
  238. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.py +146 -0
  239. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.cpp +189 -0
  240. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.py +82 -0
  241. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.cpp +560 -0
  242. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.py +651 -0
  243. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.cpp +500 -0
  244. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.py +253 -0
  245. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.cpp +452 -0
  246. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.py +318 -0
  247. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.cpp +342 -0
  248. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.py +291 -0
  249. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.cpp +131 -0
  250. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.py +318 -0
  251. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.cpp +144 -0
  252. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.py +29 -0
  253. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.cpp +66 -0
  254. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.py +44 -0
  255. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.cpp +22 -0
  256. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.py +9 -0
  257. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.cpp +510 -0
  258. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.py +408 -0
  259. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-numpy-scipy.supp +140 -0
  260. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-python.supp +117 -0
  261. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindCatch.cmake +70 -0
  262. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindEigen3.cmake +86 -0
  263. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindPythonLibsNew.cmake +257 -0
  264. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/check-style.sh +44 -0
  265. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/cmake_uninstall.cmake.in +23 -0
  266. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/libsize.py +39 -0
  267. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/make_changelog.py +64 -0
  268. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Common.cmake +402 -0
  269. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Config.cmake.in +233 -0
  270. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11NewTools.cmake +276 -0
  271. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Tools.cmake +214 -0
  272. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pyproject.toml +3 -0
  273. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_global.py.in +65 -0
  274. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_main.py.in +41 -0
  275. xcoll/scattering_routines/geant4/collimasim/pyproject.toml +8 -0
  276. xcoll/scattering_routines/geant4/collimasim/setup.py +144 -0
  277. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.cpp +403 -0
  278. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.hh +100 -0
  279. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.cpp +763 -0
  280. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.hh +118 -0
  281. xcoll/scattering_routines/geant4/collimasim/src/collimasim/__init__.py +8 -0
  282. xcoll/scattering_routines/geant4/collimasim/src/collimasim/bindings.cpp +63 -0
  283. xcoll/scattering_routines/geant4/collimasim/src/collimasim/pyCollimatorPass.py +142 -0
  284. xcoll/scattering_routines/geant4/collimasim/src/collimasim/xtrack_collimator.py +556 -0
  285. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/PKG-INFO +6 -0
  286. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/SOURCES.txt +24 -0
  287. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/dependency_links.txt +1 -0
  288. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/not-zip-safe +1 -0
  289. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/top_level.txt +1 -0
  290. xcoll/scattering_routines/geant4/collimasim/tests/README.md +25 -0
  291. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_forions.dat +25 -0
  292. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_new_example.dat +18 -0
  293. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_old_example.dat +68 -0
  294. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_testing.dat +15 -0
  295. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_yaml_example.yaml +110 -0
  296. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps.dat +7 -0
  297. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps_pyat_test.dat +3 -0
  298. xcoll/scattering_routines/geant4/collimasim/tests/resources/collonly_twiss_file_example.tfs +54 -0
  299. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings.gmad +3 -0
  300. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_black_absorber.gmad +3 -0
  301. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_ions.gmad +5 -0
  302. xcoll/scattering_routines/geant4/collimasim/tests/resources/twiss_file_testing.tfs +51 -0
  303. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat.py +65 -0
  304. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_passmethod.py +59 -0
  305. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_tracking.py +102 -0
  306. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack.py +75 -0
  307. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_angle.py +74 -0
  308. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_colldb_load.py +84 -0
  309. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction.py +159 -0
  310. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction_ion.py +99 -0
  311. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_ions.py +78 -0
  312. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_lost_energy.py +88 -0
  313. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tilt.py +80 -0
  314. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking.py +97 -0
  315. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking_ions.py +96 -0
  316. xcoll/scattering_routines/geometry/collimator_geometry.h +9 -10
  317. xcoll/scattering_routines/geometry/crystal_geometry.h +9 -6
  318. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/METADATA +1 -1
  319. xcoll-0.5.0.dist-info/RECORD +413 -0
  320. xcoll/scattering_routines/fluka/build_fluka_input.py +0 -58
  321. xcoll-0.4.0.dist-info/RECORD +0 -126
  322. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/LICENSE +0 -0
  323. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/NOTICE +0 -0
  324. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,47 @@
1
+ possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID)
2
+
3
+ if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy")
4
+ message(STATUS "Skipping embed test on PyPy")
5
+ add_custom_target(cpptest) # Dummy target on PyPy. Embedding is not supported.
6
+ set(_suppress_unused_variable_warning "${DOWNLOAD_CATCH}")
7
+ return()
8
+ endif()
9
+
10
+ find_package(Catch 2.13.2)
11
+
12
+ if(CATCH_FOUND)
13
+ message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}")
14
+ else()
15
+ message(STATUS "Catch not detected. Interpreter tests will be skipped. Install Catch headers"
16
+ " manually or use `cmake -DDOWNLOAD_CATCH=ON` to fetch them automatically.")
17
+ return()
18
+ endif()
19
+
20
+ find_package(Threads REQUIRED)
21
+
22
+ add_executable(test_embed catch.cpp test_interpreter.cpp)
23
+ pybind11_enable_warnings(test_embed)
24
+
25
+ target_link_libraries(test_embed PRIVATE pybind11::embed Catch2::Catch2 Threads::Threads)
26
+
27
+ if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
28
+ file(COPY test_interpreter.py DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
29
+ endif()
30
+
31
+ add_custom_target(
32
+ cpptest
33
+ COMMAND "$<TARGET_FILE:test_embed>"
34
+ DEPENDS test_embed
35
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
36
+
37
+ pybind11_add_module(external_module THIN_LTO external_module.cpp)
38
+ set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY
39
+ "${CMAKE_CURRENT_BINARY_DIR}")
40
+ foreach(config ${CMAKE_CONFIGURATION_TYPES})
41
+ string(TOUPPER ${config} config)
42
+ set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config}
43
+ "${CMAKE_CURRENT_BINARY_DIR}")
44
+ endforeach()
45
+ add_dependencies(cpptest external_module)
46
+
47
+ add_dependencies(check cpptest)
@@ -0,0 +1,22 @@
1
+ // The Catch implementation is compiled here. This is a standalone
2
+ // translation unit to avoid recompiling it for every test change.
3
+
4
+ #include <pybind11/embed.h>
5
+
6
+ #ifdef _MSC_VER
7
+ // Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to catch
8
+ // 2.0.1; this should be fixed in the next catch release after 2.0.1).
9
+ # pragma warning(disable: 4996)
10
+ #endif
11
+
12
+ #define CATCH_CONFIG_RUNNER
13
+ #include <catch.hpp>
14
+
15
+ namespace py = pybind11;
16
+
17
+ int main(int argc, char *argv[]) {
18
+ py::scoped_interpreter guard{};
19
+ auto result = Catch::Session().run(argc, argv);
20
+
21
+ return result < 0xff ? result : 0xff;
22
+ }
@@ -0,0 +1,23 @@
1
+ #include <pybind11/pybind11.h>
2
+
3
+ namespace py = pybind11;
4
+
5
+ /* Simple test module/test class to check that the referenced internals data of external pybind11
6
+ * modules aren't preserved over a finalize/initialize.
7
+ */
8
+
9
+ PYBIND11_MODULE(external_module, m) {
10
+ class A {
11
+ public:
12
+ explicit A(int value) : v{value} {};
13
+ int v;
14
+ };
15
+
16
+ py::class_<A>(m, "A")
17
+ .def(py::init<int>())
18
+ .def_readwrite("value", &A::v);
19
+
20
+ m.def("internals_at", []() {
21
+ return reinterpret_cast<uintptr_t>(&py::detail::get_internals());
22
+ });
23
+ }
@@ -0,0 +1,326 @@
1
+ #include <pybind11/embed.h>
2
+
3
+ #ifdef _MSC_VER
4
+ // Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to catch
5
+ // 2.0.1; this should be fixed in the next catch release after 2.0.1).
6
+ # pragma warning(disable: 4996)
7
+ #endif
8
+
9
+ #include <catch.hpp>
10
+
11
+ #include <cstdlib>
12
+ #include <fstream>
13
+ #include <functional>
14
+ #include <thread>
15
+ #include <utility>
16
+
17
+ namespace py = pybind11;
18
+ using namespace py::literals;
19
+
20
+ class Widget {
21
+ public:
22
+ explicit Widget(std::string message) : message(std::move(message)) {}
23
+ virtual ~Widget() = default;
24
+
25
+ std::string the_message() const { return message; }
26
+ virtual int the_answer() const = 0;
27
+ virtual std::string argv0() const = 0;
28
+
29
+ private:
30
+ std::string message;
31
+ };
32
+
33
+ class PyWidget final : public Widget {
34
+ using Widget::Widget;
35
+
36
+ int the_answer() const override { PYBIND11_OVERRIDE_PURE(int, Widget, the_answer); }
37
+ std::string argv0() const override { PYBIND11_OVERRIDE_PURE(std::string, Widget, argv0); }
38
+ };
39
+
40
+ PYBIND11_EMBEDDED_MODULE(widget_module, m) {
41
+ py::class_<Widget, PyWidget>(m, "Widget")
42
+ .def(py::init<std::string>())
43
+ .def_property_readonly("the_message", &Widget::the_message);
44
+
45
+ m.def("add", [](int i, int j) { return i + j; });
46
+ }
47
+
48
+ PYBIND11_EMBEDDED_MODULE(throw_exception, ) {
49
+ throw std::runtime_error("C++ Error");
50
+ }
51
+
52
+ PYBIND11_EMBEDDED_MODULE(throw_error_already_set, ) {
53
+ auto d = py::dict();
54
+ d["missing"].cast<py::object>();
55
+ }
56
+
57
+ TEST_CASE("Pass classes and data between modules defined in C++ and Python") {
58
+ auto module_ = py::module_::import("test_interpreter");
59
+ REQUIRE(py::hasattr(module_, "DerivedWidget"));
60
+
61
+ auto locals = py::dict("hello"_a="Hello, World!", "x"_a=5, **module_.attr("__dict__"));
62
+ py::exec(R"(
63
+ widget = DerivedWidget("{} - {}".format(hello, x))
64
+ message = widget.the_message
65
+ )", py::globals(), locals);
66
+ REQUIRE(locals["message"].cast<std::string>() == "Hello, World! - 5");
67
+
68
+ auto py_widget = module_.attr("DerivedWidget")("The question");
69
+ auto message = py_widget.attr("the_message");
70
+ REQUIRE(message.cast<std::string>() == "The question");
71
+
72
+ const auto &cpp_widget = py_widget.cast<const Widget &>();
73
+ REQUIRE(cpp_widget.the_answer() == 42);
74
+ }
75
+
76
+ TEST_CASE("Import error handling") {
77
+ REQUIRE_NOTHROW(py::module_::import("widget_module"));
78
+ REQUIRE_THROWS_WITH(py::module_::import("throw_exception"),
79
+ "ImportError: C++ Error");
80
+ #if PY_VERSION_HEX >= 0x03030000
81
+ REQUIRE_THROWS_WITH(py::module_::import("throw_error_already_set"),
82
+ Catch::Contains("ImportError: initialization failed"));
83
+
84
+ auto locals = py::dict("is_keyerror"_a=false, "message"_a="not set");
85
+ py::exec(R"(
86
+ try:
87
+ import throw_error_already_set
88
+ except ImportError as e:
89
+ is_keyerror = type(e.__cause__) == KeyError
90
+ message = str(e.__cause__)
91
+ )", py::globals(), locals);
92
+ REQUIRE(locals["is_keyerror"].cast<bool>() == true);
93
+ REQUIRE(locals["message"].cast<std::string>() == "'missing'");
94
+ #else
95
+ REQUIRE_THROWS_WITH(py::module_::import("throw_error_already_set"),
96
+ Catch::Contains("ImportError: KeyError"));
97
+ #endif
98
+ }
99
+
100
+ TEST_CASE("There can be only one interpreter") {
101
+ static_assert(std::is_move_constructible<py::scoped_interpreter>::value, "");
102
+ static_assert(!std::is_move_assignable<py::scoped_interpreter>::value, "");
103
+ static_assert(!std::is_copy_constructible<py::scoped_interpreter>::value, "");
104
+ static_assert(!std::is_copy_assignable<py::scoped_interpreter>::value, "");
105
+
106
+ REQUIRE_THROWS_WITH(py::initialize_interpreter(), "The interpreter is already running");
107
+ REQUIRE_THROWS_WITH(py::scoped_interpreter(), "The interpreter is already running");
108
+
109
+ py::finalize_interpreter();
110
+ REQUIRE_NOTHROW(py::scoped_interpreter());
111
+ {
112
+ auto pyi1 = py::scoped_interpreter();
113
+ auto pyi2 = std::move(pyi1);
114
+ }
115
+ py::initialize_interpreter();
116
+ }
117
+
118
+ bool has_pybind11_internals_builtin() {
119
+ auto builtins = py::handle(PyEval_GetBuiltins());
120
+ return builtins.contains(PYBIND11_INTERNALS_ID);
121
+ };
122
+
123
+ bool has_pybind11_internals_static() {
124
+ auto **&ipp = py::detail::get_internals_pp();
125
+ return (ipp != nullptr) && (*ipp != nullptr);
126
+ }
127
+
128
+ TEST_CASE("Restart the interpreter") {
129
+ // Verify pre-restart state.
130
+ REQUIRE(py::module_::import("widget_module").attr("add")(1, 2).cast<int>() == 3);
131
+ REQUIRE(has_pybind11_internals_builtin());
132
+ REQUIRE(has_pybind11_internals_static());
133
+ REQUIRE(py::module_::import("external_module").attr("A")(123).attr("value").cast<int>() == 123);
134
+
135
+ // local and foreign module internals should point to the same internals:
136
+ REQUIRE(reinterpret_cast<uintptr_t>(*py::detail::get_internals_pp()) ==
137
+ py::module_::import("external_module").attr("internals_at")().cast<uintptr_t>());
138
+
139
+ // Restart the interpreter.
140
+ py::finalize_interpreter();
141
+ REQUIRE(Py_IsInitialized() == 0);
142
+
143
+ py::initialize_interpreter();
144
+ REQUIRE(Py_IsInitialized() == 1);
145
+
146
+ // Internals are deleted after a restart.
147
+ REQUIRE_FALSE(has_pybind11_internals_builtin());
148
+ REQUIRE_FALSE(has_pybind11_internals_static());
149
+ pybind11::detail::get_internals();
150
+ REQUIRE(has_pybind11_internals_builtin());
151
+ REQUIRE(has_pybind11_internals_static());
152
+ REQUIRE(reinterpret_cast<uintptr_t>(*py::detail::get_internals_pp()) ==
153
+ py::module_::import("external_module").attr("internals_at")().cast<uintptr_t>());
154
+
155
+ // Make sure that an interpreter with no get_internals() created until finalize still gets the
156
+ // internals destroyed
157
+ py::finalize_interpreter();
158
+ py::initialize_interpreter();
159
+ bool ran = false;
160
+ py::module_::import("__main__").attr("internals_destroy_test") =
161
+ py::capsule(&ran, [](void *ran) { py::detail::get_internals(); *static_cast<bool *>(ran) = true; });
162
+ REQUIRE_FALSE(has_pybind11_internals_builtin());
163
+ REQUIRE_FALSE(has_pybind11_internals_static());
164
+ REQUIRE_FALSE(ran);
165
+ py::finalize_interpreter();
166
+ REQUIRE(ran);
167
+ py::initialize_interpreter();
168
+ REQUIRE_FALSE(has_pybind11_internals_builtin());
169
+ REQUIRE_FALSE(has_pybind11_internals_static());
170
+
171
+ // C++ modules can be reloaded.
172
+ auto cpp_module = py::module_::import("widget_module");
173
+ REQUIRE(cpp_module.attr("add")(1, 2).cast<int>() == 3);
174
+
175
+ // C++ type information is reloaded and can be used in python modules.
176
+ auto py_module = py::module_::import("test_interpreter");
177
+ auto py_widget = py_module.attr("DerivedWidget")("Hello after restart");
178
+ REQUIRE(py_widget.attr("the_message").cast<std::string>() == "Hello after restart");
179
+ }
180
+
181
+ TEST_CASE("Subinterpreter") {
182
+ // Add tags to the modules in the main interpreter and test the basics.
183
+ py::module_::import("__main__").attr("main_tag") = "main interpreter";
184
+ {
185
+ auto m = py::module_::import("widget_module");
186
+ m.attr("extension_module_tag") = "added to module in main interpreter";
187
+
188
+ REQUIRE(m.attr("add")(1, 2).cast<int>() == 3);
189
+ }
190
+ REQUIRE(has_pybind11_internals_builtin());
191
+ REQUIRE(has_pybind11_internals_static());
192
+
193
+ /// Create and switch to a subinterpreter.
194
+ auto main_tstate = PyThreadState_Get();
195
+ auto sub_tstate = Py_NewInterpreter();
196
+
197
+ // Subinterpreters get their own copy of builtins. detail::get_internals() still
198
+ // works by returning from the static variable, i.e. all interpreters share a single
199
+ // global pybind11::internals;
200
+ REQUIRE_FALSE(has_pybind11_internals_builtin());
201
+ REQUIRE(has_pybind11_internals_static());
202
+
203
+ // Modules tags should be gone.
204
+ REQUIRE_FALSE(py::hasattr(py::module_::import("__main__"), "tag"));
205
+ {
206
+ auto m = py::module_::import("widget_module");
207
+ REQUIRE_FALSE(py::hasattr(m, "extension_module_tag"));
208
+
209
+ // Function bindings should still work.
210
+ REQUIRE(m.attr("add")(1, 2).cast<int>() == 3);
211
+ }
212
+
213
+ // Restore main interpreter.
214
+ Py_EndInterpreter(sub_tstate);
215
+ PyThreadState_Swap(main_tstate);
216
+
217
+ REQUIRE(py::hasattr(py::module_::import("__main__"), "main_tag"));
218
+ REQUIRE(py::hasattr(py::module_::import("widget_module"), "extension_module_tag"));
219
+ }
220
+
221
+ TEST_CASE("Execution frame") {
222
+ // When the interpreter is embedded, there is no execution frame, but `py::exec`
223
+ // should still function by using reasonable globals: `__main__.__dict__`.
224
+ py::exec("var = dict(number=42)");
225
+ REQUIRE(py::globals()["var"]["number"].cast<int>() == 42);
226
+ }
227
+
228
+ TEST_CASE("Threads") {
229
+ // Restart interpreter to ensure threads are not initialized
230
+ py::finalize_interpreter();
231
+ py::initialize_interpreter();
232
+ REQUIRE_FALSE(has_pybind11_internals_static());
233
+
234
+ constexpr auto num_threads = 10;
235
+ auto locals = py::dict("count"_a=0);
236
+
237
+ {
238
+ py::gil_scoped_release gil_release{};
239
+ REQUIRE(has_pybind11_internals_static());
240
+
241
+ auto threads = std::vector<std::thread>();
242
+ for (auto i = 0; i < num_threads; ++i) {
243
+ threads.emplace_back([&]() {
244
+ py::gil_scoped_acquire gil{};
245
+ locals["count"] = locals["count"].cast<int>() + 1;
246
+ });
247
+ }
248
+
249
+ for (auto &thread : threads) {
250
+ thread.join();
251
+ }
252
+ }
253
+
254
+ REQUIRE(locals["count"].cast<int>() == num_threads);
255
+ }
256
+
257
+ // Scope exit utility https://stackoverflow.com/a/36644501/7255855
258
+ struct scope_exit {
259
+ std::function<void()> f_;
260
+ explicit scope_exit(std::function<void()> f) noexcept : f_(std::move(f)) {}
261
+ ~scope_exit() { if (f_) f_(); }
262
+ };
263
+
264
+ TEST_CASE("Reload module from file") {
265
+ // Disable generation of cached bytecode (.pyc files) for this test, otherwise
266
+ // Python might pick up an old version from the cache instead of the new versions
267
+ // of the .py files generated below
268
+ auto sys = py::module_::import("sys");
269
+ bool dont_write_bytecode = sys.attr("dont_write_bytecode").cast<bool>();
270
+ sys.attr("dont_write_bytecode") = true;
271
+ // Reset the value at scope exit
272
+ scope_exit reset_dont_write_bytecode([&]() {
273
+ sys.attr("dont_write_bytecode") = dont_write_bytecode;
274
+ });
275
+
276
+ std::string module_name = "test_module_reload";
277
+ std::string module_file = module_name + ".py";
278
+
279
+ // Create the module .py file
280
+ std::ofstream test_module(module_file);
281
+ test_module << "def test():\n";
282
+ test_module << " return 1\n";
283
+ test_module.close();
284
+ // Delete the file at scope exit
285
+ scope_exit delete_module_file([&]() {
286
+ std::remove(module_file.c_str());
287
+ });
288
+
289
+ // Import the module from file
290
+ auto module_ = py::module_::import(module_name.c_str());
291
+ int result = module_.attr("test")().cast<int>();
292
+ REQUIRE(result == 1);
293
+
294
+ // Update the module .py file with a small change
295
+ test_module.open(module_file);
296
+ test_module << "def test():\n";
297
+ test_module << " return 2\n";
298
+ test_module.close();
299
+
300
+ // Reload the module
301
+ module_.reload();
302
+ result = module_.attr("test")().cast<int>();
303
+ REQUIRE(result == 2);
304
+ }
305
+
306
+ TEST_CASE("sys.argv gets initialized properly") {
307
+ py::finalize_interpreter();
308
+ {
309
+ py::scoped_interpreter default_scope;
310
+ auto module = py::module::import("test_interpreter");
311
+ auto py_widget = module.attr("DerivedWidget")("The question");
312
+ const auto &cpp_widget = py_widget.cast<const Widget &>();
313
+ REQUIRE(cpp_widget.argv0().empty());
314
+ }
315
+
316
+ {
317
+ char *argv[] = {strdup("a.out")};
318
+ py::scoped_interpreter argv_scope(true, 1, argv);
319
+ std::free(argv[0]);
320
+ auto module = py::module::import("test_interpreter");
321
+ auto py_widget = module.attr("DerivedWidget")("The question");
322
+ const auto &cpp_widget = py_widget.cast<const Widget &>();
323
+ REQUIRE(cpp_widget.argv0() == "a.out");
324
+ }
325
+ py::initialize_interpreter();
326
+ }
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ import sys
3
+
4
+ from widget_module import Widget
5
+
6
+
7
+ class DerivedWidget(Widget):
8
+ def __init__(self, message):
9
+ super(DerivedWidget, self).__init__(message)
10
+
11
+ def the_answer(self):
12
+ return 42
13
+
14
+ def argv0(self):
15
+ return sys.argv[0]
@@ -0,0 +1,148 @@
1
+ /*
2
+ tests/test_enums.cpp -- enumerations
3
+
4
+ Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
5
+
6
+ All rights reserved. Use of this source code is governed by a
7
+ BSD-style license that can be found in the LICENSE file.
8
+ */
9
+
10
+ #include "pybind11_tests.h"
11
+
12
+ TEST_SUBMODULE(enums, m) {
13
+ // test_unscoped_enum
14
+ enum UnscopedEnum {
15
+ EOne = 1,
16
+ ETwo,
17
+ EThree
18
+ };
19
+ py::enum_<UnscopedEnum>(m, "UnscopedEnum", py::arithmetic(), "An unscoped enumeration")
20
+ .value("EOne", EOne, "Docstring for EOne")
21
+ .value("ETwo", ETwo, "Docstring for ETwo")
22
+ .value("EThree", EThree, "Docstring for EThree")
23
+ .export_values();
24
+
25
+ // test_scoped_enum
26
+ enum class ScopedEnum {
27
+ Two = 2,
28
+ Three
29
+ };
30
+ py::enum_<ScopedEnum>(m, "ScopedEnum", py::arithmetic())
31
+ .value("Two", ScopedEnum::Two)
32
+ .value("Three", ScopedEnum::Three);
33
+
34
+ m.def("test_scoped_enum", [](ScopedEnum z) {
35
+ return "ScopedEnum::" + std::string(z == ScopedEnum::Two ? "Two" : "Three");
36
+ });
37
+
38
+ // test_binary_operators
39
+ enum Flags {
40
+ Read = 4,
41
+ Write = 2,
42
+ Execute = 1
43
+ };
44
+ py::enum_<Flags>(m, "Flags", py::arithmetic())
45
+ .value("Read", Flags::Read)
46
+ .value("Write", Flags::Write)
47
+ .value("Execute", Flags::Execute)
48
+ .export_values();
49
+
50
+ // test_implicit_conversion
51
+ class ClassWithUnscopedEnum {
52
+ public:
53
+ enum EMode {
54
+ EFirstMode = 1,
55
+ ESecondMode
56
+ };
57
+
58
+ static EMode test_function(EMode mode) {
59
+ return mode;
60
+ }
61
+ };
62
+ py::class_<ClassWithUnscopedEnum> exenum_class(m, "ClassWithUnscopedEnum");
63
+ exenum_class.def_static("test_function", &ClassWithUnscopedEnum::test_function);
64
+ py::enum_<ClassWithUnscopedEnum::EMode>(exenum_class, "EMode")
65
+ .value("EFirstMode", ClassWithUnscopedEnum::EFirstMode)
66
+ .value("ESecondMode", ClassWithUnscopedEnum::ESecondMode)
67
+ .export_values();
68
+
69
+ // test_enum_to_int
70
+ m.def("test_enum_to_int", [](int) { });
71
+ m.def("test_enum_to_uint", [](uint32_t) { });
72
+ m.def("test_enum_to_long_long", [](long long) { });
73
+
74
+ // test_duplicate_enum_name
75
+ enum SimpleEnum
76
+ {
77
+ ONE, TWO, THREE
78
+ };
79
+
80
+ m.def("register_bad_enum", [m]() {
81
+ py::enum_<SimpleEnum>(m, "SimpleEnum")
82
+ .value("ONE", SimpleEnum::ONE) //NOTE: all value function calls are called with the same first parameter value
83
+ .value("ONE", SimpleEnum::TWO)
84
+ .value("ONE", SimpleEnum::THREE)
85
+ .export_values();
86
+ });
87
+
88
+ // test_enum_scalar
89
+ enum UnscopedUCharEnum : unsigned char {};
90
+ enum class ScopedShortEnum : short {};
91
+ enum class ScopedLongEnum : long {};
92
+ enum UnscopedUInt64Enum : std::uint64_t {};
93
+ static_assert(py::detail::all_of<
94
+ std::is_same<py::enum_<UnscopedUCharEnum>::Scalar, unsigned char>,
95
+ std::is_same<py::enum_<ScopedShortEnum>::Scalar, short>,
96
+ std::is_same<py::enum_<ScopedLongEnum>::Scalar, long>,
97
+ std::is_same<py::enum_<UnscopedUInt64Enum>::Scalar, std::uint64_t>
98
+ >::value, "Error during the deduction of enum's scalar type with normal integer underlying");
99
+
100
+ // test_enum_scalar_with_char_underlying
101
+ enum class ScopedCharEnum : char { Zero, Positive };
102
+ enum class ScopedWCharEnum : wchar_t { Zero, Positive };
103
+ enum class ScopedChar32Enum : char32_t { Zero, Positive };
104
+ enum class ScopedChar16Enum : char16_t { Zero, Positive };
105
+
106
+ // test the scalar of char type enums according to chapter 'Character types'
107
+ // from https://en.cppreference.com/w/cpp/language/types
108
+ static_assert(py::detail::any_of<
109
+ std::is_same<py::enum_<ScopedCharEnum>::Scalar, signed char>, // e.g. gcc on x86
110
+ std::is_same<py::enum_<ScopedCharEnum>::Scalar, unsigned char> // e.g. arm linux
111
+ >::value, "char should be cast to either signed char or unsigned char");
112
+ static_assert(
113
+ sizeof(py::enum_<ScopedWCharEnum>::Scalar) == 2 ||
114
+ sizeof(py::enum_<ScopedWCharEnum>::Scalar) == 4
115
+ , "wchar_t should be either 16 bits (Windows) or 32 (everywhere else)");
116
+ static_assert(py::detail::all_of<
117
+ std::is_same<py::enum_<ScopedChar32Enum>::Scalar, std::uint_least32_t>,
118
+ std::is_same<py::enum_<ScopedChar16Enum>::Scalar, std::uint_least16_t>
119
+ >::value, "char32_t, char16_t (and char8_t)'s size, signedness, and alignment is determined");
120
+ #if defined(PYBIND11_HAS_U8STRING)
121
+ enum class ScopedChar8Enum : char8_t { Zero, Positive };
122
+ static_assert(std::is_same<py::enum_<ScopedChar8Enum>::Scalar, unsigned char>::value);
123
+ #endif
124
+
125
+ // test_char_underlying_enum
126
+ py::enum_<ScopedCharEnum>(m, "ScopedCharEnum")
127
+ .value("Zero", ScopedCharEnum::Zero)
128
+ .value("Positive", ScopedCharEnum::Positive);
129
+ py::enum_<ScopedWCharEnum>(m, "ScopedWCharEnum")
130
+ .value("Zero", ScopedWCharEnum::Zero)
131
+ .value("Positive", ScopedWCharEnum::Positive);
132
+ py::enum_<ScopedChar32Enum>(m, "ScopedChar32Enum")
133
+ .value("Zero", ScopedChar32Enum::Zero)
134
+ .value("Positive", ScopedChar32Enum::Positive);
135
+ py::enum_<ScopedChar16Enum>(m, "ScopedChar16Enum")
136
+ .value("Zero", ScopedChar16Enum::Zero)
137
+ .value("Positive", ScopedChar16Enum::Positive);
138
+
139
+ // test_bool_underlying_enum
140
+ enum class ScopedBoolEnum : bool { FALSE, TRUE };
141
+
142
+ // bool is unsigned (std::is_signed returns false) and 1-byte long, so represented with u8
143
+ static_assert(std::is_same<py::enum_<ScopedBoolEnum>::Scalar, std::uint8_t>::value, "");
144
+
145
+ py::enum_<ScopedBoolEnum>(m, "ScopedBoolEnum")
146
+ .value("FALSE", ScopedBoolEnum::FALSE)
147
+ .value("TRUE", ScopedBoolEnum::TRUE);
148
+ }