pyxcp 0.18.48__tar.gz → 0.25.8__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 (229) hide show
  1. pyxcp-0.25.8/CMakeLists.txt +130 -0
  2. pyxcp-0.25.8/PKG-INFO +341 -0
  3. pyxcp-0.25.8/build_ext.py +160 -0
  4. pyxcp-0.25.8/docs/README.rst +300 -0
  5. pyxcp-0.25.8/pyproject.toml +216 -0
  6. pyxcp-0.25.8/pyxcp/__init__.py +20 -0
  7. pyxcp-0.25.8/pyxcp/aml/EtasCANMonitoring.a2l +82 -0
  8. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/aml/XCP_Common.aml +0 -1
  9. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/aml/XCPonUSB.aml +1 -1
  10. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/aml/ifdata_CAN.a2l +0 -1
  11. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/aml/ifdata_Eth.a2l +0 -1
  12. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/aml/ifdata_Flx.a2l +0 -1
  13. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/aml/ifdata_SxI.a2l +0 -1
  14. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/aml/ifdata_USB.a2l +0 -1
  15. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/asam/types.py +4 -4
  16. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/asamkeydll.c +2 -25
  17. pyxcp-0.25.8/pyxcp/asamkeydll.sh +2 -0
  18. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/checksum.py +15 -6
  19. pyxcp-0.25.8/pyxcp/cmdline.py +69 -0
  20. pyxcp-0.25.8/pyxcp/config/__init__.py +1257 -0
  21. pyxcp-0.25.8/pyxcp/config/legacy.py +120 -0
  22. pyxcp-0.25.8/pyxcp/constants.py +47 -0
  23. pyxcp-0.25.8/pyxcp/cpp_ext/aligned_buffer.hpp +168 -0
  24. pyxcp-0.25.8/pyxcp/cpp_ext/bin.hpp +105 -0
  25. pyxcp-0.25.8/pyxcp/cpp_ext/blockmem.hpp +58 -0
  26. pyxcp-0.25.8/pyxcp/cpp_ext/daqlist.hpp +374 -0
  27. pyxcp-0.25.8/pyxcp/cpp_ext/event.hpp +67 -0
  28. pyxcp-0.25.8/pyxcp/cpp_ext/extension_wrapper.cpp +208 -0
  29. pyxcp-0.25.8/pyxcp/cpp_ext/framing.hpp +360 -0
  30. pyxcp-0.25.8/pyxcp/cpp_ext/helper.hpp +280 -0
  31. pyxcp-0.25.8/pyxcp/cpp_ext/mcobject.hpp +248 -0
  32. pyxcp-0.25.8/pyxcp/cpp_ext/sxi_framing.hpp +332 -0
  33. pyxcp-0.25.8/pyxcp/cpp_ext/tsqueue.hpp +46 -0
  34. pyxcp-0.25.8/pyxcp/daq_stim/__init__.py +369 -0
  35. pyxcp-0.25.8/pyxcp/daq_stim/optimize/__init__.py +67 -0
  36. pyxcp-0.25.8/pyxcp/daq_stim/optimize/binpacking.py +41 -0
  37. pyxcp-0.25.8/pyxcp/daq_stim/scheduler.cpp +62 -0
  38. pyxcp-0.25.8/pyxcp/daq_stim/scheduler.hpp +75 -0
  39. pyxcp-0.25.8/pyxcp/daq_stim/stim.cpp +13 -0
  40. pyxcp-0.25.8/pyxcp/daq_stim/stim.hpp +604 -0
  41. pyxcp-0.25.8/pyxcp/daq_stim/stim_wrapper.cpp +50 -0
  42. pyxcp-0.25.8/pyxcp/dllif.py +100 -0
  43. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/errormatrix.py +8 -5
  44. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/examples/conf_can.toml +4 -2
  45. pyxcp-0.25.8/pyxcp/examples/conf_can_vector.json +11 -0
  46. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/examples/conf_can_vector.toml +4 -2
  47. pyxcp-0.25.8/pyxcp/examples/conf_eth.toml +9 -0
  48. pyxcp-0.25.8/pyxcp/examples/conf_nixnet.json +20 -0
  49. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/examples/conf_socket_can.toml +1 -1
  50. pyxcp-0.25.8/pyxcp/examples/run_daq.py +165 -0
  51. pyxcp-0.25.8/pyxcp/examples/xcp_policy.py +60 -0
  52. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/examples/xcp_read_benchmark.py +10 -8
  53. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/examples/xcp_skel.py +3 -6
  54. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/examples/xcp_unlock.py +10 -12
  55. pyxcp-0.25.8/pyxcp/examples/xcp_user_supplied_driver.py +43 -0
  56. pyxcp-0.25.8/pyxcp/examples/xcphello.py +65 -0
  57. pyxcp-0.25.8/pyxcp/examples/xcphello_recorder.py +107 -0
  58. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/master/__init__.py +2 -2
  59. pyxcp-0.25.8/pyxcp/master/errorhandler.py +677 -0
  60. pyxcp-0.25.8/pyxcp/master/master.py +2635 -0
  61. pyxcp-0.25.8/pyxcp/recorder/.idea/.gitignore +8 -0
  62. pyxcp-0.25.8/pyxcp/recorder/.idea/misc.xml +4 -0
  63. pyxcp-0.25.8/pyxcp/recorder/.idea/modules.xml +8 -0
  64. pyxcp-0.25.8/pyxcp/recorder/.idea/recorder.iml +6 -0
  65. pyxcp-0.25.8/pyxcp/recorder/.idea/sonarlint/issuestore/3/8/3808afc69ac1edb9d760000a2f137335b1b99728 +7 -0
  66. pyxcp-0.25.8/pyxcp/recorder/.idea/sonarlint/issuestore/9/a/9a2aa4db38d3115ed60da621e012c0efc0172aae +0 -0
  67. pyxcp-0.25.8/pyxcp/recorder/.idea/sonarlint/issuestore/b/4/b49006702b459496a8e8c94ebe60947108361b91 +0 -0
  68. pyxcp-0.25.8/pyxcp/recorder/.idea/sonarlint/issuestore/index.pb +7 -0
  69. pyxcp-0.25.8/pyxcp/recorder/.idea/sonarlint/securityhotspotstore/3/8/3808afc69ac1edb9d760000a2f137335b1b99728 +0 -0
  70. pyxcp-0.25.8/pyxcp/recorder/.idea/sonarlint/securityhotspotstore/9/a/9a2aa4db38d3115ed60da621e012c0efc0172aae +0 -0
  71. pyxcp-0.25.8/pyxcp/recorder/.idea/sonarlint/securityhotspotstore/b/4/b49006702b459496a8e8c94ebe60947108361b91 +0 -0
  72. pyxcp-0.25.8/pyxcp/recorder/.idea/sonarlint/securityhotspotstore/index.pb +7 -0
  73. pyxcp-0.25.8/pyxcp/recorder/.idea/vcs.xml +10 -0
  74. pyxcp-0.25.8/pyxcp/recorder/__init__.py +96 -0
  75. pyxcp-0.25.8/pyxcp/recorder/build_clang.cmd +1 -0
  76. pyxcp-0.25.8/pyxcp/recorder/build_clang.sh +2 -0
  77. pyxcp-0.25.8/pyxcp/recorder/build_gcc.cmd +1 -0
  78. pyxcp-0.25.8/pyxcp/recorder/build_gcc.sh +2 -0
  79. pyxcp-0.25.8/pyxcp/recorder/build_gcc_arm.sh +2 -0
  80. pyxcp-0.25.8/pyxcp/recorder/converter/__init__.py +444 -0
  81. pyxcp-0.18.48/pyxcp/recorder/lz4.cpp → pyxcp-0.25.8/pyxcp/recorder/lz4.c +606 -272
  82. pyxcp-0.25.8/pyxcp/recorder/lz4.h +879 -0
  83. pyxcp-0.25.8/pyxcp/recorder/lz4hc.c +2041 -0
  84. pyxcp-0.25.8/pyxcp/recorder/lz4hc.h +413 -0
  85. pyxcp-0.25.8/pyxcp/recorder/mio.hpp +1714 -0
  86. pyxcp-0.25.8/pyxcp/recorder/reader.hpp +138 -0
  87. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/recorder/reco.py +6 -8
  88. pyxcp-0.25.8/pyxcp/recorder/recorder.rst +0 -0
  89. pyxcp-0.25.8/pyxcp/recorder/rekorder.cpp +59 -0
  90. pyxcp-0.25.8/pyxcp/recorder/rekorder.hpp +274 -0
  91. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/recorder/setup.py +12 -11
  92. pyxcp-0.25.8/pyxcp/recorder/test_reko.py +34 -0
  93. pyxcp-0.25.8/pyxcp/recorder/unfolder.hpp +1354 -0
  94. pyxcp-0.25.8/pyxcp/recorder/wrap.cpp +184 -0
  95. pyxcp-0.25.8/pyxcp/recorder/writer.hpp +302 -0
  96. pyxcp-0.25.8/pyxcp/scripts/__init__.py +0 -0
  97. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/scripts/pyxcp_probe_can_drivers.py +0 -2
  98. pyxcp-0.25.8/pyxcp/scripts/xcp_daq_recorder.py +54 -0
  99. pyxcp-0.25.8/pyxcp/scripts/xcp_examples.py +64 -0
  100. pyxcp-0.25.8/pyxcp/scripts/xcp_fetch_a2l.py +40 -0
  101. pyxcp-0.25.8/pyxcp/scripts/xcp_id_scanner.py +18 -0
  102. pyxcp-0.25.8/pyxcp/scripts/xcp_info.py +159 -0
  103. pyxcp-0.25.8/pyxcp/scripts/xcp_profile.py +26 -0
  104. pyxcp-0.25.8/pyxcp/scripts/xmraw_converter.py +31 -0
  105. pyxcp-0.25.8/pyxcp/stim/__init__.py +0 -0
  106. pyxcp-0.25.8/pyxcp/tests/test_binpacking.py +186 -0
  107. pyxcp-0.25.8/pyxcp/tests/test_can.py +1324 -0
  108. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/tests/test_checksum.py +2 -1
  109. pyxcp-0.25.8/pyxcp/tests/test_daq.py +193 -0
  110. pyxcp-0.25.8/pyxcp/tests/test_daq_opt.py +426 -0
  111. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/tests/test_frame_padding.py +6 -3
  112. pyxcp-0.25.8/pyxcp/tests/test_framing.py +262 -0
  113. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/tests/test_master.py +237 -116
  114. pyxcp-0.25.8/pyxcp/tests/test_transport.py +177 -0
  115. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/tests/test_utils.py +2 -5
  116. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/timing.py +1 -3
  117. pyxcp-0.25.8/pyxcp/transport/__init__.py +13 -0
  118. pyxcp-0.25.8/pyxcp/transport/base.py +484 -0
  119. pyxcp-0.25.8/pyxcp/transport/base_transport.hpp +0 -0
  120. pyxcp-0.25.8/pyxcp/transport/can.py +660 -0
  121. pyxcp-0.25.8/pyxcp/transport/eth.py +254 -0
  122. pyxcp-0.25.8/pyxcp/transport/hdf5_policy.py +167 -0
  123. pyxcp-0.25.8/pyxcp/transport/sxi.py +209 -0
  124. pyxcp-0.25.8/pyxcp/transport/transport_ext.hpp +214 -0
  125. pyxcp-0.25.8/pyxcp/transport/transport_wrapper.cpp +249 -0
  126. pyxcp-0.25.8/pyxcp/transport/usb_transport.py +229 -0
  127. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/types.py +112 -22
  128. pyxcp-0.25.8/pyxcp/utils/__init__.py +127 -0
  129. pyxcp-0.25.8/pyxcp/utils/cli.py +78 -0
  130. pyxcp-0.25.8/pyxcp/vector/__init__.py +0 -0
  131. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/vector/map.py +1 -3
  132. pyxcp-0.18.48/.bumpversion.cfg +0 -8
  133. pyxcp-0.18.48/.codeclimate.yml +0 -45
  134. pyxcp-0.18.48/.coveralls.yml +0 -2
  135. pyxcp-0.18.48/.pdm.toml +0 -25
  136. pyxcp-0.18.48/.readthedocs.yml +0 -17
  137. pyxcp-0.18.48/CODE_OF_CONDUCT.md +0 -46
  138. pyxcp-0.18.48/CONTRIBUTORS +0 -6
  139. pyxcp-0.18.48/MANIFEST.in +0 -21
  140. pyxcp-0.18.48/PKG-INFO +0 -261
  141. pyxcp-0.18.48/README.md +0 -66
  142. pyxcp-0.18.48/appveyor.yml +0 -73
  143. pyxcp-0.18.48/docs/Makefile +0 -20
  144. pyxcp-0.18.48/docs/conf.py +0 -181
  145. pyxcp-0.18.48/docs/configuration.rst +0 -158
  146. pyxcp-0.18.48/docs/howto.rst +0 -10
  147. pyxcp-0.18.48/docs/howto_can_driver.rst +0 -3
  148. pyxcp-0.18.48/docs/howto_cli_tools.rst +0 -5
  149. pyxcp-0.18.48/docs/index.rst +0 -25
  150. pyxcp-0.18.48/docs/installation.rst +0 -13
  151. pyxcp-0.18.48/docs/modules.rst +0 -7
  152. pyxcp-0.18.48/docs/pyxcp.asam.rst +0 -30
  153. pyxcp-0.18.48/docs/pyxcp.master.rst +0 -38
  154. pyxcp-0.18.48/docs/pyxcp.rst +0 -76
  155. pyxcp-0.18.48/docs/pyxcp.transport.rst +0 -53
  156. pyxcp-0.18.48/docs/requirements.txt +0 -1
  157. pyxcp-0.18.48/docs/tutorial.rst +0 -4
  158. pyxcp-0.18.48/ls-contributors.cmd +0 -1
  159. pyxcp-0.18.48/ls-contributors.sh +0 -2
  160. pyxcp-0.18.48/pyproject.toml +0 -116
  161. pyxcp-0.18.48/pyxcp/__init__.py +0 -11
  162. pyxcp-0.18.48/pyxcp/aml/EtasCANMonitoring.a2l +0 -83
  163. pyxcp-0.18.48/pyxcp/cmdline.py +0 -67
  164. pyxcp-0.18.48/pyxcp/config.py +0 -57
  165. pyxcp-0.18.48/pyxcp/constants.py +0 -48
  166. pyxcp-0.18.48/pyxcp/dllif.py +0 -79
  167. pyxcp-0.18.48/pyxcp/examples/conf_can.json +0 -20
  168. pyxcp-0.18.48/pyxcp/examples/conf_can_vector.json +0 -11
  169. pyxcp-0.18.48/pyxcp/examples/conf_eth.json +0 -8
  170. pyxcp-0.18.48/pyxcp/examples/conf_eth.toml +0 -9
  171. pyxcp-0.18.48/pyxcp/examples/conf_sxi.json +0 -9
  172. pyxcp-0.18.48/pyxcp/examples/conf_sxi.toml +0 -7
  173. pyxcp-0.18.48/pyxcp/examples/xcp_user_supplied_driver.py +0 -55
  174. pyxcp-0.18.48/pyxcp/examples/xcphello.py +0 -50
  175. pyxcp-0.18.48/pyxcp/examples/xcptest.py +0 -661
  176. pyxcp-0.18.48/pyxcp/logger.py +0 -66
  177. pyxcp-0.18.48/pyxcp/master/errorhandler.py +0 -381
  178. pyxcp-0.18.48/pyxcp/master/master.py +0 -1805
  179. pyxcp-0.18.48/pyxcp/recorder/__init__.py +0 -6
  180. pyxcp-0.18.48/pyxcp/recorder/recorder.py +0 -74
  181. pyxcp-0.18.48/pyxcp/recorder/test_reko.py +0 -55
  182. pyxcp-0.18.48/pyxcp/recorder/wrap.cpp +0 -50
  183. pyxcp-0.18.48/pyxcp/tests/test_can.py +0 -230
  184. pyxcp-0.18.48/pyxcp/tests/test_config.py +0 -62
  185. pyxcp-0.18.48/pyxcp/tests/test_transport.py +0 -64
  186. pyxcp-0.18.48/pyxcp/transport/__init__.py +0 -6
  187. pyxcp-0.18.48/pyxcp/transport/base.py +0 -342
  188. pyxcp-0.18.48/pyxcp/transport/can.py +0 -421
  189. pyxcp-0.18.48/pyxcp/transport/candriver/__init__.py +0 -2
  190. pyxcp-0.18.48/pyxcp/transport/candriver/pc_canalystii.py +0 -27
  191. pyxcp-0.18.48/pyxcp/transport/candriver/pc_iscan.py +0 -23
  192. pyxcp-0.18.48/pyxcp/transport/candriver/pc_ixxat.py +0 -27
  193. pyxcp-0.18.48/pyxcp/transport/candriver/pc_kvaser.py +0 -39
  194. pyxcp-0.18.48/pyxcp/transport/candriver/pc_neovi.py +0 -31
  195. pyxcp-0.18.48/pyxcp/transport/candriver/pc_nican.py +0 -23
  196. pyxcp-0.18.48/pyxcp/transport/candriver/pc_pcan.py +0 -25
  197. pyxcp-0.18.48/pyxcp/transport/candriver/pc_serial.py +0 -27
  198. pyxcp-0.18.48/pyxcp/transport/candriver/pc_slcan.py +0 -29
  199. pyxcp-0.18.48/pyxcp/transport/candriver/pc_socketcan.py +0 -23
  200. pyxcp-0.18.48/pyxcp/transport/candriver/pc_systec.py +0 -29
  201. pyxcp-0.18.48/pyxcp/transport/candriver/pc_usb2can.py +0 -30
  202. pyxcp-0.18.48/pyxcp/transport/candriver/pc_vector.py +0 -33
  203. pyxcp-0.18.48/pyxcp/transport/candriver/python_can.py +0 -101
  204. pyxcp-0.18.48/pyxcp/transport/cxx_ext/setup.py +0 -49
  205. pyxcp-0.18.48/pyxcp/transport/eth.py +0 -223
  206. pyxcp-0.18.48/pyxcp/transport/sxi.py +0 -98
  207. pyxcp-0.18.48/pyxcp/transport/usb_transport.py +0 -213
  208. pyxcp-0.18.48/pyxcp/utils.py +0 -88
  209. pyxcp-0.18.48/pyxcp.egg-info/PKG-INFO +0 -261
  210. pyxcp-0.18.48/pyxcp.egg-info/SOURCES.txt +0 -126
  211. pyxcp-0.18.48/pyxcp.egg-info/dependency_links.txt +0 -1
  212. pyxcp-0.18.48/pyxcp.egg-info/entry_points.txt +0 -2
  213. pyxcp-0.18.48/pyxcp.egg-info/not-zip-safe +0 -1
  214. pyxcp-0.18.48/pyxcp.egg-info/requires.txt +0 -26
  215. pyxcp-0.18.48/pyxcp.egg-info/top_level.txt +0 -2
  216. pyxcp-0.18.48/requirements.txt +0 -10
  217. pyxcp-0.18.48/setup.cfg +0 -28
  218. pyxcp-0.18.48/setup.py +0 -153
  219. {pyxcp-0.18.48 → pyxcp-0.25.8}/LICENSE +0 -0
  220. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/aml/EtasCANMonitoring.aml +0 -0
  221. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/aml/XCPonCAN.aml +0 -0
  222. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/aml/XCPonEth.aml +0 -0
  223. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/aml/XCPonFlx.aml +0 -0
  224. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/aml/XCPonSxI.aml +0 -0
  225. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/asam/__init__.py +0 -0
  226. {pyxcp-0.18.48/pyxcp/scripts → pyxcp-0.25.8/pyxcp/cpp_ext}/__init__.py +0 -0
  227. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/examples/conf_can_user.toml +0 -0
  228. pyxcp-0.18.48/pyxcp/vector/__init__.py → pyxcp-0.25.8/pyxcp/py.typed +0 -0
  229. {pyxcp-0.18.48 → pyxcp-0.25.8}/pyxcp/tests/test_asam_types.py +2 -2
@@ -0,0 +1,130 @@
1
+
2
+ cmake_minimum_required(VERSION 3.20...3.30)
3
+ project(pyxcp_extensions LANGUAGES C CXX)
4
+
5
+
6
+ if(POLICY CMP0135)
7
+ cmake_policy(SET CMP0135 NEW)
8
+ endif()
9
+ cmake_policy(SET CMP0094 NEW)
10
+
11
+ find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)
12
+ find_package(pybind11 CONFIG)
13
+
14
+ SET(CMAKE_C_STANDARD 17)
15
+ set(CMAKE_CXX_STANDARD 23)
16
+
17
+ message( STATUS "Found pybind11 v${pybind11_VERSION} ${pybind11_VERSION_TYPE}: ${pybind11_INCLUDE_DIRS}")
18
+
19
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist")
20
+
21
+
22
+ SET(GCC_N_CLANG_BASE_OPTIONS "-std=c++23 -Wall -Wextra -Wpedantic -Warray-bounds -mtune=native -fexceptions")
23
+
24
+ SET(MSVC_BASE_OPTIONS "/W3 /permissive- /EHsc /bigobj /Zc:__cplusplus /std:c++latest")
25
+
26
+
27
+
28
+ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
29
+ if (MSVC)
30
+ SET(MSVC_BASE_OPTIONS "${MSVC_BASE_OPTIONS} /Od /fsanitize=address /Zi")
31
+ else()
32
+ SET(GCC_N_CLANG_BASE_OPTIONS "${GCC_N_CLANG_BASE_OPTIONS} -Og -g3 -ggdb -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined -fsanitize=bounds") # -fsanitize=hwaddress
33
+ endif()
34
+ else ()
35
+ if (MSVC)
36
+ SET(MSVC_BASE_OPTIONS "${MSVC_BASE_OPTIONS} /Ox")
37
+ else()
38
+ SET(GCC_N_CLANG_BASE_OPTIONS "${GCC_N_CLANG_BASE_OPTIONS} -O3 -fomit-frame-pointer")
39
+ endif()
40
+ endif ()
41
+
42
+
43
+ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
44
+ set(ENV{MACOSX_DEPLOYMENT_TARGET} "11.0")
45
+ SET(GCC_N_CLANG_EXTRA_OPTIONS "-stdlib=libc++")
46
+ message("Platform is Darwin")
47
+ elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
48
+ message("Platform is WINDOWS")
49
+ SET(MSVC_EXTRA_OPTIONS "")
50
+ elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
51
+ SET(GCC_N_CLANG_EXTRA_OPTIONS "-fvisibility=hidden -g0") # -fcoroutines
52
+ message("Platform is LINUX")
53
+ endif()
54
+
55
+
56
+ IF (CMAKE_C_COMPILER_ID STREQUAL "GNU")
57
+
58
+ ELSEIF (CMAKE_C_COMPILER_ID MATCHES "Clang")
59
+
60
+ ELSEIF (CMAKE_C_COMPILER_ID MATCHES "MSVC")
61
+
62
+ ELSE ()
63
+
64
+ ENDIF ()
65
+
66
+ IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
67
+
68
+ ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
69
+
70
+ ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
71
+
72
+ ELSE ()
73
+
74
+
75
+ ENDIF ()
76
+
77
+ message("Compiling C with: " ${CMAKE_C_COMPILER_ID})
78
+ message("Compiling Cpp with: " ${CMAKE_CXX_COMPILER_ID})
79
+
80
+ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
81
+
82
+ set(EXTENSION_INCS ${CMAKE_CURRENT_SOURCE_DIR}/pyxcp/cpp_ext)
83
+
84
+ pybind11_add_module(rekorder pyxcp/recorder/wrap.cpp pyxcp/recorder/lz4.c pyxcp/recorder/lz4hc.c)
85
+ pybind11_add_module(cpp_ext pyxcp/cpp_ext/extension_wrapper.cpp)
86
+ pybind11_add_module(stim pyxcp/daq_stim/stim_wrapper.cpp pyxcp/daq_stim/stim.cpp pyxcp/daq_stim/scheduler.cpp)
87
+ pybind11_add_module(transport_ext pyxcp/transport/transport_wrapper.cpp pyxcp/recorder/lz4.c pyxcp/recorder/lz4hc.c)
88
+
89
+ target_include_directories(rekorder PRIVATE ${EXTENSION_INCS} ${CMAKE_CURRENT_SOURCE_DIR}/pyxcp/recorder)
90
+ target_include_directories(cpp_ext PRIVATE ${EXTENSION_INCS})
91
+ target_include_directories(stim PRIVATE ${EXTENSION_INCS} ${CMAKE_CURRENT_SOURCE_DIR}/pyxcp/daq_stim)
92
+ target_include_directories(transport_ext PRIVATE ${EXTENSION_INCS} ${CMAKE_CURRENT_SOURCE_DIR}/pyxcp/transport ${CMAKE_CURRENT_SOURCE_DIR}/pyxcp/cpp_ext ${CMAKE_CURRENT_SOURCE_DIR}/pyxcp/recorder)
93
+
94
+ target_compile_options(rekorder PUBLIC "-DEXTENSION_NAME=pyxcp.recorder.rekorder")
95
+ target_compile_options(cpp_ext PUBLIC "-DEXTENSION_NAME=pyxcp.cpp_ext.cpp_ext")
96
+ target_compile_options(stim PUBLIC "-DEXTENSION_NAME=pyxcp.daq_stim.stim")
97
+ target_compile_options(transport_ext PUBLIC "-DEXTENSION_NAME=pyxcp.transport.transport_ext")
98
+
99
+ add_executable(asamkeydll ${CMAKE_CURRENT_SOURCE_DIR}/pyxcp/asamkeydll.c)
100
+ if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
101
+ target_link_libraries(asamkeydll PRIVATE dl)
102
+ endif()
103
+
104
+
105
+ if (CMAKE_SIZEOF_VOID_P EQUAL 8)
106
+ # CMAKE_SYSTEM_NAME STREQUAL "Windows"
107
+ endif()
108
+
109
+ IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
110
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_N_CLANG_BASE_OPTIONS} ${GCC_N_CLANG_EXTRA_OPTIONS}")
111
+ target_link_options(cpp_ext PUBLIC -flto=auto)
112
+ target_link_options(stim PUBLIC -flto=auto)
113
+ target_link_options(rekorder PUBLIC -flto=auto)
114
+ ELSEIF (CMAKE_C_COMPILER_ID MATCHES "MSVC")
115
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_BASE_OPTIONS} ${MSVC_EXTRA_OPTIONS}")
116
+ ENDIF()
117
+
118
+ IF (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
119
+ # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" -fuse-ld=lld)
120
+ ENDIF()
121
+
122
+ # target_include_directories(preprocessor PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/pya2l/extensions>)
123
+ # target_link_libraries(preprocessor pybind11::headers)
124
+ # set_target_properties(preprocessor PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON CXX_VISIBILITY_PRESET ON VISIBILITY_INLINES_HIDDEN ON)
125
+
126
+ install(TARGETS rekorder LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/pyxcp/recorder)
127
+ install(TARGETS cpp_ext LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/pyxcp/cpp_ext)
128
+ install(TARGETS stim LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/pyxcp/daq_stim)
129
+ install(TARGETS transport_ext LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/pyxcp/transport)
130
+ install(TARGETS asamkeydll RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/pyxcp)
pyxcp-0.25.8/PKG-INFO ADDED
@@ -0,0 +1,341 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyxcp
3
+ Version: 0.25.8
4
+ Summary: Universal Calibration Protocol for Python
5
+ License: LGPLv3
6
+ License-File: LICENSE
7
+ Keywords: automotive,ecu,xcp,asam,autosar
8
+ Author: Christoph Schueler
9
+ Author-email: cpu.gems@googlemail.com
10
+ Requires-Python: >=3.10,<4.0
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
14
+ Classifier: License :: Other/Proprietary License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Scientific/Engineering
22
+ Classifier: Topic :: Software Development
23
+ Requires-Dist: bandit (>=1.7.8,<2.0.0)
24
+ Requires-Dist: chardet (>=5.2.0,<6.0.0)
25
+ Requires-Dist: construct (>=2.10.68,<3.0.0)
26
+ Requires-Dist: line-profiler-pycharm (>=1.1.0,<2.0.0)
27
+ Requires-Dist: mako (>=1.2.4,<2.0.0)
28
+ Requires-Dist: pydantic (>=2.5,<3)
29
+ Requires-Dist: pyserial (>=3.5,<4.0)
30
+ Requires-Dist: python-can (>=4.2.2,<5.0.0)
31
+ Requires-Dist: pytz (>=2025.2,<2026.0)
32
+ Requires-Dist: pyusb (>=1.2.1,<2.0.0)
33
+ Requires-Dist: rich (>=14.0.0,<15.0.0)
34
+ Requires-Dist: toml (>=0.10.2,<0.11.0)
35
+ Requires-Dist: tomlkit (>=0.13.3,<0.14.0)
36
+ Requires-Dist: traitlets (<=5.11.2)
37
+ Requires-Dist: uptime (>=3.0.1,<4.0.0)
38
+ Project-URL: Homepage, https://github.com/christoph2/pyxcp
39
+ Description-Content-Type: text/x-rst
40
+
41
+ Readme
42
+ ======
43
+
44
+ .. image:: pyxcp_social.svg
45
+ :align: center
46
+
47
+ Reliable Python tooling for the ASAM MCD-1 XCP protocol (measurement,
48
+ calibration, flashing) with multiple transports (CAN, Ethernet, USB,
49
+ Serial) and handy CLI utilities.
50
+
51
+ |PyPI| |Python Versions| |License: LGPL v3+| |Code style: black|
52
+
53
+ ``pyXCP`` is a production-ready Python library for communicating with
54
+ XCP-enabled devices, most commonly automotive ECUs. Use it to take
55
+ measurements, adjust parameters (calibration), stream DAQ/STIM, and
56
+ program devices during development.
57
+
58
+ Highlights:
59
+
60
+ - Transports: Ethernet (TCP/IP), CAN, USB, Serial (SxI)
61
+ - Cross-platform: Windows, Linux, macOS
62
+ - Rich CLI tools for common XCP tasks
63
+ - Extensible architecture and layered design
64
+
65
+ --------------
66
+
67
+ Installation
68
+ ------------
69
+
70
+ The easiest way is from PyPI:
71
+
72
+ .. code:: shell
73
+
74
+ pip install pyxcp
75
+
76
+ To install from the main branch:
77
+
78
+ .. code:: shell
79
+
80
+ pip install git+https://github.com/christoph2/pyxcp.git
81
+
82
+ Requirements
83
+ ~~~~~~~~~~~~
84
+
85
+ - Python >= 3.10
86
+ - Building from source requires a working C/C++ toolchain (native
87
+ extensions are used for performance). Wheels are provided for common
88
+ platforms and Python versions; if a wheel is not available, pip will
89
+ build from source.
90
+ - An XCP slave device (or simulator)
91
+
92
+ Quick start
93
+ -----------
94
+
95
+ The tutorial walks you through typical tasks end-to-end: see `tutorial <tutorial.rst>`_.
96
+
97
+ Minimal example using the built-in argument parser and context manager:
98
+
99
+ .. code:: python
100
+
101
+ from pyxcp.cmdline import ArgumentParser
102
+
103
+ ap = ArgumentParser(description="pyXCP hello world")
104
+
105
+ with ap.run() as x:
106
+ x.connect()
107
+ identifier = x.identifier(0x01)
108
+ print(f"ID: {identifier!r}")
109
+ print(x.slaveProperties)
110
+ x.disconnect()
111
+
112
+ Configuration
113
+ ~~~~~~~~~~~~~
114
+
115
+ ``pyXCP`` supports a
116
+ `traitlets <https://github.com/ipython/traitlets>`__\-based configuration system.
117
+
118
+ - Recommended Python config example and generator: `tutorial <tutorial.rst>`__ and `configuration <configuration.rst>`__
119
+ - Legacy TOML examples remain available for compatibility.
120
+
121
+ Command‑line tools
122
+ ~~~~~~~~~~~~~~~~~~
123
+
124
+ Installed entry points (see pyproject.toml):
125
+
126
+ - xcp-info — print capabilities and properties
127
+ - xcp-id-scanner — scan for slave identifiers
128
+ - xcp-fetch-a2l — retrieve A2L from target (if supported)
129
+ - xcp-profile — generate/convert config files
130
+ - xcp-examples — launch assorted demos/examples
131
+ - xmraw-converter — convert recorder .xmraw data
132
+ - pyxcp-probe-can-drivers — list available CAN interfaces
133
+
134
+ Run any tool with -h for options.
135
+
136
+ Features
137
+ --------
138
+
139
+ - Multiple transport layers: Ethernet (TCP), CAN, USB, SxI (serial/UART)
140
+ - Data Acquisition (DAQ) and Stimulation (STIM)
141
+ - Calibration (read/write parameters)
142
+ - Flashing/programming workflows
143
+ - A2L (ASAM MCD‑2 MC) support
144
+ - Recorder utilities and converters (see `recorder <recorder.rst>`__)
145
+ - Extensible architecture for custom transports
146
+
147
+ Documentation
148
+ -------------
149
+
150
+ - Getting started tutorial: `tutorial <tutorial.rst>`__
151
+ - Configuration: `configuration <configuration.rst>`__
152
+ - CAN driver setup and troubleshooting: `howto_can_driver <howto_can_driver.rst>`__
153
+ - Recorder: `recorder <recorder.rst>`__
154
+ - Troubleshooting: `troubleshooting <troubleshooting.rst>`__
155
+ - Troubleshooting matrix (common errors, root causes, fixes):
156
+ `troubleshooting_matrix <troubleshooting_matrix.rst>`__
157
+
158
+ To build the Sphinx documentation locally:
159
+
160
+ 1. Install doc requirements:
161
+ ``pip install -r docs/requirements.txt``
162
+ 2. Build:
163
+ ``sphinx-build -b html docs docs/_build/html``
164
+ 3. Open
165
+ ``docs/_build/html/index.html``
166
+
167
+ Compatibility
168
+ -------------
169
+
170
+ - Operating systems: Windows, Linux, macOS
171
+ - Python: 3.10 - 3.14, CPython wheels where available
172
+ - CAN backends: python-can compatible drivers (see `howto_can_driver <howto_can_driver.rst>`__)
173
+
174
+ Contributing
175
+ ------------
176
+
177
+ Contributions are welcome! Please: - Read `CODE_OF_CONDUCT <../CODE_OF_CONDUCT.md>`__ - Open an
178
+ issue or discussion before large changes - Use
179
+ `pre-commit <https://github.com/pre-commit/pre-commit>`__ to run linters
180
+ and tests locally
181
+
182
+ License
183
+ -------
184
+
185
+ GNU Lesser General Public License v3 or later (LGPLv3+). See LICENSE for
186
+ details.
187
+
188
+ References
189
+ ----------
190
+
191
+ - ASAM MCD‑1 XCP standard:
192
+ https://www.asam.net/standards/detail/mcd-1-xcp/
193
+
194
+ About ASAM MCD‑1 XCP
195
+ --------------------
196
+
197
+ XCP (Universal Measurement and Calibration Protocol) is an ASAM standard
198
+ defining a vendor‑neutral protocol to access internal data of electronic
199
+ control units (ECUs) for measurement, calibration (parameter tuning),
200
+ and programming. XCP decouples the protocol from the physical transport,
201
+ so the same command set can be carried over different buses such as CAN,
202
+ FlexRay, Ethernet, USB, or Serial.
203
+
204
+ - Roles: An XCP Master (this library) communicates with an XCP Slave
205
+ (your device/ECU or simulator).
206
+ - Layered concept: XCP defines an application layer and transport
207
+ layers. ``pyXCP`` implements the application layer and multiple transport
208
+ bindings.
209
+ - Use cases:
210
+
211
+ - Measurement: Read variables from the ECU in real‑time, including
212
+ high‑rate DAQ streaming.
213
+ - Calibration: Read/write parameters (calibration data) in RAM/flash.
214
+ - Programming: Download new program/data to flash (where the slave
215
+ supports it).
216
+
217
+ For the authoritative description, see the ASAM page:
218
+ https://www.asam.net/standards/detail/mcd-1-xcp/
219
+
220
+ XCP in a nutshell
221
+ -----------------
222
+
223
+ - Connect/Session: The master establishes a connection, negotiates
224
+ capabilities/features, and optionally unlocks protected functions via
225
+ seed & key.
226
+ - Addressing: Memory is accessed via absolute or segment‑relative
227
+ addresses. Addressing modes are described in the associated A2L file
228
+ (ASAM MCD‑2 MC), which maps symbolic names to addresses, data types,
229
+ and conversion rules.
230
+ - Events: The slave exposes events (e.g., “1 ms task”, “Combustion
231
+ cycle”), which trigger DAQ sampling. The master assigns signals (ODTs)
232
+ to these events for time‑aligned acquisition.
233
+ - DAQ/STIM: DAQ = Data Acquisition (slave → master), STIM = Stimulation
234
+ (master → slave). Both use event‑driven lists for deterministic
235
+ timing.
236
+ - Timestamps: DAQ may carry timestamps from the slave for precise time
237
+ correlation.
238
+ - Security: Access to sensitive commands (e.g., programming,
239
+ calibration) can be protected by a seed & key algorithm negotiated at
240
+ runtime.
241
+ - Checksums: XCP defines checksum services useful for verifying memory
242
+ regions (e.g., after flashing).
243
+
244
+ Relation to A2L (ASAM MCD‑2 MC)
245
+ -------------------------------
246
+
247
+ While XCP defines the protocol, the A2L file describes the measurement
248
+ and calibration objects (characteristics, measurements), data types,
249
+ conversion rules, and memory layout. In practice, you use ``pyXCP`` together
250
+ with an A2L to: - Resolve symbolic names to addresses and data types. -
251
+ Configure DAQ lists from human‑readable signal names. - Interpret raw
252
+ values using the appropriate conversion methods.
253
+
254
+ ``pyXCP`` provides utilities to fetch A2L data when supported by the slave
255
+ and to work with A2L‑described objects. See also
256
+ `pya2ldb <https://github.com/christoph2/pya2l>`__!
257
+
258
+ Transports and addressing
259
+ -------------------------
260
+
261
+ XCP is transport‑agnostic. ``pyXCP`` supports multiple transports and
262
+ addressing schemes: - CAN (XCP on CAN): Robust and ubiquitous in
263
+ vehicles; limited payload and bandwidth; suited for many calibration
264
+ tasks and moderate DAQ rates. - Ethernet (XCP on TCP/UDP): High
265
+ bandwidth with low latency; well suited for rich DAQ and programming
266
+ workflows. - USB: High throughput for lab setups; requires device
267
+ support. - Serial/SxI: Simple point‑to‑point links for embedded targets
268
+ and simulators.
269
+
270
+ The exact capabilities (e.g., max CTO/DTO, checksum types, timestamping)
271
+ are negotiated at connect time and depend on the slave and transport.
272
+
273
+ Supported features (overview)
274
+ -----------------------------
275
+
276
+ The scope of features depends on the connected slave. At the library
277
+ level, ``pyXCP`` provides: - Session management: CONNECT/DISCONNECT,
278
+ GET_STATUS/SLAVE_PROPERTIES, communication mode setup, error handling. -
279
+ Memory access: Upload/short upload, Download/Download Next,
280
+ verifications, optional paged memory where supported. - DAQ/STIM:
281
+ Configuration of DAQ lists/ODTs, event assignment, data streaming,
282
+ timestamp handling when available. - Programming helpers: Building
283
+ blocks for program/erase/write flows (exact sequence per slave’s flash
284
+ algorithm and A2L description). - Security/Seed & Key: Pluggable
285
+ seed‑to‑key resolution including 32↔64‑bit bridge on Windows. -
286
+ Utilities: Identifier scanning, A2L helpers, recorder and converters.
287
+
288
+ Refer to `tutorial <tutorial.rst>`__ and `configuration <configuration.rst>`__ for feature usage,
289
+ and xcp-info for a capability dump of your target.
290
+
291
+ Compliance and versions
292
+ -----------------------
293
+
294
+ ``pyXCP`` aims to be compatible with commonly used parts of ASAM MCD‑1 XCP.
295
+ Specific optional features are enabled when a slave advertises them
296
+ during CONNECT. Because implementations vary across vendors and ECU
297
+ projects, always consult your A2L and use xcp-info to confirm negotiated
298
+ options (e.g., checksum type, timestamp unit, max DTO size, address
299
+ granularity).
300
+
301
+ If you rely on a particular XCP feature/profile not mentioned here,
302
+ please open an issue with details about your slave and A2L so we can
303
+ clarify support and—if feasible—add coverage.
304
+
305
+ Safety, performance, and limitations
306
+ ------------------------------------
307
+
308
+ - Safety‑critical systems: XCP is a development and testing protocol. Do
309
+ not enable measurement/calibration on safety‑critical systems in the
310
+ field unless your system‑level safety case covers it.
311
+ - Performance: Achievable DAQ rates depend on transport bandwidth, ECU
312
+ event rates, DTO sizes, and host processing. Ethernet typically yields
313
+ the highest throughput.
314
+ - Latency/jitter: Event scheduling in the slave and OS scheduling on the
315
+ host can affect determinism. Use timestamps to correlate data
316
+ precisely.
317
+ - Access control: Seed & key protects sensitive functions; your
318
+ organization’s policy should govern algorithm distribution and access.
319
+
320
+ Further resources
321
+ -----------------
322
+
323
+ - ASAM MCD‑1 XCP standard (overview and membership):
324
+ https://www.asam.net/standards/detail/mcd-1-xcp/
325
+ - ASAM MCD‑2 MC (A2L) for object descriptions:
326
+ https://www.asam.net/standards/detail/mcd-2-mc/
327
+ - Introduction to DAQ/STIM concepts (ASAM publications and vendor docs)
328
+ - Related: CCP (legacy predecessor to XCP), ASAM MDF for measurement
329
+ data storage
330
+
331
+ .. |CI| image:: https://github.com/christoph2/pyxcp/workflows/Python%20application/badge.svg
332
+ :target: https://github.com/christoph2/pyxcp/actions
333
+ .. |PyPI| image:: https://img.shields.io/pypi/v/pyxcp.svg
334
+ :target: https://pypi.org/project/pyxcp/
335
+ .. |Python Versions| image:: https://img.shields.io/pypi/pyversions/pyxcp.svg
336
+ :target: https://pypi.org/project/pyxcp/
337
+ .. |License: LGPL v3+| image:: https://img.shields.io/badge/License-LGPL%20v3%2B-blue.svg
338
+ :target: https://www.gnu.org/licenses/lgpl-3.0
339
+ .. |Code style: black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
340
+ :target: https://github.com/psf/black
341
+
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env python
2
+
3
+ import multiprocessing as mp
4
+ import os
5
+ import platform
6
+ import re
7
+ import subprocess # nosec
8
+ import sys
9
+ import sysconfig
10
+ from pathlib import Path
11
+ from tempfile import TemporaryDirectory
12
+
13
+
14
+ TOP_DIR = Path(__file__).parent
15
+
16
+ print("Platform", platform.system())
17
+ uname = platform.uname()
18
+ if uname.system == "Darwin":
19
+ os.environ["MACOSX_DEPLOYMENT_TARGET"] = "10.13"
20
+
21
+ VARS = sysconfig.get_config_vars()
22
+
23
+
24
+ def get_python_base() -> str:
25
+ # Applies in this form only to Windows.
26
+ if "base" in VARS and VARS["base"]:
27
+ return VARS["base"]
28
+ if "installed_base" in VARS and VARS["installed_base"]:
29
+ return VARS["installed_base"]
30
+
31
+
32
+ def alternate_libdir(pth: str):
33
+ base = Path(pth).parent
34
+ libdir = Path(base) / "libs"
35
+ if libdir.exists():
36
+ # available_libs = os.listdir(libdir)
37
+ return str(libdir)
38
+ else:
39
+ return ""
40
+
41
+
42
+ def get_py_config() -> dict:
43
+ pynd = VARS["py_version_nodot"] # Should always be present.
44
+ include = sysconfig.get_path("include") # Seems to be cross-platform.
45
+ if uname.system == "Windows":
46
+ base = get_python_base()
47
+ library = f"python{pynd}.lib"
48
+ libdir = Path(base) / "libs"
49
+ if libdir.exists():
50
+ available_libs = os.listdir(libdir)
51
+ if library in available_libs:
52
+ libdir = str(libdir)
53
+ else:
54
+ libdir = ""
55
+ else:
56
+ libdir = alternate_libdir(include)
57
+ else:
58
+ library = VARS["LIBRARY"]
59
+ DIR_VARS = ("LIBDIR", "BINLIBDEST", "DESTLIB", "LIBDEST", "MACHDESTLIB", "DESTSHARED", "LIBPL")
60
+ arch = None
61
+ if uname.system == "Linux":
62
+ arch = VARS.get("MULTIARCH", "")
63
+ found = False
64
+ for dir_var in DIR_VARS:
65
+ if found:
66
+ break
67
+ dir_name = VARS.get(dir_var)
68
+ if not dir_name:
69
+ continue
70
+ if uname.system == "Darwin":
71
+ full_path = [Path(dir_name) / library]
72
+ elif uname.system == "Linux":
73
+ full_path = [Path(dir_name) / arch / library, Path(dir_name) / library]
74
+ else:
75
+ print("PF?", uname.system)
76
+ for fp in full_path:
77
+ print(f"Trying '{fp}'")
78
+ if fp.exists():
79
+ print(f"found Python library: '{fp}'")
80
+ libdir = str(fp.parent)
81
+ found = True
82
+ break
83
+ if not found:
84
+ print("Could NOT locate Python library.")
85
+ return dict(exe=sys.executable, include=include, libdir="", library=library)
86
+ return dict(exe=sys.executable, include=include, libdir=libdir, library=library)
87
+
88
+
89
+ def banner(msg: str) -> None:
90
+ print("=" * 80)
91
+ print(str.center(msg, 80))
92
+ print("=" * 80)
93
+
94
+
95
+ def get_env_int(name: str, default: int = 0) -> int:
96
+ return int(os.environ.get(name, default))
97
+
98
+
99
+ def get_env_bool(name: str, default: int = 0) -> bool:
100
+ return get_env_int(name, default)
101
+
102
+
103
+ def build_extension(debug: bool = False, use_temp_dir: bool = False) -> None:
104
+ print("build_ext::build_extension()")
105
+
106
+ use_temp_dir = use_temp_dir or get_env_bool("BUILD_TEMP")
107
+ debug = debug or get_env_bool("BUILD_DEBUG")
108
+
109
+ cfg = "Debug" if debug else "Release"
110
+ bits, linkage = platform.architecture()
111
+ print(f"Bits: {bits!r} Linkage: {linkage!r} Build-Type: {cfg!r}")
112
+
113
+ if bits == "32bit" and linkage == "ELF":
114
+ cmake_args = []
115
+ else:
116
+ py_cfg = get_py_config()
117
+ cmake_args = [
118
+ f"-DPython3_EXECUTABLE={py_cfg['exe']}",
119
+ f"-DPython3_INCLUDE_DIR={py_cfg['include']}",
120
+ f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
121
+ ]
122
+ if py_cfg["libdir"]:
123
+ cmake_args.append(f"-DPython3_LIBRARY={str(Path(py_cfg['libdir']) / Path(py_cfg['library']))}")
124
+
125
+ build_args = ["--config Release", "--verbose"]
126
+ # cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 /path/to/src
127
+
128
+ if sys.platform.startswith("darwin"):
129
+ # Cross-compile support for macOS - respect ARCHFLAGS if set
130
+ archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
131
+ if archs:
132
+ cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]
133
+
134
+ if use_temp_dir:
135
+ build_temp = Path(TemporaryDirectory(suffix=".build-temp").name) / "extension_it_in"
136
+ else:
137
+ build_temp = Path(".")
138
+ # print("cwd:", os.getcwd(), "build-dir:", build_temp, "top:", str(TOP_DIR))
139
+ if not build_temp.exists():
140
+ build_temp.mkdir(parents=True)
141
+
142
+ banner("Step #1: Configure")
143
+ # cmake_args += ["--debug-output"]
144
+ subprocess.run(["cmake", "-S", str(TOP_DIR), *cmake_args], cwd=build_temp, check=True) # nosec
145
+
146
+ cmake_args += [f"--parallel {mp.cpu_count()}"]
147
+
148
+ banner("Step #2: Build")
149
+ # build_args += ["-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"]
150
+ subprocess.run(["cmake", "--build", str(build_temp), *build_args], cwd=TOP_DIR, check=True) # nosec
151
+
152
+ banner("Step #3: Install")
153
+ # subprocess.run(["cmake", "--install", "."], cwd=build_temp, check=True) # nosec
154
+ subprocess.run(["cmake", "--install", build_temp], cwd=TOP_DIR, check=True) # nosec
155
+
156
+
157
+ if __name__ == "__main__":
158
+ includes = subprocess.getoutput("pybind11-config --cmakedir") # nosec
159
+ os.environ["pybind11_DIR"] = includes
160
+ build_extension(use_temp_dir=False)