python.conf 39 KB

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