1 |
Hi all- |
2 |
|
3 |
First, thanks for the great tool. I've been using Gentoo for about 10 |
4 |
years, and I use Catalyst to build custom Gentoo live CDs that contain |
5 |
extra software (e.g. netcat6, rsync, ddrescue, etc.). |
6 |
|
7 |
At some point in the past the stage3 tarballs only contained Python 3, |
8 |
though it looks like the 20130516 amd64 stage3 contains both 2.7 and |
9 |
3.2. It's reasonable to assume that any current Gentoo system has a |
10 |
Python 3.2+ interpreter, so is there any objection to making Catalyst |
11 |
work on Python 3? The fewer things in the world that depend on Python 2, |
12 |
the better (in my opinion). Portage has supported Python 3 for some time |
13 |
and it makes sense for Catalyst to follow suit. |
14 |
|
15 |
I use Python 3 for all of my own work and have a reasonable amount of |
16 |
experience porting projects to Python 3. This typically involves a lot |
17 |
of code churn even when there aren't any logic changes -- every print |
18 |
statement has to be converted to calling the print function, for |
19 |
instance. Explicit conversion between bytes and str can require a bit |
20 |
more thought but isn't difficult. |
21 |
|
22 |
This conversion might require other miscellaneous cleanup, including |
23 |
some whitespace-only commits. Python 3 does not allow mixing tabs and |
24 |
spaces for indentation, and (e.g.) catalyst_support.py is a *mess* with |
25 |
indentation. PyCharm also notices things like unnecessary "\" line |
26 |
continuation characters, unused variables, mutable default arguments |
27 |
(e.g. catalyst_support.spawn's "env"), equality comparisons against |
28 |
None, and unreachable code (lines 183 - 220 of catalyst_lock.py). |
29 |
|
30 |
It looks like the project has mostly standardized on using tabs for |
31 |
indentation, so that's what I'll use when changing indentation is necessary. |
32 |
|
33 |
In any case, over the next few weeks/months I'll prepare a series of |
34 |
patches in decreasing order of priority: |
35 |
|
36 |
1. Changes required to run 2to3, like changing string exceptions (e.g. |
37 |
catalyst_lock.py:34) to 'raise Exception("message")' |
38 |
2. Automated 2to3 conversion |
39 |
3. Minimal indentation changes required for Python 3 to parse the code |
40 |
(as I mentioned, the diff of catalyst_support.py will still be quite |
41 |
large) |
42 |
4. Any required bytes/str fixes and other things that 2to3 isn't smart |
43 |
enough to do on its own |
44 |
5. Miscellaneous style tweaks (some of which are suggested by PEP 8), like: |
45 |
1. using os.path.join where appropriate (e.g. grp_target.py:38, |
46 |
catalyst_lock.py:80) |
47 |
2. using context managers ("with open(filename) as f:") |
48 |
3. replacing mutable default function arguments |
49 |
4. using argparse instead of getopt in the main catalyst script (maybe) |
50 |
5. catching Exception instead of using a raw 'except:' -- probably |
51 |
don't want to catch SystemExit, StopIteration and |
52 |
KeyboardInterrupt in a lot of these places |
53 |
6. Other PEP 8-inspired changes like using spaces around operators and |
54 |
function arguments |
55 |
|
56 |
The intention is that categories 1 through 4 would be the minimum set of |
57 |
changes required to make Catalyst run on Python 3. Categories 5 and 6 |
58 |
would be a mix of PEP 8 and newer Python idioms and applying these would |
59 |
be optional. |
60 |
|
61 |
I'm not a Gentoo developer and I'll be making a lot of small commits, so |
62 |
sharing my changes will probably be easiest by publishing a clone of the |
63 |
Catalyst repository on GitHub. (I plan to make/test/release all of these |
64 |
changes whether or not they'll make it in to Catalyst in the near |
65 |
future. Even if the Gentoo releng team doesn't care about supporting |
66 |
Python 3 now, having a working port available might make it easier to |
67 |
justify that change in the future :) ) |
68 |
|
69 |
Thanks for your time and any feedback, |
70 |
MMR... |
71 |
-- |
72 |
Matthew Ruffalo |
73 |
Department of Electrical Engineering and Computer Science |
74 |
Case Western Reserve University |