Skip to content
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

Merged
merged 2 commits into from Jan 23, 2017
Merged

Conversation

jcdyer
Copy link

@jcdyer jcdyer commented Sep 7, 2016

Plan for migrating Open edX code to Python 3.

@jcdyer jcdyer force-pushed the cdyer/oep-0007-python3-migration branch from 2c667bb to a65f2cd Compare September 23, 2016 17:43
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

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,

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.

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
+++++++++++++++++++++++++
Copy link
Author

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>` |
Copy link
Contributor

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
Copy link
Author

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.

Copy link
Author

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.

@jcdyer jcdyer changed the title [WIP] OEP-7: python3 migration plan OEP-7: python3 migration plan Oct 27, 2016

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

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
++++++++++++++

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

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):

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

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

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
...........................................
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Author

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
Copy link
Contributor

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.

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
Copy link
Contributor

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
Copy link
Contributor

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"

@jcdyer jcdyer changed the title OEP-7: python3 migration plan OEP-7: Python 3 migration plan Nov 18, 2016
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"and and"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@jcdyer
Copy link
Author

jcdyer commented Jan 17, 2017

@jmbowman: I think I've responded to all your concerns. Please take another look.

Copy link
Contributor

@jmbowman jmbowman left a 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.
Copy link
Contributor

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

@jcdyer jcdyer force-pushed the cdyer/oep-0007-python3-migration branch 2 times, most recently from b834e4e to 696b257 Compare January 17, 2017 21:10
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
Copy link
Contributor

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...

Copy link
Contributor

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.

Copy link
Author

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
Copy link
Contributor

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
Copy link
Contributor

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 | |
Copy link
Contributor

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).

Copy link
Author

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``).

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@pdpinch
Copy link
Contributor

pdpinch commented Jan 20, 2017

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.

@jcdyer
Copy link
Author

jcdyer commented Jan 20, 2017

Great idea @pdpinch. I'll add that in.

@pdpinch
Copy link
Contributor

pdpinch commented Jan 20, 2017

credit should go to @Colin-Fredericks for calling it out -- I'm just a (very) interested party

@jcdyer jcdyer force-pushed the cdyer/oep-0007-python3-migration branch from 9da45bd to 9211365 Compare January 20, 2017 22:02
@jcdyer
Copy link
Author

jcdyer commented Jan 20, 2017

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.)

@Colin-Fredericks
Copy link

@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.

@jcdyer
Copy link
Author

jcdyer commented Jan 23, 2017

@Colin-Fredericks Think big hair.

@jmbowman I believe this OEP is ready to merge.

@jcdyer jcdyer force-pushed the cdyer/oep-0007-python3-migration branch from 9211365 to 85563ae Compare January 23, 2017 20:26
@jcdyer jcdyer force-pushed the cdyer/oep-0007-python3-migration branch from 85563ae to 3e170cc Compare January 23, 2017 20:27
Copy link
Contributor

@jmbowman jmbowman left a 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.

@jcdyer jcdyer merged commit a0b9a92 into master Jan 23, 2017
@feanil feanil deleted the cdyer/oep-0007-python3-migration branch May 23, 2019 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet