python.conf 42 KB

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