1 |
On Sat, 2022-04-09 at 19:08 +0300, Arthur Zamarin wrote: |
2 |
> On 09/04/2022 18.20, Michał Górny wrote: |
3 |
> > Hi, everyone. |
4 |
> > |
5 |
> > TL;DR I think I came up with a feasible plan towards cleanly removing |
6 |
> > dev-python/namespace-* packages that aren't technically needed anymore |
7 |
> > with modern versions of Python. |
8 |
> > |
9 |
> > |
10 |
> > What are namespace packages? Let's take "zope" as an example. |
11 |
> > Normally, various subpackages like "zope.interface" and |
12 |
> > "zope.configuration" would have all to be present in a single directory, |
13 |
> > that is inside the "zope" package. However, if "zope" is made a |
14 |
> > namespace package, its subpackages can be loaded from different |
15 |
> > locations. Notably, in order to test zope.configuration prior to |
16 |
> > installing it, we load it from build tree but its dependency |
17 |
> > zope.interface from system site-packages. |
18 |
> > |
19 |
> > Historically, for this to work, the "zope/__init__.py" had to specify |
20 |
> > some magic incantations. On Gentoo, we've added dev-python/namespace-* |
21 |
> > that installed these magical "__init__.py" files and made all |
22 |
> > subpackages (e.g. dev-python/zope-*) depend on it. |
23 |
> > |
24 |
> > However, Python 3.3 introduced PEP 420 implicit namespaces that made |
25 |
> > magical incantations unnecessary -- if "zope" didn't include |
26 |
> > "__init__.py", it was implicitly treated as a namespace. Unfortunately, |
27 |
> > there were some interoperability issues between the two kinds of magical |
28 |
> > incantations and implicit namespaces. So while we were able to retire |
29 |
> > pkgutil-style namespaces, setuptools-style namespaces remained. |
30 |
> > |
31 |
> > I think we can change that now. |
32 |
> > |
33 |
> > |
34 |
> > I've done some experiments, particularly with dev-python/zope-interface |
35 |
> > and dev-python/zope-configuration. If nobody finds a problem with this |
36 |
> > solution, I think we can aim to bump all packages relying on namespaces |
37 |
> > and retire them in 1-2 months. |
38 |
> > |
39 |
> > The rough idea is to remove RDEP on dev-python/namespace-* from |
40 |
> > the package, and updating python_test to use a temporary pkgutil-style |
41 |
> > incantation (yes, for setuptools-style packages), e.g.: |
42 |
> > |
43 |
> > ``` |
44 |
> > python_compile() { |
45 |
> > distutils-r1_python_compile |
46 |
> > find "${BUILD_DIR}" -name '*.pth' -delete || die |
47 |
> > } |
48 |
> > |
49 |
> > python_test() { |
50 |
> > cd "${BUILD_DIR}/install$(python_get_sitedir)" || die |
51 |
> > # this is needed to keep the tests working while |
52 |
> > # dev-python/namespace-zope is still installed |
53 |
> > cat > zope/__init__.py <<-EOF || die |
54 |
> > __path__ = __import__('pkgutil').extend_path(__path__, |
55 |
> > __name__) |
56 |
> > EOF |
57 |
> > eunittest |
58 |
> > rm zope/__init__.py || die |
59 |
> > } |
60 |
> > ``` |
61 |
> |
62 |
> I quite like that we make the "hack" more local, just in test phase. But |
63 |
> I think this code is quite error prone, and an easy mistake can be made |
64 |
> if someone copies it incorrectly. |
65 |
> |
66 |
> Is it possible to add an eclass function to auto create and cleanup this |
67 |
> file, and all I need to do is to pass it the correct namespace ("zope" |
68 |
> in above example)? |
69 |
> |
70 |
> Also, by using a common function name, it would be easy to fix it if we |
71 |
> did a mistake and find all consumers when we feel safe to cleanup this code. |
72 |
> |
73 |
> One point of failure for this function is how to do the auto cleanup? I |
74 |
> was thinking using environment variables to hold our added magic names, |
75 |
> which is created before `python_test` call and cleans after it is done. |
76 |
> I really prefer if we could call it during prepare phase (so we can |
77 |
> still use auto generated d_e_t calls). |
78 |
> |
79 |
|
80 |
That's pretty much the big problem -- I don't really know. I feel like |
81 |
adding two functions is pretty much error prone itself, especially given |
82 |
that this 'cd' logic is not necessarily correct for other packages. |
83 |
|
84 |
In the end, we're talking about a few ebuilds for period of a few |
85 |
months, so I'm not sure if there's really a point in putting more effort |
86 |
into it. |
87 |
|
88 |
-- |
89 |
Best regards, |
90 |
Michał Górny |