Skip to content

Commit 6ad4975

Browse files
committed
Update porting cheat-sheet
1 parent 27ee197 commit 6ad4975

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

docs/porting.rst

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Step 0 goal: set up and see the tests passing on Python 2 and failing on Python
1515
a. Clone the package from github/bitbucket. Optionally rename your repo to ``package-future``. Examples: ``reportlab-future``, ``paramiko-future``, ``mezzanine-future``.
1616
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``)
1717
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.::
1919
20-
conda create -n py33 python=3.3
20+
conda create -n py33 python=3.3 pip
2121

2222
.. _porting-step1:
2323

@@ -26,20 +26,18 @@ Step 1: modern Py2 code
2626

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

29-
1a. Install ``future`` into the virtualenv using::
29+
**1a**. Install ``future`` into the virtualenv using::
3030
3131
pip install future
3232
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::
3735

3836
futurize --stage1 -w **/*.py
3937

40-
1c. Commit all changes
38+
**1c**. Commit all changes
4139

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

4442
See :ref:`forwards-conversion-stage1` for more info.
4543

@@ -76,24 +74,24 @@ Step 2: working Py3 code that still supports Py2
7674
The goal for this step is to get the tests passing first on Py3 and then on Py2
7775
again with the help of the ``future`` package.
7876

79-
2a. Run::
77+
**2a**. Run::
8078

8179
futurize —-stage2 myfolder1/*.py myfolder2/*.py
8280

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

86-
futurize --stage2 **/*.py
84+
futurize --stage2 **/*.py
8785

88-
To apply the changes, add the ``-w`` argument.
86+
To apply the changes, add the ``-w`` argument.
8987

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

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
9795

9896
Optionally, you can use the ``--unicode-literals`` flag to adds this further
9997
import to the top of each module::
@@ -109,23 +107,23 @@ Python 3 semantics on Python 2, invoke it like this::
109107
futurize --stage2 --all-imports myfolder/*.py
110108

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

114-
2c. Commit your changes! :)
112+
**2c**. Commit your changes! :)
115113

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

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

126124
See :ref:`what-else` for more info.
127125

128126
After each change, re-run the tests on Py3 and Py2 to ensure they pass on both.
129127

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
131129
#python3 #python-future.

0 commit comments

Comments
 (0)