You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/porting.rst
+29-31Lines changed: 29 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,9 +15,9 @@ Step 0 goal: set up and see the tests passing on Python 2 and failing on Python
15
15
a. Clone the package from github/bitbucket. Optionally rename your repo to ``package-future``. Examples: ``reportlab-future``, ``paramiko-future``, ``mezzanine-future``.
16
16
b. Create and activate a Python 2 conda environment or virtualenv. Install the package with ``python setup.py install`` and run its test suite on Py2.7 or Py2.6 (e.g. ``python setup.py test`` or ``py.test`` or ``nosetests``)
17
17
c. Optionally: if there’s a ``.travis.yml`` file, add Python version 3.3 and remove any versions < 2.6.
18
-
d. Install Python 3.3 with e.g. ``sudo apt-get install python3``. On other platforms, an easy way is to use Miniconda3. See `Miniconda3<http://repo.continuum.io/miniconda/index.html>`_. Then e.g.::
18
+
d. Install Python 3.3 with e.g. ``sudo apt-get install python3``. On other platforms, an easy way is to use `Miniconda<http://repo.continuum.io/miniconda/index.html>`_. Then e.g.::
19
19
20
-
conda create -n py33 python=3.3
20
+
conda create -n py33 python=3.3 pip
21
21
22
22
.. _porting-step1:
23
23
@@ -26,20 +26,18 @@ Step 1: modern Py2 code
26
26
27
27
The goal for this step is to modernize the Python 2 code without introducing any dependencies (on ``future`` or e.g. ``six``) at this stage.
28
28
29
-
1a. Install ``future`` into the virtualenv using::
29
+
**1a**. Install ``future`` into the virtualenv using::
30
30
31
31
pip install future
32
32
33
-
1b. Run ``futurize --stage1 -w *.py subdir1/*.py subdir2/*.py``
34
-
35
-
Note that with ``zsh``, you can apply stage1 to all Python source files
36
-
recursively with::
33
+
**1b**. Run ``futurize --stage1 -w *.py subdir1/*.py subdir2/*.py``. Note that with
34
+
``zsh``, you can apply stage1 to all Python source files recursively with::
37
35
38
36
futurize --stage1 -w **/*.py
39
37
40
-
1c. Commit all changes
38
+
**1c**. Commit all changes
41
39
42
-
1d. Re-run the test suite on Py2 and fix any errors.
40
+
**1d**. Re-run the test suite on Py2 and fix any errors.
43
41
44
42
See :ref:`forwards-conversion-stage1` for more info.
45
43
@@ -76,24 +74,24 @@ Step 2: working Py3 code that still supports Py2
76
74
The goal for this step is to get the tests passing first on Py3 and then on Py2
77
75
again with the help of the ``future`` package.
78
76
79
-
2a. Run::
77
+
**2a**. Run::
80
78
81
79
futurize —-stage2 myfolder1/*.py myfolder2/*.py
82
80
83
-
Alternatively, with ``zsh``, you can view the stage 2 changes to all Python source files
84
-
recursively with::
81
+
Alternatively, with ``zsh``, you can view the stage 2 changes to all Python source files
82
+
recursively with::
85
83
86
-
futurize --stage2 **/*.py
84
+
futurize --stage2 **/*.py
87
85
88
-
To apply the changes, add the ``-w`` argument.
86
+
To apply the changes, add the ``-w`` argument.
89
87
90
-
This stage makes further conversions needed to support both Python 2 and 3.
91
-
These will likely require imports from ``future``, such as::
88
+
This stage makes further conversions needed to support both Python 2 and 3.
89
+
These will likely require imports from ``future``, such as::
92
90
93
-
from future import standard_library
94
-
standard_library.install_hooks()
95
-
from future.builtins import bytes
96
-
from future.builtins import open
91
+
from future import standard_library
92
+
standard_library.install_hooks()
93
+
from future.builtins import bytes
94
+
from future.builtins import open
97
95
98
96
Optionally, you can use the ``--unicode-literals`` flag to adds this further
99
97
import to the top of each module::
@@ -109,23 +107,23 @@ Python 3 semantics on Python 2, invoke it like this::
109
107
futurize --stage2 --all-imports myfolder/*.py
110
108
111
109
112
-
2b. Re-run your tests on Py3 now. Make changes until your tests pass on Python 3.
110
+
**2b**. Re-run your tests on Py3 now. Make changes until your tests pass on Python 3.
113
111
114
-
2c. Commit your changes! :)
112
+
**2c**. Commit your changes! :)
115
113
116
-
2d. Now run your tests on Python 2 and notice the errors. Add wrappers from ``future`` to re-enable Python 2 compatibility:
114
+
**2d**. Now run your tests on Python 2 and notice the errors. Add wrappers from ``future`` to re-enable Python 2 compatibility:
117
115
118
-
- :func:`utils.reraise()` function for raising exceptions compatibly
119
-
- ``bytes(b'blah')`` instead of ``b'blah'``
120
-
- ``str('my string')`` instead of ``'my string'`` if you need to enforce Py3’s strict type-checking on Py2
121
-
- ``int(1234)`` instead of ``1234`` if you want to enforce a Py3-like long integer
122
-
- :func:`@utils.implements_iterator` decorator for any custom iterator class with a ``.__next__()`` method (which used to be ``.next()``)
123
-
- :func:`@utils.python_2_unicode_compatible` decorator for any class with a ``__str__`` method (which used to be ``__unicode__``).
124
-
- :func:`utils.with_metaclass` to define any metaclasses.
116
+
- :func:`utils.reraise()` function for raising exceptions compatibly
117
+
- ``bytes(b'blah')`` instead of ``b'blah'``
118
+
- ``str('my string')`` instead of ``'my string'`` if you need to enforce Py3’s strict type-checking on Py2
119
+
- ``int(1234)`` instead of ``1234`` if you want to enforce a Py3-like long integer
120
+
- :func:`@utils.implements_iterator` decorator for any custom iterator class with a ``.__next__()`` method (which used to be ``.next()``)
121
+
- :func:`@utils.python_2_unicode_compatible` decorator for any class with a ``__str__`` method (which used to be ``__unicode__``).
122
+
- :func:`utils.with_metaclass` to define any metaclasses.
125
123
126
124
See :ref:`what-else` for more info.
127
125
128
126
After each change, re-run the tests on Py3 and Py2 to ensure they pass on both.
129
127
130
-
2e. You’re done! Celebrate! Push your code and announce to the world! Hashtags
128
+
**2e.** You’re done! Celebrate! Push your code and announce to the world! Hashtags
0 commit comments