3ee3d08b812ab5ca8db26b463626fc116967dac9
[gentoo.git] / dev-python / twisted / twisted-20.3.0.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python3_{6,7,8,9} )
7 PYTHON_REQ_USE="threads(+)"
8
9 inherit distutils-r1 virtualx
10
11 TWISTED_PN="Twisted"
12 TWISTED_P="${TWISTED_PN}-${PV}"
13 TWISTED_RELEASE=$(ver_cut 1-2)
14
15 DESCRIPTION="An asynchronous networking framework written in Python"
16 HOMEPAGE="https://www.twistedmatrix.com/trac/"
17 SRC_URI="https://twistedmatrix.com/Releases/${TWISTED_PN}"
18 SRC_URI="${SRC_URI}/${TWISTED_RELEASE}/${TWISTED_P}.tar.bz2
19         https://dev.gentoo.org/~mgorny/dist/twisted-regen-cache.gz"
20
21 KEYWORDS="~alpha amd64 arm ~arm64 ~mips ppc64 ~s390 sparc x86 ~amd64-linux ~x86-linux"
22
23 LICENSE="MIT"
24 SLOT="0"
25 IUSE="conch crypt http2 serial test"
26 RESTRICT="!test? ( test )"
27
28 RDEPEND="
29         >=dev-python/attrs-19.2.0[${PYTHON_USEDEP}]
30         >=dev-python/automat-0.3.0[${PYTHON_USEDEP}]
31         >=dev-python/constantly-15.1.0[${PYTHON_USEDEP}]
32         >=dev-python/hyperlink-17.1.1[${PYTHON_USEDEP}]
33         >=dev-python/incremental-16.10.1[${PYTHON_USEDEP}]
34         >=dev-python/pyhamcrest-1.9.0[${PYTHON_USEDEP}]
35         >=dev-python/zope-interface-4.4.2[${PYTHON_USEDEP}]
36         conch? (
37                 dev-python/pyasn1[${PYTHON_USEDEP}]
38                 >=dev-python/cryptography-1.5.0[${PYTHON_USEDEP}]
39                 >=dev-python/appdirs-1.4.0[${PYTHON_USEDEP}]
40         )
41         crypt? (
42                 >=dev-python/pyopenssl-16.0.0[${PYTHON_USEDEP}]
43                 dev-python/service_identity[${PYTHON_USEDEP}]
44                 >=dev-python/idna-0.6[${PYTHON_USEDEP}]
45         )
46         serial? ( >=dev-python/pyserial-3.0[${PYTHON_USEDEP}] )
47         http2? (
48                 >=dev-python/hyper-h2-3.0.0[${PYTHON_USEDEP}]
49                 <dev-python/hyper-h2-4.0.0[${PYTHON_USEDEP}]
50                 >=dev-python/priority-1.1.0[${PYTHON_USEDEP}]
51                 <dev-python/priority-2.0[${PYTHON_USEDEP}]
52         )
53         !dev-python/twisted-core
54         !dev-python/twisted-conch
55         !dev-python/twisted-lore
56         !dev-python/twisted-mail
57         !dev-python/twisted-names
58         !dev-python/twisted-news
59         !dev-python/twisted-pair
60         !dev-python/twisted-runner
61         !dev-python/twisted-words
62         !dev-python/twisted-web
63 "
64 DEPEND="
65         dev-python/bcrypt
66         >=dev-python/incremental-16.10.1[${PYTHON_USEDEP}]
67         test? (
68                 dev-python/gmpy[${PYTHON_USEDEP}]
69                 dev-python/pyasn1[${PYTHON_USEDEP}]
70                 >=dev-python/cryptography-0.9.1[${PYTHON_USEDEP}]
71                 >=dev-python/appdirs-1.4.0[${PYTHON_USEDEP}]
72                 >=dev-python/pyopenssl-0.13[${PYTHON_USEDEP}]
73                 dev-python/service_identity[${PYTHON_USEDEP}]
74                 dev-python/idna[${PYTHON_USEDEP}]
75                 dev-python/pyserial[${PYTHON_USEDEP}]
76                 >=dev-python/constantly-15.1.0[${PYTHON_USEDEP}]
77                 net-misc/openssh
78         )
79 "
80
81 S=${WORKDIR}/${TWISTED_P}
82
83 python_prepare_all() {
84         local PATCHES=(
85                 "${FILESDIR}"/twisted-20.3.0-py38-cgi.patch
86                 "${FILESDIR}"/twisted-20.3.0-py38-hmac.patch
87                 "${FILESDIR}"/twisted-20.3.0-py39-b64.patch
88                 "${FILESDIR}"/twisted-20.3.0-py39-combined.patch
89         )
90
91         # upstream test for making releases; not very useful and requires
92         # sphinx (including on py2)
93         rm src/twisted/python/test/test_release.py || die
94
95         # Conch doesn't work with latest >=OpenSSH 7.6
96         #   - https://twistedmatrix.com/trac/ticket/9311
97         #   - https://twistedmatrix.com/trac/ticket/9515
98         rm src/twisted/conch/test/test_ckeygen.py || die
99         rm src/twisted/conch/test/test_conch.py || die
100         rm src/twisted/conch/test/test_cftp.py || die
101
102         # puts system in EMFILE state, then the exception handler may fail
103         # trying to open more files due to some gi magic
104         sed -e '/SKIP_EMFILE/s:None:"Fails on non-pristine systems":' \
105                 -i src/twisted/internet/test/test_tcp.py || die
106
107         # multicast tests fail within network-sandbox
108         sed -e 's:test_joinLeave:_&:' \
109                 -e 's:test_loopback:_&:' \
110                 -e 's:test_multiListen:_&:' \
111                 -e 's:test_multicast:_&:' \
112                 -i src/twisted/test/test_udp.py || die
113
114         # accesses /dev/net/tun
115         sed -e '/class RealDeviceTestsMixin/a\
116     skip = "Requires extra permissions"' \
117                 -i src/twisted/pair/test/test_tuntap.py || die
118
119         # TODO: figure it out, probably doesn't accept DST date here
120         sed -e 's:test_getTimezoneOffsetWithoutDaylightSavingTime:_&:' \
121                 -i src/twisted/test/test_log.py || die
122
123         # TODO: failures specific to Python 2
124         sed -e 's:testLookupProcNetTcp:_&:' \
125                 -i src/twisted/test/test_ident.py || die
126         sed -e 's:test_loggingFactoryOpensLogfileAutomatically:_&:' \
127                 -i src/twisted/test/test_policies.py || die
128
129         distutils-r1_python_prepare_all
130 }
131
132 src_test() {
133         virtx distutils-r1_src_test
134 }
135
136 python_test() {
137         # TODO: upstream seems to override our build paths
138         distutils_install_for_testing
139
140         "${EPYTHON}" -m twisted.trial twisted ||
141                 die "Tests failed with ${EPYTHON}"
142 }
143
144 python_install() {
145         distutils-r1_python_install
146
147         cd "${D}$(python_get_sitedir)" || die
148
149         # own the dropin.cache so we don't leave orphans
150         touch twisted/plugins/dropin.cache || die
151
152         python_doscript "${WORKDIR}"/twisted-regen-cache
153 }
154
155 python_install_all() {
156         distutils-r1_python_install_all
157
158         newconfd "${FILESDIR}/twistd.conf" twistd
159         newinitd "${FILESDIR}/twistd.init" twistd
160 }
161
162 python_postinst() {
163         twisted-regen-cache || die
164 }
165
166 pkg_postinst() {
167         python_foreach_impl python_postinst
168
169         einfo "Install complete"
170         if use test ; then
171                 einfo ""
172                 einfo "Some tests have been disabled during testing due to"
173                 einfo "known incompatibilities with the emerge sandboxes and/or"
174                 einfo "not runnable as the root user."
175                 einfo "For a complete test suite run on the code."
176                 einfo "Run the tests as a normal user for each python it is installed to."
177                 einfo "  ie:  $ python3.6 /usr/bin/trial twisted"
178         fi
179 }
180
181 python_postrm() {
182         rm -f "${ROOT}$(python_get_sitedir)/twisted/plugins/dropin.cache" || die
183 }
184
185 pkg_postrm() {
186         # if we're removing the last version, remove the cache file
187         if [[ ! ${REPLACING_VERSIONS} ]]; then
188                 python_foreach_impl python_postrm
189         fi
190 }