New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python 3 Anaconda #122
Python 3 Anaconda #122
Conversation
Popen returns bytes by default, use a helper method to turn on universal_newlines so that the return values are strings as expected. Update urllib interface for python3 changes. proxy handling is done with a ProxyHandler which needs to be installed before opening the url.
Or else there will be issues such as missing overrides.
Imputils does not publicly provide the imp module and also does not exist anymore in Python 3. Importing imp directly should work fine in both Python 2 and 3.
Python 3 is the future.
Queue has been renamed to queue and ConfigParser to configparser in Python 3. Also make sure that we don't shadow the queue module by renaming all "queue" variables to "queue_instance".
The parse-kickstart script used for anaconda-dracut emits cmdline strings and creates ifcfg files for network settings. Test these to make sure they are working correctly. (cherry picked from commit 9546d9ede8754ab67bdbd3efd7d8c6bc2bf52ec3)
python-deps should print the unique list of files Add site.py and sysconfig.py dependencies to python-deps Make sure to pick up any dependencies they have by running them through modulefinder. Add PYTHONHASHSEED to python-deps call When creating boot images dracut is run in a minimal chroot with no /dev/urandom, setting PYTHONHASHSEED lets python3 run without it. The seed is used for hashing object ids. It is not used for anything requiring security.
Also Drop the unicode (c) from parse-kickstart It causes modulefinder to choke when reading the file. Arguably a bug with modulefinder, but it solves things for now.
The vncpasswd utility returns binary output.
The subprocess module returns bytes in Python 3, so we need to (try) decoding the output (as utf-8) for functions that expect text string output and there is now a execWithCaptureBinary for forwarding binary output when running commands. We also need to make sure that the output is "printable" when binary output logging to the program.log is enabled.
In the places where Anaconda expects the program to returna string.
The when the correct Unicode normalisation method has been set (NFKD), we need to replace the old bogus values with correct ones in the ASCII conversion tests.
All strings are Unicode strings in Python, so remove tests that check if a string is Unicode or not.
Also fix the normalisation method string - it should be "NFKD", not "NKFD".
It was used to force utf-8 as default encoding, which is no longer needed in Python 3.
The os.write() function works with bytes, as does the IP address unpacking function. But ProxyString needs a string to prevent various (often cryptic) issues with quote/unquote expecting/returning str/bytes instances.
This is useful in many places where we are never sure if we get str or bytes and we need/want to work with str objects. Also remove one related (previously) unused import and obsolete comment & needless encoding.
For example rpm and vncconfig.
StringTypes is now str, UnicodeType is also str and StringType is bytes.
In Python 3 exceptions don't (necessarily) have the 'message' attribute. Just use the str(e) call instead.
In Python 2 calling map() returned a list, which had the side effect of running the given function on all items in the provided iterable, even if the result of the map() call was not used. On the other hand in Python 3 map() returns an iterator and the mapped function is not applied on the iterable until items are yielded from the iterator. In short any map() usage that does not use the iterable **does nothing** in Python 3.
During population/refresh of the spoke checks may not be set up yet when widgets change their state.
In Python 3 it is not hashable and it was never meant to be on Python 2 neither.
This results in seek errors in Python 3. Use "wb" instead with the same result in this case.
Access to class level variables from list comprehension no longer works in Python 3, so replace it with a for cycle.
It was shadowing the Python standard library warnings module. The py-compile script used by autotools to generate bytecode for Python modules is stupid enough to *prepend* its PWD to PYTHONPATH and because of that it trying to import the warnings spoke in place of the warnings module, breaking the Anaconda package build.
So if we modify the named tempfile externally, we need to also externally open it to get the externally added content.
We should open temporary files in text mode if we want to write text strings into them or get text back - tempfiles use the binary mode by default in Python 3.
The Python 3 C extension API has a revamped module initialization code and also some of the autotools Python stuff needed to be changed.
Both in functions and in lambdas - Python 3 lambda will not unpack the tuple into named arguments. Instead, each argument will need to be referenced by its positional index.
Various issues such as: - iterators need to be converted to lists before joining to a single list - iterator need to be converted to a list before doing indexed access or using other list specific API on it - trying to add a dict_values to a list - adding lists and dict_values together - use chaining in the above two cases
Strings are Unicode by default in Python 3 and don't need to be decoded. Also don't do needless encoding and decoding in general.
Urllib functionality has been split into a number of submodules in Python 3.
None to int comparison became an illegal operation in Python 3.
While Python 2 tolerates numeric comparisons between None and integers (like for example None > 0), Python 3 no longer tolerates this and considers it to be an error.
The __cmp__() function is no longer available in Python 3.
Wrap compare functions and make them into key functions or forward port the cmp function.
Division ( / ) returns floating point numbers in Python 3, so use floor division ( // ) to always get an int.
Division always returns a float in Python 3, so it is more likely a float might end in set_system_time(). So wrap the value with int() before calling the function.
Make it possible to run makeupdates without the yum-utils Python module being available. We are now running makeupdates with Python 3 but yum is Python 2 only, so the yum-utils package will never be available.
Division always returns a float in Python 3.
Don't use the (deprecated in Python 3) _safechars private property of the pipes module. Generate the set of safe characters locally instead.
Weeeee!!!!! :) I think you can drop the bug reference in all the commits above. |
@vpodzime I've actually used it on purpose and would like to keep it, so that we can easily identify the Python 3 supports commits in the future. |
@clumens makeupdates is using just some version comparison code from yum-utils, I'll look for a different provider of that (I'm sure DNF needs to have something similar). |
This PR looks ok to me. |
Pushed manually. |
This pull request changes Anaconda to use Python 3 as requested in the "Python 3 as Default" Fedora change proposal[0] and tracked in bug 1014220[1]. All Python 2-only dependencies are also dropped and replaced by Python 3 equivalents. Please note that this is a forward port to Python 3 without keeping Python 2 compatibility.
[0] https://fedoraproject.org/wiki/Changes/Python_3_as_Default
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1014220