Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH] distutils-r1.eclass: Add pyproject.toml support
Date: Tue, 24 Dec 2019 11:42:54
Message-Id: 20191224114214.301636-1-mgorny@gentoo.org
1 Signed-off-by: Michał Górny <mgorny@g.o>
2 ---
3 eclass/distutils-r1.eclass | 29 +++++++++++++++++++++++++++++
4 1 file changed, 29 insertions(+)
5
6 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
7 index 65294a065da7..c3d2b9fc11c3 100644
8 --- a/eclass/distutils-r1.eclass
9 +++ b/eclass/distutils-r1.eclass
10 @@ -86,6 +86,8 @@ esac
11 # - no -- do not add the dependency (pure distutils package)
12 # - bdepend -- add it to BDEPEND (the default)
13 # - rdepend -- add it to BDEPEND+RDEPEND (when using entry_points)
14 +# - pyproject.toml -- use pyproject2setuptools to install a project
15 +# using pyproject.toml (flit, poetry...)
16 # - manual -- do not add the depedency and suppress the checks
17 # (assumes you will take care of doing it correctly)
18 #
19 @@ -127,6 +129,9 @@ _distutils_set_globals() {
20 bdep+=" dev-python/setuptools[${PYTHON_USEDEP}]"
21 rdep+=" dev-python/setuptools[${PYTHON_USEDEP}]"
22 ;;
23 + pyproject.toml)
24 + bdep+=" dev-python/pyproject2setuppy[${PYTHON_USEDEP}]"
25 + ;;
26 *)
27 die "Invalid DISTUTILS_USE_SETUPTOOLS=${DISTUTILS_USE_SETUPTOOLS}"
28 ;;
29 @@ -439,6 +444,7 @@ distutils_enable_tests() {
30 _distutils_verify_use_setuptools() {
31 [[ ${DISTUTILS_OPTIONAL} ]] && return
32 [[ ${DISTUTILS_USE_SETUPTOOLS} == manual ]] && return
33 + [[ ${DISTUTILS_USE_SETUPTOOLS} == pyproject.toml ]] && return
34
35 # ok, those are cheap greps. we can try toimprove them if we hit
36 # false positives.
37 @@ -560,6 +566,28 @@ _distutils-r1_disable_ez_setup() {
38 fi
39 }
40
41 +# @FUNCTION: _distutils-r1_handle_pyproject_toml
42 +# @INTERNAL
43 +# @DESCRIPTION:
44 +# Generate setup.py for pyproject.toml if requested.
45 +_distutils-r1_handle_pyproject_toml() {
46 + if [[ ! -f setup.py && -f pyproject.toml ]]; then
47 + if [[ ${DISTUTILS_USE_SETUPTOOLS} == pyproject.toml ]]; then
48 + cat > setup.py <<-EOF || die
49 + #!/usr/bin/env python
50 + from pyproject2setuppy.main import main
51 + main()
52 + EOF
53 + chmod +x setup.py || die
54 + else
55 + eerror "No setup.py found but pyproject.toml is present. In order to enable"
56 + eerror "pyproject.toml support in distutils-r1, set:"
57 + eerror " DISTUTILS_USE_SETUPTOOLS=pyproject.toml"
58 + die "No setup.py found and DISTUTILS_USE_SETUPTOOLS!=pyproject.toml"
59 + fi
60 + fi
61 +}
62 +
63 # @FUNCTION: distutils-r1_python_prepare_all
64 # @DESCRIPTION:
65 # The default python_prepare_all(). It applies the patches from PATCHES
66 @@ -588,6 +616,7 @@ distutils-r1_python_prepare_all() {
67 fi
68
69 _distutils-r1_disable_ez_setup
70 + _distutils-r1_handle_pyproject_toml
71
72 if [[ ${DISTUTILS_IN_SOURCE_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
73 then
74 --
75 2.24.1