python.conf 38 KB

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