python.conf 41 KB

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