python.conf 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  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. _REQUIRE_EXPLICIT_LICENSE()
  202. NO_CLANG_TIDY()
  203. }
  204. }
  205. # tag:python-specific tag:test
  206. STYLE_PYTHON_VALUE=no
  207. STYLE_PYTHON_PYPROJECT_VALUE=
  208. ### @usage: STYLE_PYTHON([pyproject])
  209. ###
  210. ### Check python3 sources for style issues using black.
  211. macro STYLE_PYTHON(pyproject...) {
  212. SET(STYLE_PYTHON_VALUE yes)
  213. SET(STYLE_PYTHON_PYPROJECT_VALUE ${pyproject})
  214. }
  215. # tag:python-specific tag:test
  216. ### @usage: NO_DOCTESTS()
  217. ###
  218. ### Disable doctests in PY[|3|23_]TEST
  219. macro NO_DOCTESTS() {
  220. ENV(YA_PYTEST_DISABLE_DOCTEST="yes")
  221. }
  222. # tag:python-specific tag:test
  223. ### @usage: _BASE_PYTEST # internal
  224. ###
  225. ### Base logic of Python 2.x py.test modules: common module properties and dependencies.
  226. module _BASE_PYTEST: _BASE_PY_PROGRAM {
  227. .NODE_TYPE=Program
  228. .FINAL_TARGET=no
  229. .ALLOWED=YT_SPEC NO_DOCTESTS
  230. when ($USE_ARCADIA_PYTHON == "yes") {
  231. PEERDIR+=library/python/pytest
  232. }
  233. when ($USE_ARCADIA_PYTHON == "no") {
  234. MODULE_SUFFIX=.pkg.fake
  235. PEERDIR+=library/python/pytest/empty
  236. }
  237. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS canondata/result.json)
  238. }
  239. # tag:python-specific tag:deprecated tag:test
  240. ### @usage: PYTEST_BIN() #deprecated
  241. ###
  242. ### Same as PY2TEST. Don't use this, use PY2TEST instead.
  243. module PYTEST_BIN: _BASE_PYTEST {
  244. .NODE_TYPE=Program
  245. .DEFAULT_NAME_GENERATOR=FullPath
  246. .ARGS_PARSER=Base
  247. SETUP_PYTEST_BIN()
  248. }
  249. # tag:python-specific tag:test
  250. ### @usage: PY2TEST([name])
  251. ###
  252. ### The test module for Python 2.x based on py.test
  253. ###
  254. ### This module is compatible only with PYTHON2-tagged modules and selects peers from multimodules accordingly.
  255. ### This module is compatible with non-Arcadia Python builds.
  256. ###
  257. ### Documentation: https://wiki.yandex-team.ru/yatool/test/#python
  258. ### Documentation about the Arcadia test system: https://wiki.yandex-team.ru/yatool/test/
  259. module PY2TEST: PYTEST_BIN {
  260. .RESTRICTED=STYLE_PYTHON
  261. .DEFAULT_NAME_GENERATOR=FullPath
  262. .ARGS_PARSER=Base
  263. when ($FAIL_PY2 == "yes") {
  264. _OK=no
  265. }
  266. elsewhen ($OPENSOURCE != "yes") {
  267. PEERDIR+=build/rules/py2_deprecation
  268. }
  269. SET(MODULE_LANG PY2)
  270. ASSERT(_OK You are using deprecated Python2-only code (PY2TEST). Please consider rewriting to Python 3.)
  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_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS canondata/result.json)
  283. SET(MODULE_LANG PY3)
  284. SETUP_PYTEST_BIN()
  285. PEERDIR+=library/python/pytest
  286. }
  287. # tag:python-specific tag:test
  288. ### Disable submodules with the specified name(s).
  289. ### Unlike EXCLUDE_TAGS this variable:
  290. ### - affects all projects in the build;
  291. ### - filter by module name and ignore MODULE_TAG.
  292. EXCLUDE_SUBMODULES=PY3TEST_LIBRARY
  293. # tag:python-specific tag:test
  294. ### @usage: PY3TEST([name])
  295. ###
  296. ### The test module for Python 3.x based on py.test
  297. ###
  298. ### This module is compatible only with PYTHON3-tagged modules and selects peers from multimodules accordingly.
  299. ### This module is only compatible with Arcadia Python build (to avoid tests duplication from Python2/3-tests). For non-Arcadia python use PYTEST.
  300. ###
  301. ### Documentation: https://wiki.yandex-team.ru/yatool/test/#testynapytest
  302. ### Documentation about the Arcadia test system: https://wiki.yandex-team.ru/yatool/test/
  303. multimodule PY3TEST {
  304. module PY3TEST_PROGRAM: PY3TEST_BIN {
  305. .IGNORED=RUN_ANTLR4_PYTHON
  306. .FINAL_TARGET=yes
  307. }
  308. module PY3TEST_LIBRARY: PY3_LIBRARY {
  309. PEERDIR+=library/python/pytest
  310. _REQUIRE_EXPLICIT_LICENSE()
  311. }
  312. }
  313. # tag:python-specific
  314. ### @usage: PY_ANY_MODULE(name major_ver [minor_ver] [EXPORTS symlist_file] [PREFIX prefix])
  315. ###
  316. ### The Python external module for any versio of Arcadia or system Python.
  317. ### 1. major_ver and minor_ver must be integers.
  318. ### 2. The resulting .so will have the prefix "lib".
  319. ### 3. Processing EXPORTS and PREFIX is the same as for DLL module
  320. ### This is native DLL, so it will select C++ version from PROTO_LIBRARY.
  321. ###
  322. ### Note: Use PYTHON2_MODULE()/PYTHON3_MODULE() in order to PEERDIR proper version of PY23_NATIVE_LIBRARY.
  323. ### Do not PEERDIR any PY*_LIBRARY: this will link Python in and render artifact unusable as Python module.
  324. ###
  325. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  326. module PY_ANY_MODULE: DLL_UNIT {
  327. .SEM=CPP_DYN_LIBRARY_SEM
  328. when ($MSVC != "yes" && $DARWIN != "yes") {
  329. LDFLAGS+= -Wl,-Bsymbolic
  330. }
  331. when ($USE_ARCADIA_PYTHON == "no") {
  332. when ($USE_SYSTEM_PYTHON) {
  333. PEERDIR+=build/platform/python
  334. }
  335. otherwise {
  336. when ($MSVC == "yes" || $CYGWIN == "yes") {
  337. LDFLAGS+=$PYTHON_LIBRARIES
  338. }
  339. }
  340. }
  341. # This by now replicates ymake's behavior. We'll get rid of SONAME setting in ymake and fix this code altogether
  342. SONAME=${pre=$MODULE_PREFIX;suf=$MODULE_SUFFIX:REALPRJNAME}
  343. when ($MODULE_VERSION) {
  344. LINK_DYN_LIB_FLAGS=--soname ${output;pre=$MODULE_PREFIX;suf=$MODULE_SUFFIX$MODULE_VERSION:REALPRJNAME}
  345. }
  346. _SONAME=$SONAME$MODULE_VERSION
  347. # -bundle
  348. when ($DARWIN == "yes") {
  349. LDFLAGS+=-flat_namespace
  350. }
  351. when ($MSVC == "yes" || $CYGWIN == "yes") {
  352. MODULE_PREFIX=
  353. MODULE_SUFFIX=.pyd
  354. }
  355. otherwise {
  356. MODULE_PREFIX=
  357. MODULE_SUFFIX=.so
  358. }
  359. .RESTRICTED=USE_PYTHON2 USE_PYTHON3 PY_SRCS PY_MAIN
  360. }
  361. # tag:python-specific
  362. ### @usage: PY2MODULE(name major_ver [minor_ver] [EXPORTS symlist_file] [PREFIX prefix])
  363. ###
  364. ### The Python external module for Python2 and any system Python
  365. ### 1. major_ver and minor_ver must be integers.
  366. ### 2. The resulting .so will have the prefix "lib".
  367. ### 3. Processing EXPORTS and PREFIX is the same as for DLL module
  368. ### This is native DLL, so it will select C++ version from PROTO_LIBRARY.
  369. ###
  370. ### Note: this module will always PEERDIR Python2 version of PY23_NATIVE_LIBRARY.
  371. ### Do not PEERDIR PY2_LIBRARY or PY23_LIBRARY: this will link Python in and render artifact unusable as Python module.
  372. ###
  373. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  374. module PY2MODULE: PY_ANY_MODULE {
  375. PYTHON2_MODULE()
  376. SET(MODULE_LANG PY2)
  377. .RESTRICTED=PYTHON3_MODULE PYTHON3_ADDINCL
  378. }
  379. # tag:python-specific
  380. ### @usage: PY3MODULE(name major_ver [minor_ver] [EXPORTS symlist_file] [PREFIX prefix])
  381. ###
  382. ### The Python external module for Python3 and any system Python
  383. ### 1. major_ver and minor_ver must be integers.
  384. ### 2. The resulting .so will have the prefix "lib".
  385. ### 3. Processing EXPORTS and PREFIX is the same as for DLL module
  386. ### This is native DLL, so it will select C++ version from PROTO_LIBRARY.
  387. ###
  388. ### Note: this module will always PEERDIR Python3 version of PY23_NATIVE_LIBRARY.
  389. ### Do not PEERDIR PY3_LIBRARY or PY23_LIBRARY: this will link Python in and render artifact unusable as Python module.
  390. ###
  391. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  392. module PY3MODULE: PY_ANY_MODULE {
  393. PYTHON3_MODULE()
  394. SET(MODULE_LANG PY3)
  395. .RESTRICTED=PYTHON2_MODULE PYTHON2_ADDINCL
  396. }
  397. # tag:python-specific
  398. ### @usage: PYTHON2_MODULE()
  399. ###
  400. ### Use in PY_ANY_MODULE to set it up for Python 2.x.
  401. macro PYTHON2_MODULE() {
  402. when ($USE_ARCADIA_PYTHON == "yes" && $MSVC == "yes" || $IS_CROSS_TOOLS == "yes") {
  403. PEERDIR+=contrib/tools/python/lib
  404. }
  405. SET(ANTLR_PYTHON Python2)
  406. PYTHON2_ADDINCL()
  407. }
  408. # tag:python-specific
  409. ### @usage: PYTHON3_MODULE()
  410. ###
  411. ### Use in PY_ANY_MODULE to set it up for Python 3.x.
  412. macro PYTHON3_MODULE() {
  413. when ($USE_ARCADIA_PYTHON == "yes" && $MSVC == "yes" || $IS_CROSS_TOOLS == "yes") {
  414. PEERDIR+=contrib/tools/python3/lib
  415. }
  416. SET(ANTLR_PYTHON Python3)
  417. PYTHON3_ADDINCL()
  418. }
  419. # tag:python-specific
  420. module _PY_PACKAGE: UNION {
  421. .EXTS=.py
  422. .ALLOWED=GRPC USE_SKIFF
  423. .IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER
  424. ENABLE(PY_PROTOS_FOR)
  425. SET(PEERDIR_TAGS PY_PROTO)
  426. SET(DONT_RESOLVE_INCLUDES no)
  427. }
  428. # tag:python-specific tag:deprecated tag:internal
  429. ### @usage: PY_PACKAGE(name) # internal, deprecated
  430. ###
  431. ### This is module created via PY_PROTOS_FOR() macro
  432. module PY_PACKAGE: _PY_PACKAGE {
  433. .ALIASES=SRCS=SRCS
  434. .FINAL_TARGET=yes
  435. }
  436. # tag:python-specific
  437. PY_NAMESPACE_VALUE=
  438. # tag:python-specific
  439. ### @usage: PY_NAMESPACE(prefix)
  440. ###
  441. ### Sets default Python namespace for all python sources in the module.
  442. ### Especially suitable in PROTO_LIBRARY where Python sources are generated and there is no PY_SRCS to place NAMESPACE parameter.
  443. macro PY_NAMESPACE(Arg) {
  444. SET(PY_NAMESPACE_VALUE $Arg)
  445. }
  446. # tag:python-specific tag:deprecated
  447. ### @usage: PY2_LIBRARY() # deprecated
  448. ###
  449. ### Deprecated. Use PY23_LIBRARY or PY3_LIBRARY instead.
  450. ### Python 2.x binary built library. Builds sources from PY_SRCS to data suitable for PY2_PROGRAM.
  451. ### Adds dependencies to Python 2.x runtime library from Arcadia.
  452. ### This module is only compatible with PYTHON2-tagged modules and selects those from multimodules.
  453. ### This module is only compatible with Arcadia Python build.
  454. ###
  455. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  456. module PY2_LIBRARY: _LIBRARY {
  457. _ARCADIA_PYTHON_ADDINCL()
  458. when ($NO_PYTHON_INCLS != "yes") {
  459. PEERDIR+=contrib/libs/python
  460. }
  461. when ($MSVC == "yes" || $CYGWIN == "yes") {
  462. MODULE_PREFIX=py
  463. }
  464. otherwise {
  465. MODULE_PREFIX=libpy
  466. }
  467. .ALLOWED=FORK_TESTS
  468. .IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER USE_PYTHON2
  469. .RESTRICTED=PYTHON3_ADDINCL USE_PYTHON3 PYTHON2_ADDINCL OPTIMIZE_PY_PROTOS NO_OPTIMIZE_PY_PROTOS STYLE_PYTHON
  470. USE_GLOBAL_CMD=yes
  471. when ($PY_PROTO_MYPY_ENABLED == "yes") {
  472. PY_PROTO_MYPY_SUFFIX=_pb2.pyi
  473. PY_PROTO_MYPY_PLUGIN=$PY_PROTO_MYPY_PLUGIN_BASE ${output;hide;noauto;norel;nopath;noext;suf=_pb2.pyi:File}
  474. 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}"})
  475. }
  476. SET(MODULE_LANG PY2)
  477. ADD_CLANG_TIDY()
  478. }
  479. # tag:python-specific
  480. ### @usage: PY3_LIBRARY()
  481. ###
  482. ### Python 3.x binary library. Builds sources from PY_SRCS to data suitable for PY2_PROGRAM
  483. ### Adds dependencies to Python 2.x runtime library from Arcadia.
  484. ### This module is only compatible with PYTHON3-tagged modules and selects those from multimodules.
  485. ### This module is only compatible with Arcadia Python build.
  486. ###
  487. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  488. module PY3_LIBRARY: _LIBRARY {
  489. _ARCADIA_PYTHON3_ADDINCL()
  490. when ($NO_PYTHON_INCLS != "yes") {
  491. PEERDIR+=contrib/libs/python
  492. }
  493. when ($MSVC == "yes" || $CYGWIN == "yes") {
  494. MODULE_PREFIX=py3
  495. }
  496. otherwise {
  497. MODULE_PREFIX=libpy3
  498. }
  499. .ALLOWED=FORK_TESTS
  500. .IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER
  501. .RESTRICTED=PYTHON3_ADDINCL USE_PYTHON3 PYTHON2_ADDINCL USE_PYTHON2 OPTIMIZE_PY_PROTOS NO_OPTIMIZE_PY_PROTOS
  502. USE_GLOBAL_CMD=yes
  503. RUN_CYTHON_SCRIPT=$YMAKE_PYTHON3 $CYTHON_SCRIPT
  504. RUN_CYTHON_SCRIPT_H=$YMAKE_PYTHON3 $CYTHON_SCRIPT
  505. PYTHON_TYPE_FOR_CYTHON=PY3
  506. ANTLR_PYTHON=Python3
  507. when ($PY_PROTO_MYPY_ENABLED == "yes") {
  508. PY_PROTO_MYPY_SUFFIX=_pb2.pyi
  509. PY_PROTO_MYPY_PLUGIN=$PY_PROTO_MYPY_PLUGIN_BASE ${output;hide;noauto;norel;nopath;noext;suf=_pb2.pyi:File}
  510. 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}"})
  511. }
  512. SET(MODULE_LANG PY3)
  513. ADD_CLANG_TIDY()
  514. }
  515. # tag:python-specific
  516. ### @usage: _BASE_PY_PROGRAM #internal
  517. ###
  518. ### The base module for all Python 2.x binary programs. Adds linking logic, relevant module properties and
  519. ### dependency on Python 2.x interpreter. Also adds import tests on all sources including PEERDIR'ed libraries.
  520. ### Links all Python 2.x libraries and Python 2.x interpreter into itself to form regular executable.
  521. ### This only compatible with PYTHON2-tagged modules and selects those from multimodules.
  522. ###
  523. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  524. module _BASE_PY_PROGRAM: _BASE_PROGRAM {
  525. .CMD=PY_PROGRAM_LINK_EXE
  526. _ARCADIA_PYTHON_ADDINCL()
  527. when ($SANITIZER_TYPE && $SANITIZER_TYPE != "no") {
  528. NO_CHECK_IMPORTS_FOR_VALUE=
  529. }
  530. ADD_CHECK_PY_IMPORTS()
  531. when ($NO_PYTHON_INCLS != "yes") {
  532. PEERDIR += contrib/libs/python
  533. }
  534. when ($USE_ARCADIA_PYTHON == "yes") {
  535. PEERDIR += library/python/runtime/main
  536. PEERDIR += contrib/deprecated/python/subprocess32
  537. when ($PYTHON_SQLITE3 != "no") {
  538. PEERDIR += contrib/tools/python/src/Modules/_sqlite
  539. }
  540. }
  541. when ($PYTHON_COVERAGE == "yes") {
  542. PEERDIR+=library/python/coverage
  543. }
  544. when ($ARCH_PPC64LE == "yes") {
  545. _MY_ALLOCATOR=SYSTEM
  546. }
  547. otherwise {
  548. _MY_ALLOCATOR=J
  549. }
  550. ALLOCATOR($_MY_ALLOCATOR)
  551. STRIP()
  552. when ($BUILD_TYPE == "DEBUG") {
  553. NO_STRIP=yes
  554. }
  555. when ($SANITIZER_TYPE && $SANITIZER_TYPE != "no") {
  556. NO_STRIP=yes
  557. }
  558. .IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER USE_PYTHON2
  559. .RESTRICTED=PYTHON3_ADDINCL USE_PYTHON3 PYTHON2_ADDINCL OPTIMIZE_PY_PROTOS NO_OPTIMIZE_PY_PROTOS
  560. SET(MODULE_LANG PY2)
  561. }
  562. # tag:python-specific tag:codenav
  563. when ($CODENAVIGATION && $NOCODENAVIGATION != "yes") {
  564. PY3_PROGRAM_LINK_EXE=$LINK_EXE ${kv;hide:"py3yndex $TARGET"}
  565. }
  566. otherwise {
  567. PY3_PROGRAM_LINK_EXE=$LINK_EXE
  568. }
  569. # tag:python-specific
  570. ### @usage: _BASE_PY_PROGRAM #internal
  571. ###
  572. ### The base module for all Python 3.x binary programs. Adds linking logic, relevant module properties and
  573. ### dependency on Python 3.x interpreter. Also adds import tests on all sources including libraries.
  574. ### Links all Python 3.x libraries and Python 3.x interpreter into itself to form regular executable.
  575. ### This only compatible with PYTHON3-tagged modules and selects those from multimodules
  576. ###
  577. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/
  578. module _BASE_PY3_PROGRAM: _BASE_PROGRAM {
  579. .CMD=PY3_PROGRAM_LINK_EXE
  580. _ARCADIA_PYTHON3_ADDINCL()
  581. RUN_CYTHON_SCRIPT=$YMAKE_PYTHON3 $CYTHON_SCRIPT
  582. RUN_CYTHON_SCRIPT_H=$YMAKE_PYTHON3 $CYTHON_SCRIPT
  583. PYTHON_TYPE_FOR_CYTHON=PY3
  584. PEERDIR(library/python/runtime_py3/main)
  585. when ($PYTHON_SQLITE3 != "no") {
  586. PEERDIR += contrib/tools/python3/src/Modules/_sqlite
  587. }
  588. when ($SANITIZER_TYPE && $SANITIZER_TYPE != "no") {
  589. NO_CHECK_IMPORTS_FOR_VALUE=
  590. }
  591. ADD_CHECK_PY_IMPORTS()
  592. when ($ARCH_PPC64LE == "yes") {
  593. _MY_ALLOCATOR=SYSTEM
  594. }
  595. otherwise {
  596. _MY_ALLOCATOR=J
  597. }
  598. ALLOCATOR($_MY_ALLOCATOR)
  599. STRIP()
  600. when ($NO_PYTHON_INCLS != "yes") {
  601. PEERDIR+=contrib/libs/python
  602. }
  603. when ($BUILD_TYPE == "DEBUG") {
  604. NO_STRIP=yes
  605. }
  606. when ($SANITIZER_TYPE && $SANITIZER_TYPE != "no") {
  607. NO_STRIP=yes
  608. }
  609. when ($PYTHON_COVERAGE == "yes") {
  610. PEERDIR+=library/python/coverage
  611. }
  612. when ($CODENAVIGATION && $NOCODENAVIGATION != "yes") {
  613. PEERDIR += contrib/python/six
  614. }
  615. .IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER
  616. .RESTRICTED=PYTHON3_ADDINCL USE_PYTHON3 PYTHON2_ADDINCL USE_PYTHON2
  617. SET(MODULE_LANG PY3)
  618. SET(ANTLR_PYTHON Python3)
  619. }
  620. # tag:python-specific
  621. ### @usage: PY3_PROGRAM_BIN([progname])
  622. ### Use instead of PY3_PROGRAM only if ya.make with PY3_PROGRAM() included in another ya.make
  623. ### In all other cases use PY3_PROGRAM
  624. module PY3_PROGRAM_BIN: _BASE_PY3_PROGRAM {
  625. # Look's like we cannot avoid copy-paste util ymake supports multiple inheritance
  626. # We need to attach coverage.extractor to every py_program target, except pytest targets
  627. ADD_YTEST($MODULE_PREFIX$REALPRJNAME coverage.extractor)
  628. }
  629. # tag:python-specific tag:internal
  630. NO_PYTHON_INCLS=no
  631. ### @usage: NO_PYTHON_INCLUDES() # internal
  632. ###
  633. ### Disable dependencies on libraries providing Python headers.
  634. ### This is only used in Python libraries themselves to avoid PEERDIR loops.
  635. macro NO_PYTHON_INCLUDES() {
  636. ENABLE(NO_PYTHON_INCLS)
  637. }
  638. # tag:python-specific
  639. ### @usage: PYTHON2_ADDINCL()
  640. ###
  641. ### This macro adds include path for Python headers (Python 2.x variant) without PEERDIR.
  642. ### This should be used in 2 cases only:
  643. ### - In PY2MODULE since it compiles into .so and uses external Python runtime;
  644. ### - In system Python libraries themselves since proper PEERDIR there may create a loop;
  645. ### In all other cases use USE_PYTHON2 macro instead.
  646. ###
  647. ### Never use this macro in PY2_PROGRAM, PY2_LIBRARY and PY23_LIBRARY: they have everything needed by default.
  648. ###
  649. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs
  650. macro PYTHON2_ADDINCL() {
  651. _PYTHON_ADDINCL()
  652. SET(MODULE_TAG PY2_NATIVE)
  653. SET(PEERDIR_TAGS CPP_PROTO CPP_FBS PY2_NATIVE YQL_UDF_STATIC __EMPTY__ DLL_LIB)
  654. }
  655. # tag:python-specific tag:internal
  656. ### @usage: _ARCADIA_PYTHON_ADDINCL() # internal
  657. ### This macro sets up Python headers for modules with Arcadia python (e.g. PY2_LIBRARY) and configures module as Python 2.x.
  658. macro _ARCADIA_PYTHON_ADDINCL() {
  659. _PYTHON_ADDINCL()
  660. SET(MODULE_TAG PY2)
  661. SET(PEERDIR_TAGS PY2 PY2_NATIVE PY_PROTO PY2_FBS YQL_UDF_STATIC __EMPTY__ DLL_LIB)
  662. }
  663. # tag:python-specific tag:internal
  664. ### @usage: _PYTHON_ADDINCL() # internal
  665. ### This macro sets up Python 2.x headers for both Arcadia and non-Arcadia python.
  666. macro _PYTHON_ADDINCL() {
  667. SET(PYTHON2 yes)
  668. SET(PYTHON3 no)
  669. when ($USE_ARCADIA_PYTHON == "yes") {
  670. ADDINCL+=GLOBAL contrib/libs/python/Include
  671. CFLAGS+=-DARCADIA_PYTHON_UNICODE_SIZE=$ARCADIA_PYTHON_UNICODE_SIZE
  672. }
  673. otherwise {
  674. when ($USE_SYSTEM_PYTHON) {
  675. PEERDIR+=build/platform/python
  676. }
  677. otherwise {
  678. CFLAGS+=$PYTHON_INCLUDE
  679. }
  680. }
  681. }
  682. # tag:python-specific
  683. ### @usage: PYTHON3_ADDINCL()
  684. ###
  685. ### This macro adds include path for Python headers (Python 3.x variant).
  686. ### This should be used in 2 cases only:
  687. ### - In PY2MODULE since it compiles into .so and uses external Python runtime;
  688. ### - In system Python libraries themselves since peerdir there may create a loop;
  689. ### In all other cases use USE_PYTHON3() macro instead.
  690. ###
  691. ### Never use this macro in PY3_PROGRAM and PY3_LIBRARY and PY23_LIBRARY: they have everything by default.
  692. ###
  693. ### Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs
  694. macro PYTHON3_ADDINCL() {
  695. _PYTHON3_ADDINCL()
  696. SET(MODULE_TAG PY3_NATIVE)
  697. SET(PEERDIR_TAGS CPP_PROTO CPP_FBS PY3_NATIVE YQL_UDF_STATIC __EMPTY__ DLL_LIB)
  698. }
  699. # tag:python-specific tag:internal
  700. ### @usage: _ARCADIA_PYTHON3_ADDINCL() # internal
  701. ###
  702. ### This macro sets up Python3 headers for modules with Arcadia python (e.g. PY3_LIBRARY) and configures module as Python 3.x.
  703. macro _ARCADIA_PYTHON3_ADDINCL() {
  704. _PYTHON3_ADDINCL()
  705. SET(MODULE_TAG PY3)
  706. SET(MODULE_LANG 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. }
  927. module PY3TEST_PROGRAM: PY3TEST_BIN {
  928. .FINAL_TARGET=yes
  929. .RESTRICTED=RUN_ANTLR4_PYTHON
  930. OBJ_SUF=.py3
  931. CANONIZE_SUB_PATH=py3test
  932. RUN_CYTHON_SCRIPT_H=$YMAKE_PYTHON $CYTHON_SCRIPT
  933. }
  934. module PY3TEST_LIBRARY: PY3_LIBRARY {
  935. .RESTRICTED=RUN_ANTLR4_PYTHON
  936. PEERDIR+=library/python/pytest
  937. _REQUIRE_EXPLICIT_LICENSE()
  938. RUN_CYTHON_SCRIPT_H=$YMAKE_PYTHON $CYTHON_SCRIPT
  939. }
  940. }