python.conf 39 KB

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