python.conf 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. # tag:python-specific tag:cython-specific
  2. CYTHON_SCRIPT=${input:"${ARCADIA_ROOT}/contrib/tools/cython/cython.py"} ${hide:CYTHON_FAKE_ID} $CYTHON_PREDEFINED_INCLUDES
  3. RUN_CYTHON_SCRIPT=$YMAKE_PYTHON $CYTHON_SCRIPT
  4. RUN_CYTHON_SCRIPT_H=$YMAKE_PYTHON $CYTHON_SCRIPT
  5. PYTHON_TYPE_FOR_CYTHON=PY2
  6. CYTHON_OUTPUT_INCLUDES=\
  7. ${output_include;hide:"contrib/libs/python/Include/compile.h"} \
  8. ${output_include;hide:"contrib/libs/python/Include/frameobject.h"} \
  9. ${output_include;hide:"contrib/libs/python/Include/longintrepr.h"} \
  10. ${output_include;hide:"contrib/libs/python/Include/pyconfig.h"} \
  11. ${output_include;hide:"contrib/libs/python/Include/Python.h"} \
  12. ${output_include;hide:"contrib/libs/python/Include/pythread.h"} \
  13. ${output_include;hide:"contrib/libs/python/Include/structmember.h"} \
  14. ${output_include;hide:"contrib/libs/python/Include/traceback.h"} \
  15. ${output_include;hide:"contrib/tools/cython/generated_c_headers.h"} \
  16. ${output_include;hide:"omp.h"}
  17. # tag:cython-specific
  18. CYTHON_CPP_OUTPUT_INCLUDES=${output_include;hide:"contrib/tools/cython/generated_cpp_headers.h"}
  19. # tag:cython-specific
  20. CYTHON_PREDEFINED_INCLUDES=\
  21. ${input;hide:"contrib/tools/cython/Cython/Utility/Buffer.c"} \
  22. ${input;hide:"contrib/tools/cython/Cython/Utility/Builtins.c"} \
  23. ${input;hide:"contrib/tools/cython/Cython/Utility/CMath.c"} \
  24. ${input;hide:"contrib/tools/cython/Cython/Utility/Capsule.c"} \
  25. ${input;hide:"contrib/tools/cython/Cython/Utility/CommonTypes.c"} \
  26. ${input;hide:"contrib/tools/cython/Cython/Utility/Complex.c"} \
  27. ${input;hide:"contrib/tools/cython/Cython/Utility/Coroutine.c"} \
  28. ${input;hide:"contrib/tools/cython/Cython/Utility/CythonFunction.c"} \
  29. ${input;hide:"contrib/tools/cython/Cython/Utility/Embed.c"} \
  30. ${input;hide:"contrib/tools/cython/Cython/Utility/Exceptions.c"} \
  31. ${input;hide:"contrib/tools/cython/Cython/Utility/ExtensionTypes.c"} \
  32. ${input;hide:"contrib/tools/cython/Cython/Utility/FunctionArguments.c"} \
  33. ${input;hide:"contrib/tools/cython/Cython/Utility/ImportExport.c"} \
  34. ${input;hide:"contrib/tools/cython/Cython/Utility/MemoryView_C.c"} \
  35. ${input;hide:"contrib/tools/cython/Cython/Utility/ModuleSetupCode.c"} \
  36. ${input;hide:"contrib/tools/cython/Cython/Utility/ObjectHandling.c"} \
  37. ${input;hide:"contrib/tools/cython/Cython/Utility/Optimize.c"} \
  38. ${input;hide:"contrib/tools/cython/Cython/Utility/Overflow.c"} \
  39. ${input;hide:"contrib/tools/cython/Cython/Utility/Printing.c"} \
  40. ${input;hide:"contrib/tools/cython/Cython/Utility/Profile.c"} \
  41. ${input;hide:"contrib/tools/cython/Cython/Utility/StringTools.c"} \
  42. ${input;hide:"contrib/tools/cython/Cython/Utility/TestUtilityLoader.c"} \
  43. ${input;hide:"contrib/tools/cython/Cython/Utility/TypeConversion.c"}
  44. # tag:cython-specific
  45. CYTHON_PREDEFINED_INDUCED=\
  46. contrib/libs/python/Include/Python.h
  47. # tag:cython-specific
  48. CYTHON_OPTIONS=
  49. when ($OS_LINUX) {
  50. CYTHON_OPTIONS += -E UNAME_SYSNAME=Linux
  51. }
  52. elsewhen ($OS_DARWIN) {
  53. CYTHON_OPTIONS += -E UNAME_SYSNAME=Darwin
  54. }
  55. elsewhen ($OS_WINDOWS) {
  56. CYTHON_OPTIONS += -E UNAME_SYSNAME=Windows
  57. }
  58. # tag:python-specific
  59. # PYTHON_DISTR={ "default" | "macos-brew" } determine python system supply
  60. # see build/platform/python/ya.make
  61. PYTHON_DISTR="default"
  62. when ($USE_SYSTEM_PYTHON) {
  63. USE_ARCADIA_PYTHON=no
  64. select ($USE_SYSTEM_PYTHON) {
  65. "2.7" ? {
  66. _SYSTEM_PYTHON27=yes
  67. PY_VERSION=2.7
  68. PY_FRAMEWORK_VERSION=2.7
  69. }
  70. "3.4" ? {
  71. _SYSTEM_PYTHON34=yes
  72. PY_VERSION=3.4m
  73. PY_FRAMEWORK_VERSION=3.4
  74. }
  75. "3.5" ? {
  76. _SYSTEM_PYTHON35=yes
  77. PY_VERSION=3.5m
  78. PY_FRAMEWORK_VERSION=3.5
  79. }
  80. "3.6" ? {
  81. _SYSTEM_PYTHON36=yes
  82. PY_VERSION=3.6m
  83. PY_FRAMEWORK_VERSION=3.6
  84. }
  85. "3.7" ? {
  86. _SYSTEM_PYTHON37=yes
  87. PY_VERSION=3.7m
  88. PY_FRAMEWORK_VERSION=3.7
  89. }
  90. "3.8" ? {
  91. _SYSTEM_PYTHON38=yes
  92. PY_VERSION=3.8
  93. PY_FRAMEWORK_VERSION=3.8
  94. }
  95. "3.9" ? {
  96. _SYSTEM_PYTHON39=yes
  97. PY_VERSION=3.9
  98. PY_FRAMEWORK_VERSION=3.9
  99. }
  100. "3.10" ? {
  101. _SYSTEM_PYTHON310=yes
  102. PY_VERSION=3.10
  103. PY_FRAMEWORK_VERSION=3.10
  104. }
  105. "3.11" ? {
  106. _SYSTEM_PYTHON311=yes
  107. PY_VERSION=3.11
  108. PY_FRAMEWORK_VERSION=3.11
  109. }
  110. "3.12" ? {
  111. _SYSTEM_PYTHON312=yes
  112. PY_VERSION=3.12
  113. PY_FRAMEWORK_VERSION=3.12
  114. }
  115. default ? {
  116. FATAL_ERROR_MESSAGE+=invalid USE_SYSTEM_PYTHON value
  117. }
  118. }
  119. }
  120. when ($BUILD_PYTHON3_BIN) {
  121. YMAKE_PYTHON3=${BUILD_PYTHON3_BIN}
  122. YMAKE_PYTHON3_PEERDIR=
  123. }
  124. otherwise {
  125. YMAKE_PYTHON3=${YMAKE_PYTHON3_RESOURCE_GLOBAL}/python3
  126. }
  127. # tag:python-specific
  128. when ($USE_ARCADIA_PYTHON == "no") {
  129. SYSINCL+=build/sysincl/python.yml
  130. }
  131. when ($OPENSOURCE) {
  132. SYSINCL+=build/sysincl/python-2-disable.yml
  133. }
  134. # tag:python-specific
  135. PYTHON2=no
  136. PYTHON3=no
  137. # tag:python-specific
  138. PYTHON_IMPORT_TRACING=yes
  139. # tag:python-specific
  140. when (!$ARCADIA_PYTHON_UNICODE_SIZE) {
  141. when ($OS_WINDOWS) {
  142. ARCADIA_PYTHON_UNICODE_SIZE=2
  143. }
  144. otherwise {
  145. ARCADIA_PYTHON_UNICODE_SIZE=4
  146. }
  147. }
  148. YMAKE_PYTHON3_PEERDIR=build/platform/python/ymake_python3
  149. macro NO_YMAKE_PYTHON3() {
  150. SET(YMAKE_PYTHON3_PEERDIR)
  151. }
  152. # tag:python-specific tag:deprecated tag:internal
  153. module _PY2_PROGRAM: _BASE_PY_PROGRAM {
  154. SET(MODULE_LANG PY2)
  155. # Looks like we cannot avoid copy-paste util ymake supports multiple inheritance
  156. # We need to attach coverage.extractor to every py_program target, except pytest targets
  157. ADD_YTEST($MODULE_PREFIX$REALPRJNAME coverage.extractor)
  158. }
  159. # tag:python-specific tag:deprecated
  160. ### @usage: PY2_PROGRAM([progname]) # deprecated
  161. ###
  162. ### Deprecated. Use PY3_PROGRAM instead.
  163. ### Python 2.x binary program. Links all Python 2.x libraries and Python 2.x interpreter into itself to form regular executable.
  164. ### If name is not specified it will be generated from the name of the containing project directory.
  165. ### This only compatible with PYTHON2-tagged modules and selects those from multimodules.
  166. ###
  167. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  168. module PY2_PROGRAM: _PY2_PROGRAM {
  169. .RESTRICTED=STYLE_PYTHON
  170. when ($FAIL_PY2 == "yes") {
  171. _OK=no
  172. }
  173. elsewhen ($OPENSOURCE != "yes") {
  174. PEERDIR+=build/rules/py2_deprecation
  175. }
  176. ASSERT(_OK You are using deprecated Python2-only code (PY2_PROGRAM). Please consider rewriting to Python 3.)
  177. }
  178. # tag:python-specific
  179. ### @usage: NO_EXTENDED_SOURCE_SEARCH()
  180. ###
  181. ### Prevent module using in extended python source search.
  182. ### Use the macro if module contains python2-only files (or other python sources which shouldn't be imported by python3 interpreter)
  183. ### which resides in the same directories with python 3 useful code. contrib/python/future is a example.
  184. ### Anyway, preferred way is to move such files into separate dir and don't use this macro at all.
  185. ###
  186. ### Also see: https://docs.yandex-team.ru/ya-make/manual/python/vars#y_python_extended_source_search for details
  187. macro NO_EXTENDED_SOURCE_SEARCH() {
  188. SET(NO_EXTENDED_SOURCE_SEARCH yes)
  189. }
  190. # tag:python-specific
  191. ### @usage: PY3_PROGRAM([progname])
  192. ###
  193. ### Python 3.x binary program. Links all Python 3.x libraries and Python 3.x interpreter into itself to form regular executable.
  194. ### If name is not specified it will be generated from the name of the containing project directory.
  195. ### This only compatible with PYTHON3-tagged modules and selects those from multimodules.
  196. ###
  197. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  198. multimodule PY3_PROGRAM {
  199. module PY3_BIN: PY3_PROGRAM_BIN {
  200. .PEERDIRSELF=PY3_BIN_LIB
  201. .IGNORED=RESOURCE RESOURCE_FILES PEERDIR TASKLET_REG RUN_ANTLR4_PYTHON BUILDWITH_CYTHON_CPP _BUILDWITH_CYTHON_CPP_DEP _BUILDWITH_CYTHON_CPP_H BUILDWITH_CYTHON_C _BUILDWITH_CYTHON_C_DEP _BUILDWITH_CYTHON_C_H _BUILDWITH_CYTHON_C_API_H
  202. # Notify pybuild to skip almost all PY_SRCS arguments except MAIN
  203. ENABLE(PROCESS_PY_MAIN_ONLY)
  204. _PY_PROGRAM()
  205. NO_CLANG_TIDY()
  206. }
  207. module PY3_BIN_LIB: PY3_LIBRARY {
  208. .IGNORED=LICENSE_RESTRICTION LICENSE_RESTRICTION_EXCEPTIONS
  209. # Notify pybuild to skip all python main function definitions
  210. ENABLE(IGNORE_PY_MAIN)
  211. NO_CLANG_TIDY()
  212. }
  213. }
  214. # tag:python-specific tag:test
  215. STYLE_PYTHON_VALUE=no
  216. STYLE_PYTHON_PYPROJECT_VALUE=
  217. ### @usage: STYLE_PYTHON([pyproject])
  218. ###
  219. ### Check python3 sources for style issues using black.
  220. macro STYLE_PYTHON(pyproject...) {
  221. SET(STYLE_PYTHON_VALUE yes)
  222. SET(STYLE_PYTHON_PYPROJECT_VALUE ${pyproject})
  223. }
  224. # tag:python-specific tag:test
  225. STYLE_RUFF_VALUE=no
  226. RUFF_CONFIG_PATHS_FILE=build/config/tests/ruff/ruff_config_paths.json
  227. ### @usage: STYLE_RUFF()
  228. ###
  229. ### Check python3 sources for style issues using ruff.
  230. macro STYLE_RUFF() {
  231. SET(STYLE_RUFF_VALUE yes)
  232. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${RUFF_CONFIG_PATHS_FILE})
  233. }
  234. # tag:python-specific tag:test
  235. ### @usage: NO_DOCTESTS()
  236. ###
  237. ### Disable doctests in PY[|3|23_]TEST
  238. macro NO_DOCTESTS() {
  239. ENV(YA_PYTEST_DISABLE_DOCTEST="yes")
  240. }
  241. # tag:python-specific tag:test
  242. ### @usage: _BASE_PYTEST # internal
  243. ###
  244. ### Base logic of Python 2.x py.test modules: common module properties and dependencies.
  245. module _BASE_PYTEST: _BASE_PY_PROGRAM {
  246. .NODE_TYPE=Program
  247. .FINAL_TARGET=no
  248. .ALLOWED=YT_SPEC NO_DOCTESTS
  249. when ($USE_ARCADIA_PYTHON == "yes") {
  250. PEERDIR+=library/python/pytest
  251. }
  252. when ($USE_ARCADIA_PYTHON == "no") {
  253. MODULE_SUFFIX=.pkg.fake
  254. PEERDIR+=library/python/pytest/empty
  255. }
  256. }
  257. # tag:python-specific tag:deprecated tag:test
  258. ### @usage: PYTEST_BIN() #deprecated
  259. ###
  260. ### Same as PY2TEST. Don't use this, use PY2TEST instead.
  261. module PYTEST_BIN: _BASE_PYTEST {
  262. .NODE_TYPE=Program
  263. .DEFAULT_NAME_GENERATOR=FullPath
  264. .ARGS_PARSER=Base
  265. SETUP_PYTEST_BIN()
  266. }
  267. # tag:python-specific tag:test
  268. ### @usage: PY2TEST([name])
  269. ###
  270. ### The test module for Python 2.x based on py.test
  271. ###
  272. ### This module is compatible only with PYTHON2-tagged modules and selects peers from multimodules accordingly.
  273. ### This module is compatible with non-Arcadia Python builds.
  274. ###
  275. ### Documentation: https://wiki.yandex-team.ru/yatool/test/#python
  276. ### Documentation about the Arcadia test system: https://wiki.yandex-team.ru/yatool/test/
  277. module PY2TEST: PYTEST_BIN {
  278. .RESTRICTED=STYLE_PYTHON
  279. .DEFAULT_NAME_GENERATOR=FullPath
  280. .ARGS_PARSER=Base
  281. when ($FAIL_PY2 == "yes") {
  282. _OK=no
  283. }
  284. elsewhen ($OPENSOURCE != "yes") {
  285. PEERDIR+=build/rules/py2_deprecation
  286. }
  287. SET(MODULE_LANG PY2)
  288. ASSERT(_OK You are using deprecated Python2-only code (PY2TEST). Please consider rewriting to Python 3.)
  289. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS canondata/result.json)
  290. _DONT_REQUIRE_LICENSE()
  291. }
  292. # tag:python-specific tag:deprecated tag:test
  293. ### @usage: PY3TEST_BIN() #deprecated
  294. ###
  295. ### Same as PY3TEST. Don't use this, use PY3TEST instead.
  296. module PY3TEST_BIN: _BASE_PY3_PROGRAM {
  297. .NODE_TYPE=Program
  298. .FINAL_TARGET=no
  299. .ALLOWED=YT_SPEC NO_DOCTESTS
  300. .DEFAULT_NAME_GENERATOR=FullPath
  301. .ARGS_PARSER=Base
  302. SET(MODULE_LANG PY3)
  303. SETUP_PYTEST_BIN()
  304. PEERDIR+=library/python/pytest
  305. }
  306. # tag:python-specific tag:test
  307. ### Disable submodules with the specified name(s).
  308. ### Unlike EXCLUDE_TAGS this variable:
  309. ### - affects all projects in the build;
  310. ### - filter by module name and ignore MODULE_TAG.
  311. EXCLUDE_SUBMODULES=PY3TEST_LIBRARY
  312. # tag:python-specific tag:test
  313. ### @usage: PY3TEST([name])
  314. ###
  315. ### The test module for Python 3.x based on py.test
  316. ###
  317. ### This module is compatible only with PYTHON3-tagged modules and selects peers from multimodules accordingly.
  318. ### This module is only compatible with Arcadia Python build (to avoid tests duplication from Python2/3-tests). For non-Arcadia python use PYTEST.
  319. ###
  320. ### Documentation: https://wiki.yandex-team.ru/yatool/test/#testynapytest
  321. ### Documentation about the Arcadia test system: https://wiki.yandex-team.ru/yatool/test/
  322. multimodule PY3TEST {
  323. module PY3TEST_PROGRAM: PY3TEST_BIN {
  324. .IGNORED=RUN_ANTLR4_PYTHON
  325. .FINAL_TARGET=yes
  326. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS canondata/result.json)
  327. _DONT_REQUIRE_LICENSE()
  328. }
  329. module PY3TEST_LIBRARY: PY3_LIBRARY {
  330. PEERDIR+=library/python/pytest
  331. _DONT_REQUIRE_LICENSE()
  332. }
  333. }
  334. # tag:python-specific
  335. ### @usage: PY_ANY_MODULE(name major_ver [minor_ver] [EXPORTS symlist_file] [PREFIX prefix])
  336. ###
  337. ### The Python external module for any versio of Arcadia or system Python.
  338. ### 1. major_ver and minor_ver must be integers.
  339. ### 2. The resulting .so will have the prefix "lib".
  340. ### 3. Processing EXPORTS and PREFIX is the same as for DLL module
  341. ### This is native DLL, so it will select C++ version from PROTO_LIBRARY.
  342. ###
  343. ### Note: Use PYTHON2_MODULE()/PYTHON3_MODULE() in order to PEERDIR proper version of PY23_NATIVE_LIBRARY.
  344. ### Do not PEERDIR any PY*_LIBRARY: this will link Python in and render artifact unusable as Python module.
  345. ###
  346. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  347. module PY_ANY_MODULE: DLL_UNIT {
  348. .SEM=CPP_DYN_LIBRARY_SEM
  349. when ($MSVC != "yes" && $DARWIN != "yes") {
  350. LDFLAGS+= -Wl,-Bsymbolic
  351. }
  352. when ($USE_ARCADIA_PYTHON == "no") {
  353. when ($USE_SYSTEM_PYTHON) {
  354. PEERDIR+=build/platform/python
  355. }
  356. otherwise {
  357. when ($MSVC == "yes" || $CYGWIN == "yes") {
  358. LDFLAGS+=$PYTHON_LIBRARIES
  359. }
  360. }
  361. }
  362. # This by now replicates ymake's behavior. We'll get rid of SONAME setting in ymake and fix this code altogether
  363. SONAME=${pre=$MODULE_PREFIX;suf=$MODULE_SUFFIX:REALPRJNAME}
  364. when ($MODULE_VERSION) {
  365. LINK_DYN_LIB_FLAGS=--soname ${output;pre=$MODULE_PREFIX;suf=$MODULE_SUFFIX$MODULE_VERSION:REALPRJNAME}
  366. }
  367. _SONAME=$SONAME$MODULE_VERSION
  368. # -bundle
  369. when ($DARWIN == "yes") {
  370. when ($CLANG_VER == "16") {
  371. # TODO(pg): also check 17 and beyond
  372. }
  373. otherwise {
  374. LDFLAGS+=-flat_namespace
  375. }
  376. }
  377. when ($MSVC == "yes" || $CYGWIN == "yes") {
  378. MODULE_PREFIX=
  379. MODULE_SUFFIX=.pyd
  380. }
  381. otherwise {
  382. MODULE_PREFIX=
  383. MODULE_SUFFIX=.so
  384. }
  385. .RESTRICTED=USE_PYTHON2 USE_PYTHON3 PY_SRCS PY_MAIN
  386. }
  387. # tag:python-specific
  388. ### @usage: PY2MODULE(name major_ver [minor_ver] [EXPORTS symlist_file] [PREFIX prefix])
  389. ###
  390. ### The Python external module for Python2 and any system Python
  391. ### 1. major_ver and minor_ver must be integers.
  392. ### 2. The resulting .so will have the prefix "lib".
  393. ### 3. Processing EXPORTS and PREFIX is the same as for DLL module
  394. ### This is native DLL, so it will select C++ version from PROTO_LIBRARY.
  395. ###
  396. ### Note: this module will always PEERDIR Python2 version of PY23_NATIVE_LIBRARY.
  397. ### Do not PEERDIR PY2_LIBRARY or PY23_LIBRARY: this will link Python in and render artifact unusable as Python module.
  398. ###
  399. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  400. module PY2MODULE: PY_ANY_MODULE {
  401. PYTHON2_MODULE()
  402. SET(MODULE_LANG PY2)
  403. .RESTRICTED=PYTHON3_MODULE PYTHON3_ADDINCL
  404. }
  405. # tag:python-specific
  406. ### @usage: PY3MODULE(name major_ver [minor_ver] [EXPORTS symlist_file] [PREFIX prefix])
  407. ###
  408. ### The Python external module for Python3 and any system Python
  409. ### 1. major_ver and minor_ver must be integers.
  410. ### 2. The resulting .so will have the prefix "lib".
  411. ### 3. Processing EXPORTS and PREFIX is the same as for DLL module
  412. ### This is native DLL, so it will select C++ version from PROTO_LIBRARY.
  413. ###
  414. ### Note: this module will always PEERDIR Python3 version of PY23_NATIVE_LIBRARY.
  415. ### Do not PEERDIR PY3_LIBRARY or PY23_LIBRARY: this will link Python in and render artifact unusable as Python module.
  416. ###
  417. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  418. module PY3MODULE: PY_ANY_MODULE {
  419. PYTHON3_MODULE()
  420. SET(MODULE_LANG PY3)
  421. .RESTRICTED=PYTHON2_MODULE PYTHON2_ADDINCL
  422. }
  423. # tag:python-specific
  424. ### @usage: PYTHON2_MODULE()
  425. ###
  426. ### Use in PY_ANY_MODULE to set it up for Python 2.x.
  427. macro PYTHON2_MODULE() {
  428. when ($USE_ARCADIA_PYTHON == "yes" && $MSVC == "yes" || $IS_CROSS_TOOLS == "yes") {
  429. PEERDIR+=contrib/tools/python/lib
  430. }
  431. SET(ANTLR_PYTHON Python2)
  432. PYTHON2_ADDINCL()
  433. }
  434. # tag:python-specific
  435. ### @usage: PYTHON3_MODULE()
  436. ###
  437. ### Use in PY_ANY_MODULE to set it up for Python 3.x.
  438. macro PYTHON3_MODULE() {
  439. when ($USE_ARCADIA_PYTHON == "yes" && $MSVC == "yes" || $IS_CROSS_TOOLS == "yes") {
  440. PEERDIR+=contrib/tools/python3/lib2
  441. }
  442. SET(ANTLR_PYTHON Python3)
  443. PYTHON3_ADDINCL()
  444. }
  445. # tag:python-specific
  446. module _PY_PACKAGE: UNION {
  447. .EXTS=.py
  448. .ALLOWED=GRPC USE_SKIFF
  449. .IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER
  450. ENABLE(PY_PROTOS_FOR)
  451. SET(PEERDIR_TAGS PY_PROTO)
  452. SET(DONT_RESOLVE_INCLUDES no)
  453. }
  454. # tag:python-specific tag:deprecated tag:internal
  455. ### @usage: PY_PACKAGE(name) # internal, deprecated
  456. ###
  457. ### This is module created via PY_PROTOS_FOR() macro
  458. module PY_PACKAGE: _PY_PACKAGE {
  459. .ALIASES=SRCS=SRCS
  460. .FINAL_TARGET=yes
  461. }
  462. # tag:python-specific
  463. PY_NAMESPACE_VALUE=
  464. # tag:python-specific
  465. ### @usage: PY_NAMESPACE(prefix)
  466. ###
  467. ### Sets default Python namespace for all python sources in the module.
  468. ### Especially suitable in PROTO_LIBRARY where Python sources are generated and there is no PY_SRCS to place NAMESPACE parameter.
  469. macro PY_NAMESPACE(Arg) {
  470. SET(PY_NAMESPACE_VALUE $Arg)
  471. }
  472. # tag:python-specific tag:deprecated
  473. ### @usage: PY2_LIBRARY() # deprecated
  474. ###
  475. ### Deprecated. Use PY23_LIBRARY or PY3_LIBRARY instead.
  476. ### Python 2.x binary built library. Builds sources from PY_SRCS to data suitable for PY2_PROGRAM.
  477. ### Adds dependencies to Python 2.x runtime library from Arcadia.
  478. ### This module is only compatible with PYTHON2-tagged modules and selects those from multimodules.
  479. ### This module is only compatible with Arcadia Python build.
  480. ###
  481. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  482. module PY2_LIBRARY: _LIBRARY {
  483. _ARCADIA_PYTHON_ADDINCL()
  484. when ($NO_PYTHON_INCLS != "yes") {
  485. PEERDIR+=contrib/libs/python
  486. }
  487. when ($MSVC == "yes" || $CYGWIN == "yes") {
  488. MODULE_PREFIX=py
  489. }
  490. otherwise {
  491. MODULE_PREFIX=libpy
  492. }
  493. .ALLOWED=FORK_TESTS
  494. .IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER USE_PYTHON2
  495. .RESTRICTED=PYTHON3_ADDINCL USE_PYTHON3 PYTHON2_ADDINCL OPTIMIZE_PY_PROTOS NO_OPTIMIZE_PY_PROTOS STYLE_PYTHON
  496. USE_GLOBAL_CMD=yes
  497. when ($PY_PROTO_MYPY_ENABLED == "yes") {
  498. PY_PROTO_MYPY_SUFFIX=_pb2.pyi
  499. PY_PROTO_MYPY_PLUGIN=$PY_PROTO_MYPY_PLUGIN_BASE ${output;hide;noauto;norel;nopath;noext;suf=_pb2.pyi:File}
  500. PY_PROTO_MYPY_PLUGIN_INTERNAL=$PY_PROTO_MYPY_PLUGIN_BASE ${output;hide;noauto;norel;nopath;noext;suf=__int___pb2.pyi:File} ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__int___pb2.pyi:File} ${nopath;noext;suf=_pb2.pyi:File}"})
  501. }
  502. SET(MODULE_LANG PY2)
  503. ADD_CLANG_TIDY()
  504. }
  505. # tag:python-specific
  506. ### @usage: PY3_LIBRARY()
  507. ###
  508. ### Python 3.x binary library. Builds sources from PY_SRCS to data suitable for PY2_PROGRAM
  509. ### Adds dependencies to Python 2.x runtime library from Arcadia.
  510. ### This module is only compatible with PYTHON3-tagged modules and selects those from multimodules.
  511. ### This module is only compatible with Arcadia Python build.
  512. ###
  513. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  514. module PY3_LIBRARY: _LIBRARY {
  515. _ARCADIA_PYTHON3_ADDINCL()
  516. when ($NO_PYTHON_INCLS != "yes") {
  517. PEERDIR+=contrib/libs/python
  518. }
  519. when ($MSVC == "yes" || $CYGWIN == "yes") {
  520. MODULE_PREFIX=py3
  521. }
  522. otherwise {
  523. MODULE_PREFIX=libpy3
  524. }
  525. .ALLOWED=FORK_TESTS
  526. .IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER
  527. .RESTRICTED=PYTHON3_ADDINCL USE_PYTHON3 PYTHON2_ADDINCL USE_PYTHON2 OPTIMIZE_PY_PROTOS NO_OPTIMIZE_PY_PROTOS
  528. USE_GLOBAL_CMD=yes
  529. RUN_CYTHON_SCRIPT=$YMAKE_PYTHON3 $CYTHON_SCRIPT
  530. RUN_CYTHON_SCRIPT_H=$YMAKE_PYTHON3 $CYTHON_SCRIPT
  531. PYTHON_TYPE_FOR_CYTHON=PY3
  532. ANTLR_PYTHON=Python3
  533. when ($PY_PROTO_MYPY_ENABLED == "yes") {
  534. PY_PROTO_MYPY_SUFFIX=_pb2.pyi
  535. PY_PROTO_MYPY_PLUGIN=$PY_PROTO_MYPY_PLUGIN_BASE ${output;hide;noauto;norel;nopath;noext;suf=_pb2.pyi:File}
  536. PY_PROTO_MYPY_PLUGIN_INTERNAL=$PY_PROTO_MYPY_PLUGIN_BASE ${output;hide;noauto;norel;nopath;noext;suf=__int___pb2.pyi:File} ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__int___pb2.pyi:File} ${nopath;noext;suf=_pb2.pyi:File}"})
  537. }
  538. SET(MODULE_LANG PY3)
  539. ADD_CLANG_TIDY()
  540. }
  541. # tag:python-specific
  542. ### @usage: _BASE_PY_PROGRAM #internal
  543. ###
  544. ### The base module for all Python 2.x binary programs. Adds linking logic, relevant module properties and
  545. ### dependency on Python 2.x interpreter. Also adds import tests on all sources including PEERDIR'ed libraries.
  546. ### Links all Python 2.x libraries and Python 2.x interpreter into itself to form regular executable.
  547. ### This only compatible with PYTHON2-tagged modules and selects those from multimodules.
  548. ###
  549. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  550. module _BASE_PY_PROGRAM: _BASE_PROGRAM {
  551. .CMD=PY_PROGRAM_LINK_EXE
  552. _ARCADIA_PYTHON_ADDINCL()
  553. when ($SANITIZER_TYPE && $SANITIZER_TYPE != "no") {
  554. NO_CHECK_IMPORTS_FOR_VALUE=
  555. }
  556. ADD_CHECK_PY_IMPORTS()
  557. when ($NO_PYTHON_INCLS != "yes") {
  558. PEERDIR += contrib/libs/python
  559. }
  560. when ($USE_ARCADIA_PYTHON == "yes") {
  561. PEERDIR += library/python/runtime/main
  562. PEERDIR += contrib/deprecated/python/subprocess32
  563. when ($PYTHON_SQLITE3 != "no") {
  564. PEERDIR += contrib/tools/python/src/Modules/_sqlite
  565. }
  566. }
  567. when ($PYTHON_COVERAGE == "yes") {
  568. PEERDIR+=library/python/coverage
  569. }
  570. when ($PYTHON_IMPORT_TRACING == "yes") {
  571. PEERDIR += library/python/import_tracing/constructor
  572. }
  573. when ($ARCH_PPC64LE == "yes") {
  574. _MY_ALLOCATOR=SYSTEM
  575. }
  576. otherwise {
  577. _MY_ALLOCATOR=J
  578. }
  579. ALLOCATOR($_MY_ALLOCATOR)
  580. STRIP()
  581. when ($BUILD_TYPE == "DEBUG" || $BUILD_TYPE == "FASTDEBUG") {
  582. NO_STRIP=yes
  583. }
  584. when ($SANITIZER_TYPE && $SANITIZER_TYPE != "no") {
  585. NO_STRIP=yes
  586. }
  587. .IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER USE_PYTHON2
  588. .RESTRICTED=PYTHON3_ADDINCL USE_PYTHON3 PYTHON2_ADDINCL OPTIMIZE_PY_PROTOS NO_OPTIMIZE_PY_PROTOS
  589. SET(MODULE_LANG PY2)
  590. }
  591. # tag:python-specific tag:codenav
  592. when ($CODENAVIGATION && $NOCODENAVIGATION != "yes") {
  593. PY3_PROGRAM_LINK_EXE=$LINK_EXE ${kv;hide:"py3yndex $TARGET"}
  594. }
  595. otherwise {
  596. PY3_PROGRAM_LINK_EXE=$LINK_EXE
  597. }
  598. # tag:python-specific
  599. ### @usage: _BASE_PY_PROGRAM #internal
  600. ###
  601. ### The base module for all Python 3.x binary programs. Adds linking logic, relevant module properties and
  602. ### dependency on Python 3.x interpreter. Also adds import tests on all sources including libraries.
  603. ### Links all Python 3.x libraries and Python 3.x interpreter into itself to form regular executable.
  604. ### This only compatible with PYTHON3-tagged modules and selects those from multimodules
  605. ###
  606. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  607. module _BASE_PY3_PROGRAM: _BASE_PROGRAM {
  608. .CMD=PY3_PROGRAM_LINK_EXE
  609. _ARCADIA_PYTHON3_ADDINCL()
  610. RUN_CYTHON_SCRIPT=$YMAKE_PYTHON3 $CYTHON_SCRIPT
  611. RUN_CYTHON_SCRIPT_H=$YMAKE_PYTHON3 $CYTHON_SCRIPT
  612. PYTHON_TYPE_FOR_CYTHON=PY3
  613. PEERDIR(library/python/runtime_py3/main)
  614. when ($PYTHON_SQLITE3 != "no") {
  615. PEERDIR += contrib/tools/python3/Modules/_sqlite
  616. }
  617. when ($SANITIZER_TYPE && $SANITIZER_TYPE != "no") {
  618. NO_CHECK_IMPORTS_FOR_VALUE=
  619. }
  620. ADD_CHECK_PY_IMPORTS()
  621. when ($ARCH_PPC64LE == "yes") {
  622. _MY_ALLOCATOR=SYSTEM
  623. }
  624. otherwise {
  625. _MY_ALLOCATOR=J
  626. }
  627. ALLOCATOR($_MY_ALLOCATOR)
  628. STRIP()
  629. when ($NO_PYTHON_INCLS != "yes") {
  630. PEERDIR+=contrib/libs/python
  631. }
  632. when ($BUILD_TYPE == "DEBUG" || $BUILD_TYPE == "FASTDEBUG") {
  633. NO_STRIP=yes
  634. }
  635. when ($SANITIZER_TYPE && $SANITIZER_TYPE != "no") {
  636. NO_STRIP=yes
  637. }
  638. when ($PYTHON_COVERAGE == "yes") {
  639. PEERDIR+=library/python/coverage
  640. }
  641. when ($PYTHON_IMPORT_TRACING == "yes") {
  642. PEERDIR += library/python/import_tracing/constructor
  643. }
  644. when ($CODENAVIGATION && $NOCODENAVIGATION != "yes") {
  645. PEERDIR += contrib/python/six
  646. }
  647. .IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER
  648. .RESTRICTED=PYTHON3_ADDINCL USE_PYTHON3 PYTHON2_ADDINCL USE_PYTHON2
  649. SET(MODULE_LANG PY3)
  650. SET(ANTLR_PYTHON Python3)
  651. }
  652. # tag:python-specific
  653. ### @usage: PY3_PROGRAM_BIN([progname])
  654. ### Use instead of PY3_PROGRAM only if ya.make with PY3_PROGRAM() included in another ya.make
  655. ### In all other cases use PY3_PROGRAM
  656. module PY3_PROGRAM_BIN: _BASE_PY3_PROGRAM {
  657. # Look's like we cannot avoid copy-paste util ymake supports multiple inheritance
  658. # We need to attach coverage.extractor to every py_program target, except pytest targets
  659. ADD_YTEST($MODULE_PREFIX$REALPRJNAME coverage.extractor)
  660. }
  661. # tag:python-specific tag:internal
  662. NO_PYTHON_INCLS=no
  663. ### @usage: NO_PYTHON_INCLUDES() # internal
  664. ###
  665. ### Disable dependencies on libraries providing Python headers.
  666. ### This is only used in Python libraries themselves to avoid PEERDIR loops.
  667. macro NO_PYTHON_INCLUDES() {
  668. ENABLE(NO_PYTHON_INCLS)
  669. }
  670. # tag:python-specific
  671. ### @usage: PYTHON2_ADDINCL()
  672. ###
  673. ### This macro adds include path for Python headers (Python 2.x variant) without PEERDIR.
  674. ### This should be used in 2 cases only:
  675. ### - In PY2MODULE since it compiles into .so and uses external Python runtime;
  676. ### - In system Python libraries themselves since proper PEERDIR there may create a loop;
  677. ### In all other cases use USE_PYTHON2 macro instead.
  678. ###
  679. ### Never use this macro in PY2_PROGRAM, PY2_LIBRARY and PY23_LIBRARY: they have everything needed by default.
  680. ###
  681. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs
  682. macro PYTHON2_ADDINCL() {
  683. _PYTHON_ADDINCL()
  684. SET(MODULE_TAG PY2_NATIVE)
  685. SET(PEERDIR_TAGS CPP_PROTO CPP_FBS PY2_NATIVE YQL_UDF_STATIC __EMPTY__ RESOURCE_LIB DLL_LIB)
  686. }
  687. # tag:python-specific tag:internal
  688. ### @usage: _ARCADIA_PYTHON_ADDINCL() # internal
  689. ### This macro sets up Python headers for modules with Arcadia python (e.g. PY2_LIBRARY) and configures module as Python 2.x.
  690. macro _ARCADIA_PYTHON_ADDINCL() {
  691. _PYTHON_ADDINCL()
  692. SET(MODULE_TAG PY2)
  693. SET(PEERDIR_TAGS PY2 PY2_NATIVE PY_PROTO PY2_FBS YQL_UDF_STATIC __EMPTY__ RESOURCE_LIB DLL_LIB)
  694. }
  695. # tag:python-specific tag:internal
  696. ### @usage: _PYTHON_ADDINCL() # internal
  697. ### This macro sets up Python 2.x headers for both Arcadia and non-Arcadia python.
  698. macro _PYTHON_ADDINCL() {
  699. SET(PYTHON2 yes)
  700. SET(PYTHON3 no)
  701. when ($USE_ARCADIA_PYTHON == "yes") {
  702. ADDINCL+=GLOBAL contrib/libs/python/Include
  703. CFLAGS+=-DARCADIA_PYTHON_UNICODE_SIZE=$ARCADIA_PYTHON_UNICODE_SIZE
  704. }
  705. otherwise {
  706. when ($USE_SYSTEM_PYTHON) {
  707. PEERDIR+=build/platform/python
  708. }
  709. otherwise {
  710. CFLAGS+=$PYTHON_INCLUDE
  711. }
  712. }
  713. }
  714. # tag:python-specific
  715. ### @usage: PYTHON3_ADDINCL()
  716. ###
  717. ### This macro adds include path for Python headers (Python 3.x variant).
  718. ### This should be used in 2 cases only:
  719. ### - In PY2MODULE since it compiles into .so and uses external Python runtime;
  720. ### - In system Python libraries themselves since peerdir there may create a loop;
  721. ### In all other cases use USE_PYTHON3() macro instead.
  722. ###
  723. ### Never use this macro in PY3_PROGRAM and PY3_LIBRARY and PY23_LIBRARY: they have everything by default.
  724. ###
  725. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs
  726. macro PYTHON3_ADDINCL() {
  727. _PYTHON3_ADDINCL()
  728. SET(MODULE_TAG PY3_NATIVE)
  729. SET(PEERDIR_TAGS CPP_PROTO CPP_FBS PY3_NATIVE YQL_UDF_STATIC __EMPTY__ RESOURCE_LIB DLL_LIB)
  730. }
  731. # tag:python-specific tag:internal
  732. ### @usage: _ARCADIA_PYTHON3_ADDINCL() # internal
  733. ###
  734. ### This macro sets up Python3 headers for modules with Arcadia python (e.g. PY3_LIBRARY) and configures module as Python 3.x.
  735. macro _ARCADIA_PYTHON3_ADDINCL() {
  736. _PYTHON3_ADDINCL()
  737. SET(MODULE_TAG PY3)
  738. SET(PEERDIR_TAGS PY3 PY3_BIN_LIB PY3TEST_LIBRARY PY3_NATIVE PY3_PROTO PY3_FBS YQL_UDF_STATIC __EMPTY__ RESOURCE_LIB DLL_LIB)
  739. }
  740. # tag:python-specific tag:internal
  741. ### @usage: _PYTHON_ADDINCL() # internal
  742. ###
  743. ### This macro sets up Python 3.x headers for both Arcadia and non-Arcadia python.
  744. macro _PYTHON3_ADDINCL() {
  745. SET(PYTHON3 yes)
  746. SET(PYTHON2 no)
  747. when ($USE_ARCADIA_PYTHON == "yes") {
  748. CFLAGS+=-DUSE_PYTHON3
  749. ADDINCL+=GLOBAL contrib/libs/python/Include
  750. }
  751. otherwise {
  752. when ($USE_SYSTEM_PYTHON) {
  753. PEERDIR+=build/platform/python
  754. }
  755. otherwise {
  756. CFLAGS+=$PYTHON_INCLUDE
  757. }
  758. }
  759. }
  760. # tag:python-specific
  761. ### @usage: USE_PYTHON2()
  762. ###
  763. ### This adds Python 2.x runtime library to your LIBRARY and makes it Python2-compatible.
  764. ### Compatibility means proper PEERDIRs, ADDINCLs and variant selection on PEERDIRs to multimodules.
  765. ###
  766. ### If you'd like to use #include <Python.h> with Python2 specify USE_PYTHON2 or better make it PY2_LIBRARY.
  767. ### If you'd like to use #include <Python.h> with Python3 specify USE_PYTHON3 or better make it PY3_LIBRARY.
  768. ### If you'd like to use #include <Python.h> with both Python2 and Python3 convert your LIBRARY to PY23_LIBRARY.
  769. ###
  770. ### @see: [PY2_LIBRARY](#module_PY2_LIBRARY), [PY3_LIBRARY](#module_PY3_LIBRARY), [PY23_LIBRARY](#multimodule_PY23_LIBRARY)
  771. macro USE_PYTHON2() {
  772. _ARCADIA_PYTHON_ADDINCL()
  773. SET(PEERDIR_TAGS PY2 PY2_NATIVE CPP_PROTO CPP_FBS YQL_UDF_STATIC __EMPTY__ RESOURCE_LIB DLL_LIB)
  774. PEERDIR(contrib/libs/python)
  775. }
  776. # tag:python-specific
  777. ### @usage: USE_PYTHON3()
  778. ###
  779. ### This adds Python3 library to your LIBRARY and makes it Python3-compatible.
  780. ### Compatibility means proper PEERDIRs, ADDINCLs and variant selection on PEERDIRs to multimodules.
  781. ###
  782. ### If you'd like to use #include <Python.h> with Python3 specify USE_PYTHON3 or better make it PY3_LIBRARY.
  783. ### If you'd like to use #include <Python.h> with Python2 specify USE_PYTHON2 or better make it PY2_LIBRARY.
  784. ### If you'd like to use #include <Python.h> with both Python2 and Python3 convert your LIBRARY to PY23_LIBRARY.
  785. ###
  786. ### @see: [PY2_LIBRARY](#module_PY2_LIBRARY), [PY3_LIBRARY](#module_PY3_LIBRARY), [PY23_LIBRARY](#multimodule_PY23_LIBRARY)
  787. macro USE_PYTHON3() {
  788. _ARCADIA_PYTHON3_ADDINCL()
  789. SET(PEERDIR_TAGS PY3 PY3_BIN_LIB PY3TEST_LIBRARY PY3_NATIVE CPP_PROTO CPP_FBS YQL_UDF_STATIC __EMPTY__ RESOURCE_LIB DLL_LIB)
  790. PEERDIR(contrib/libs/python)
  791. when ($USE_ARCADIA_PYTHON == "yes") {
  792. PEERDIR+=library/python/runtime_py3
  793. }
  794. }
  795. # tag:python-specific tag:coverage
  796. ### @usage: NO_PYTHON_COVERAGE()
  797. ###
  798. ### Disable python coverage for module
  799. macro NO_PYTHON_COVERAGE() {
  800. DISABLE(PYTHON_COVERAGE)
  801. }
  802. # tag:python-specific tag:import_tracing
  803. ### @usage: NO_IMPORT_TRACING()
  804. ###
  805. ### Disable python coverage for module
  806. macro NO_IMPORT_TRACING() {
  807. DISABLE(PYTHON_IMPORT_TRACING)
  808. }
  809. # tag:python-specific tag:coverage tag:cython
  810. ### @usage: NO_CYTHON_COVERAGE()
  811. ###
  812. ### Disable cython and cythonized python coverage (CYTHONIZE_PY)
  813. ### Implies NO_CLANG_COVERAGE() - right now, we can't disable instrumentation for .py.cpp files, but enable for .cpp
  814. macro NO_CYTHON_COVERAGE() {
  815. DISABLE(CYTHON_COVERAGE)
  816. NO_CLANG_COVERAGE()
  817. }
  818. # tag:python-specific
  819. ### @usage: PY_SRCS({| CYTHON_C} { | TOP_LEVEL | NAMESPACE ns} Files...)
  820. ###
  821. ### Build specified Python sources according to Arcadia binary Python build. Basically creates precompiled and source resources keyed with module paths.
  822. ### The resources eventually are linked into final program and can be accessed as regular Python modules.
  823. ### This custom loader linked into the program will add them to sys.meta_path.
  824. ###
  825. ### PY_SRCS also support .proto, .ev, .pyx and .swg files. The .proto and .ev are compiled to .py-code by protoc and than handled as usual .py files.
  826. ### .pyx and .swg lead to C/C++ Python extensions generation, that are automatically registered in Python as built-in modules.
  827. ###
  828. ### By default .pyx files are built as C++-extensions. Use CYTHON_C to build them as C (similar to BUILDWITH_CYTHON_C, but with the ability to specify namespace).
  829. ###
  830. ### __init__.py never required, but if present (and specified in PY_SRCS), it will be imported when you import package modules with __init__.py Oh.
  831. ###
  832. ### @example
  833. ###
  834. ### PY2_LIBRARY(mymodule)
  835. ### PY_SRCS(a.py sub/dir/b.py e.proto sub/dir/f.proto c.pyx sub/dir/d.pyx g.swg sub/dir/h.swg)
  836. ### END()
  837. ###
  838. ### PY_SRCS honors Python2 and Python3 differences and adjusts itself to Python version of a current module.
  839. ### PY_SRCS can be used in any Arcadia Python build modules like PY*_LIBRARY, PY*_PROGRAM, PY*TEST.
  840. ### PY_SRCS in LIBRARY or PROGRAM effectively converts these into PY2_LIBRARY and PY2_PROGRAM respectively.
  841. ### It is strongly advised to make this conversion explicit. Never use PY_SRCS in a LIBRARY if you plan to use it from external Python extension module.
  842. ###
  843. ### Documentation: https://wiki.yandex-team.ru/arcadia/python/pysrcs/#modulipylibrarypy3libraryimakrospysrcs
  844. macro PY_SRCS() {
  845. DEFAULT(MODULE_TAG PY2)
  846. DEFAULT(PYTHON2 yes)
  847. DEFAULT(PYTHON3 no)
  848. }
  849. # tag:python-specific
  850. _ALL_PY_FILES=
  851. # tag:python-specific
  852. macro _ALL_PY_SRCS2(TOP_LEVEL?"TOP_LEVEL":"", RECURSIVE?"/**":"", ONLY_TEST_FILES?"test_*.py":"*.py", ONLY_TEST_FILES2?"*_test.py":"***", NO_TEST_FILES?"**/test_*.py **/*_test.py":"", NAMESPACE[], REST[], REST2[], EAT_TAIL[]) {
  853. _GLOB(_ALL_PY_FILES ${suf=${RECURSIVE}/${ONLY_TEST_FILES}:REST} ${suf=${RECURSIVE}/${ONLY_TEST_FILES2}:REST2} ${suf=${RECURSIVE}/ya.make:REST} EXCLUDE ya.make ${NO_TEST_FILES})
  854. }
  855. # tag:python-specific
  856. ### @usage: ALL_PY_SRCS([RECURSIVE] [NO_TEST_FILES] { | TOP_LEVEL | NAMESPACE ns} [Dirs...])
  857. ###
  858. ### Puts all .py-files from given Dirs (relative to projects') into PY_SRCS of the current module.
  859. ### If Dirs is ommitted project directory is used
  860. ###
  861. ### `RECURSIVE` makes lookup recursive with resprect to Dirs
  862. ### `NO_TEST_FILES` excludes files `test_*.py` and `*_test.py` those are normally subject to `TEST_SRCS`
  863. ### `TOP_LEVEL` and `NAMESPACE` are forwarded to `PY_SRCS`
  864. ###
  865. ### Note: Only one such macro per module is allowed
  866. ### Note: Macro is designed to reject any ya.make files in Dirs except current one
  867. ###
  868. ### @see [PY_SRCS()](#macro_PY_SRCS)
  869. macro ALL_PY_SRCS(TOP_LEVEL?"TOP_LEVEL":"", NAMESPACE="", RECURSIVE?"RECURSIVE":"", NO_TEST_FILES?"NO_TEST_FILES":"", Files...) {
  870. _ALL_PY_SRCS2(${pre=NAMESPACE :NAMESPACE} ${TOP_LEVEL} ${RECURSIVE} ${NO_TEST_FILES} REST .${pre=/:Files})
  871. PY_SRCS(_MR ${pre=NAMESPACE :NAMESPACE} ${TOP_LEVEL} $_ALL_PY_FILES)
  872. }
  873. # tag:python-specific
  874. ### @usage: ALL_PYTEST_SRCS([RECURSIVE] [Dirs...])
  875. ###
  876. ### Puts all .py-files from given Dirs (relative to projects') into TEST_SRCS of the current module.
  877. ### If Dirs is omitted project directory is used
  878. ###
  879. ### `RECURSIVE` makes lookup recursive with respect to Dirs
  880. ### `ONLY_TEST_FILES` includes only files `test_*.py` and `*_test.py`, others are normally subject to `PY_SRCS`
  881. ###
  882. ### Note: Only one such macro per module is allowed
  883. ### Note: Macro is designed to reject any ya.make files in Dirs except current one
  884. ###
  885. ### @see [TEST_SRCS()](#macro_TEST_SRCS)
  886. macro ALL_PYTEST_SRCS(TOP_LEVEL?"TOP_LEVEL":"", NAMESPACE="", RECURSIVE?"RECURSIVE":"", ONLY_TEST_FILES?"ONLY_TEST_FILES ONLY_TEST_FILES2 REST2":"EAT_TAIL", Files...) {
  887. _ALL_PY_SRCS2(${pre=NAMESPACE :NAMESPACE} ${TOP_LEVEL} ${RECURSIVE} REST .${pre=/:Files} ${ONLY_TEST_FILES} .${pre=/:Files})
  888. TEST_SRCS(_MR $_ALL_PY_FILES)
  889. }
  890. # tag:python-specific
  891. _PY_EXTRA_LINT_FILES_VALUE=
  892. ### @usage: PY_EXTRA_LINT_FILES(files...)
  893. ###
  894. ### Add extra Python files for linting. This macro allows adding
  895. ### Python files which has no .py extension.
  896. macro PY_EXTRA_LINT_FILES(FILES...) {
  897. SET_APPEND(_PY_EXTRA_LINT_FILES_VALUE $FILES)
  898. }
  899. # tag:python-specific
  900. ### @usage: PY23_LIBRARY([name])
  901. ###
  902. ### Build PY2_LIBRARY or PY3_LIBRARY depending on incoming PEERDIR.
  903. ### Direct build or build by RECURSE creates both variants.
  904. ### This multimodule doesn't define any final targets, so use from DEPENDS or BUNDLE is not allowed.
  905. ###
  906. ### Documentation: https://wiki.yandex-team.ru/arcadia/python/pysrcs
  907. multimodule PY23_LIBRARY {
  908. module PY2: PY2_LIBRARY {
  909. .RESTRICTED=RUN_ANTLR4_PYTHON
  910. OBJ_SUF=.py2
  911. }
  912. module PY3: PY3_LIBRARY {
  913. .RESTRICTED=RUN_ANTLR4_PYTHON
  914. RUN_CYTHON_SCRIPT_H=$YMAKE_PYTHON $CYTHON_SCRIPT
  915. OBJ_SUF=.py3
  916. }
  917. }
  918. # tag:python-specific
  919. ### @usage: PY23_NATIVE_LIBRARY([name])
  920. ###
  921. ### Build LIBRARY compatible with either Python 2.x or Python 3.x depending on incoming PEERDIR.
  922. ###
  923. ### This multimodule doesn't depend on Arcadia Python binary build. It is intended only for C++ code and cannot contain PY_SRCS and USE_PYTHON2 macros.
  924. ### Use these multimodule instead of PY23_LIBRARY if the C++ extension defined in it will be used in PY2MODULE.
  925. ### While it doesn't bring Arcadia Python dependency itself, it is still compatible with Arcadia Python build and can be PEERDIR-ed from PY2_LIBRARY and alikes.
  926. ### Proper version will be selected according to Python version of the module PEERDIR comes from.
  927. ###
  928. ### This mulrtimodule doesn't define any final targets so cannot be used from DEPENDS or BUNDLE macros.
  929. ###
  930. ### For more information read https://wiki.yandex-team.ru/arcadia/python/pysrcs/#pysrcssrcsipy23nativelibrary
  931. ###
  932. ### @see [LIBRARY()](#module_LIBRARY), [PY2MODULE()](#module_PY2MODULE)
  933. multimodule PY23_NATIVE_LIBRARY {
  934. module PY2: LIBRARY {
  935. .RESTRICTED=PY_SRCS USE_PYTHON2 USE_PYTHON3 PYTHON3_ADDINCL RUN_ANTLR4_PYTHON
  936. OBJ_SUF=.py2
  937. PYTHON2_ADDINCL()
  938. SET(MODULE_LANG PY2)
  939. }
  940. module PY3: LIBRARY {
  941. .RESTRICTED=PY_SRCS USE_PYTHON2 USE_PYTHON3 RUN_ANTLR4_PYTHON
  942. .ALIASES=PYTHON2_ADDINCL=PYTHON3_ADDINCL
  943. .SEM=CPP_LIBRARY_SEM
  944. .GLOBAL_SEM=CPP_OBJ_LIBRARY_SEM
  945. PYTHON3_ADDINCL()
  946. SET(MODULE_LANG PY3)
  947. when ($MSVC == "yes" || $CYGWIN == "yes") {
  948. MODULE_PREFIX=py3c
  949. }
  950. otherwise {
  951. MODULE_PREFIX=libpy3c
  952. }
  953. OBJ_SUF=.py3
  954. }
  955. }
  956. # tag:python-specific
  957. multimodule PY23_TEST {
  958. module PY2 : PYTEST_BIN {
  959. .RESTRICTED=RUN_ANTLR4_PYTHON
  960. MODULE_PREFIX=py2_
  961. OBJ_SUF=.py2
  962. CANONIZE_SUB_PATH=py2test
  963. RUN_CYTHON_SCRIPT_H=$YMAKE_PYTHON $CYTHON_SCRIPT
  964. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS canondata/py2test/result.json)
  965. _DONT_REQUIRE_LICENSE()
  966. }
  967. module PY3TEST_PROGRAM: PY3TEST_BIN {
  968. .FINAL_TARGET=yes
  969. .RESTRICTED=RUN_ANTLR4_PYTHON
  970. OBJ_SUF=.py3
  971. CANONIZE_SUB_PATH=py3test
  972. RUN_CYTHON_SCRIPT_H=$YMAKE_PYTHON $CYTHON_SCRIPT
  973. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS canondata/py3test/result.json)
  974. _DONT_REQUIRE_LICENSE()
  975. }
  976. module PY3TEST_LIBRARY: PY3_LIBRARY {
  977. .RESTRICTED=RUN_ANTLR4_PYTHON
  978. PEERDIR+=library/python/pytest
  979. RUN_CYTHON_SCRIPT_H=$YMAKE_PYTHON $CYTHON_SCRIPT
  980. _DONT_REQUIRE_LICENSE()
  981. }
  982. }