python.conf 39 KB

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