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
OEP-7: Python 3 migration plan #21
Conversation
2c667bb
to
a65f2cd
Compare
With primary development of Python occurring on Python 3, and with Python 2 | ||
scheduled for end-of-life in 2020, edX needs to plan for a transition of all of | ||
our code to Python 3. Open edX is a large project, spanning many applications | ||
over even more github repos, with even more dependencies on third party |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/github repos/repositories
our code to Python 3. Open edX is a large project, spanning many applications | ||
over even more github repos, with even more dependencies on third party | ||
libraries. This document outlines how we plan to scope the problem, socialize | ||
understanding of the differences between versions of python, migrate our code, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalize Python
Rationale | ||
========= | ||
|
||
* Python 2 will only receive support from the python core devs until 2020. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalize Python.
|
||
|
||
Choosing a python version | ||
+++++++++++++++++++++++++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why polyglot?
OEP-0007: Migrating to Python 3 | ||
=============================== | ||
+---------------+-------------------------------------------+ | ||
| OEP | :doc:`OEP-7 </oeps/oep-0007>` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you rebase onto master, you'll need to change this to <oep-0007>
.
Choosing a python version | ||
+++++++++++++++++++++++++ | ||
|
||
All greenfield python projects should be written using python 3 unless a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/greenfield/new/
solution, edX will maintain a repository of compatibility shims (edx-compat?). | ||
Ideally, all edx-maintained code that implements different behavior based on | ||
python version will be in this repo. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Packaging: Use proper trove classifiers.
|
||
All files should have the main `__future__` imports at the top to regularize | ||
some behaviors that differ by default between Python 2 and 3. `from | ||
__future__ import absolute_import` forbid the use of implicit relative |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: these would be more readable as a list
|
||
Migrating code | ||
++++++++++++++ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have links to six and future's documentation somewhere in this document
........................................... | ||
|
||
In order to write code that looks as much like native Python 3 as possible, | ||
you may want to use `from __future__ import unicode_literals`, which makes bare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this
does not make code formatting, it makes quote formatting
work to change after the fact. This can be avoided in some cases by iterating | ||
directly over the dict object. Instead of using: | ||
|
||
for key, value in six.viewitems(d): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These format as quote blocks, not code blocks
-------------- | ||
|
||
If you find other incompatibilities, a shim will likely be found in [the `six` | ||
library](https://pythonhosted.org/six/). For incompatibilies with no other |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, here's the link. It probably should've been up at the first reference.
arise during migration. | ||
|
||
Appropriate tooling will help. Tests should be configured to run under both | ||
Python 2 or 3 (tox helps with this). As it would double the cost of running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link to tox
Before converting a codebase to Python 3, we need to make sure the code we | ||
depend on will also support Python 3. We can make a rough check for | ||
third-party library support using the [Can I Use Python 3 website or | ||
library](https://caniusepython3.com/). This will sometimes show inaccurate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link and 5 others below use Markdown formatting, but this is a reStructuredText document. They need to be updated to render correctly in the output.
possible, we will use unambiguous text or byte objects. In most cases, text | ||
should be preferred. Bytes should only be used when you can answer the | ||
question: "Do I need this specific sequence of bytes." The most | ||
error-resistent way to acheive this is to use what is called a "unicode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling: resistent -> resistant
bytes-oriented library). The only operation that should (ideally) be performed | ||
on bytes is decoding. | ||
|
||
In those cases where ambiguity is required (such as working with libraries like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The matching close parenthesis is missing
developers working on that project. | ||
|
||
Handling literals, Option 1: Python 3-Style | ||
........................................... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Periods don't seem to be among the valid section header underline characters
|
||
native = 'string' # pylint: disable=native-string | ||
|
||
This version creates noisier code than Option 2, below, but makes it easier to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is Option 2; did you mean to reference Option 1 above?
Programming Language :: Python :: 2 | ||
Programming Language :: Python :: 2 :: Only | ||
Programming Language :: Python :: 3 | ||
Programming Language :: Python :: 3 :: Only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The odd-numbered lines from these blocks are being omitted from the output; the colons are probably throwing off the formatting somehow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shows up now. I'm not sure if I changed something or not.
Appropriate tooling will help. Tests should be configured to run under both | ||
Python 2 or 3 (tox helps with this). As it would double the cost of running | ||
tests to run both all the time, we may only want to enable Python 3 tests in | ||
the CI environment for repos that are actively being migrated. We still want |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extra test runs shouldn't matter for repos that use Travis, as they're run in parallel on external hardware and don't incur usage fees.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They will eat into our available travis workers, which we're already a little short on, leading to more queue backup and longer delays for tests to run.
* Deploy xblocks separately to test remote execution | ||
* Migrate to Python 3 | ||
* Upgrade external xblocks as needed, and support partners who wish to do the | ||
same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't valid rst formatting for nested lists; the type of bullet needs to change for the 2nd level
Deploying Services | ||
++++++++++++++++++ | ||
|
||
Once a service has been achieved full Python 3 compatibility, we will need to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar, probably just need to drop "been"
where each one is preferable. The two options are `six`, and `future`. | ||
|
||
Six is a simple compatibility library. If something works differently in | ||
Python 2 and and Python 3, you import six, and use functions that it provides |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"and and"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
@jmbowman: I think I've responded to all your concerns. Please take another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last formatting nitpick, other than that looks good.
|
||
* IDAs that we want to continue supporting in the future | ||
+ Old IDAs (that we want to replace) should not be upgraded, but we will need | ||
to prioritize replacement to occur during the migration timeframe. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nested bullets here and in the third bullet point need to be separated by blank lines from the parent list items to be formatted correctly
b834e4e
to
696b257
Compare
Appropriate tooling will help. Tests should be configured to run under both | ||
Python 2 or 3 using tox. As it would double the cost of running | ||
tests to run both all the time, we may only want to enable Python 3 tests in | ||
the CI environment for repos that are actively being migrated. We still want |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't worry about this. We are building our CI infrastructure for scale. If we reach a point where we can't support what we need to do, then we can think about removing pieces...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, technically...due to our billing, prices won't be doubled by using more builds in Travis, for example. So the statement is inaccurate. I argue that you remove this value statement altogether; we should just test what we need to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Ben. That's helpful information.
|
||
|
||
New libraries should additionally support Python 2 using a single code-base | ||
with Six_ as a compatibility layer if they will be used by projects that run on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have, at times, struggled with different libraries requiring different versions of six
.
can use ``futurize``, and what other work needs to be done. | ||
|
||
|
||
Deploying Services |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could remove this section. This is true of all significant changes like this and only applicable to edx.org
+---------------+-------------------------------------------+ | ||
| Author | Cliff Dyer <cdyer@edx.org> | | ||
+---------------+-------------------------------------------+ | ||
| Arbiter | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to update this with the actual arbiter (not sure who it is for this OEP).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
statement. | ||
* ``from __future__ import division`` will make single-slash division | ||
(``a / b``) always perform floating point division, and double-slash division | ||
(``a // b``). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incomplete sentence. Should read and double slash division ("a // b") perform integer division
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Since course content can contain python code, I think you need a section that addresses it specifically. I presume the python version is controlled by the sandbox setting. But I think there's a feature flag for disabling the sandbox, in which case I think python in courseware would use the same version that edx-platform is running on. |
Great idea @pdpinch. I'll add that in. |
credit should go to @Colin-Fredericks for calling it out -- I'm just a (very) interested party |
9da45bd
to
9211365
Compare
Thanks @Colin-Fredericks! I've added language to address that in the "Order of Migrations" section, under "edx-platform". (Also, I think we went to high school together.) |
@jcdyer Huh! So we did! Now I need to dig out my old 1996 NMH Facebook and find your picture. Thanks for the help here. |
@Colin-Fredericks Think big hair. @jmbowman I believe this OEP is ready to merge. |
9211365
to
85563ae
Compare
85563ae
to
3e170cc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to go! Just update the Status and Resolution fields accordingly.
Plan for migrating Open edX code to Python 3.