python.conf 42 KB

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