python.conf 40 KB

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