• Home
  • Raw
  • Download

Lines Matching full:your

12    use, it is good to have your project available for both major releases of
29 To make your project be single-source Python 2/3 compatible, the basic steps
36 #. Use Futurize_ (or Modernize_) to update your code (e.g. ``python -m pip install future``)
37 #. Use Pylint_ to help make sure you don't regress on your Python 3 support
39 #. Use caniusepython3_ to find out which of your dependencies are blocking your
41 #. Once your dependencies are no longer blocking you, use continuous integration
44 #. Consider using optional static type checking to make sure your type usage
45 works in both Python 2 & 3 (e.g. use mypy_ to check your typing under both
59 **today**! Even if your dependencies are not supporting Python 3 yet that does
60 not mean you can't modernize your code **now** to support Python 3. Most changes
64 Another key point is that modernizing your Python 2 code to also support
71 your code to support Python 2 & 3 simultaneously.
84 to your code should continue to look and feel like idiomatic Python code. At
97 Make sure you specify the proper version support in your ``setup.py`` file
100 In your ``setup.py`` file you should have the proper `trove classifier`_
101 specifying what versions of Python you support. As your project does not support
111 Once you have your code supporting the oldest version of Python 2 you want it
112 to, you will want to make sure your test suite has good coverage. A good rule of
113 thumb is that if you want to be confident enough in your test suite that any
114 failures that appear after having tools rewrite your code are actual bugs in the
115 tools and not in your code. If you want a number to aim for, try to get over 80%
124 Once you have your code well-tested you are ready to begin porting your code to
125 Python 3! But to fully understand how your code is going to change and what
133 Update your code
137 it's time to update your code! You have a choice between two tools in porting
138 your code automatically: Futurize_ and Modernize_. Which tool you choose will
139 depend on how much like Python 3 you want your code to be. Futurize_ does its
148 Regardless of which tool you choose, they will update your code to run under
151 your test suite first and visually inspect the diff to make sure the
152 transformation is accurate. After you have transformed your test suite and
153 verified that all the tests still pass as expected, then you can transform your
156 Unfortunately the tools can't automate everything to make your code work under
161 for you and what you may have to fix on your own (e.g. using ``io.open()`` over
175 have not been doing this then you will need to go through your code and do two
178 #. Add ``from __future__ import division`` to your files
183 an object defines a ``__truediv__`` method but not ``__floordiv__`` then your
240 decoding between binary data and text at the edge of your code. This means that
242 your code needs to send text as binary data then encode it as late as possible.
243 This allows your code to work with only text internally and thus eliminates
246 The next issue is making sure you know whether the string literals in your code
288 #. Decide which of your APIs take text and which take binary data
289 #. Make sure that your code that works with text also works with ``unicode`` and
348 Once you have fully translated your code to be compatible with Python 3, you
349 will want to make sure your code doesn't regress and stop working under
361 compatibility issues your code triggers during execution. If you turn warnings
365 You can also use the Pylint_ project and its ``--py3k`` flag to lint your code
366 to receive warnings when your code begins to deviate from Python 3
368 over your code regularly to catch compatibility regressions. This does require
373 Check which dependencies block your transition
376 **After** you have made your code compatible with Python 3 you should begin to
377 care about whether your dependencies have also been ported. The caniusepython3_
383 The project also provides code which you can integrate into your test suite so
385 you from using Python 3. This allows you to avoid having to manually check your
389 Update your ``setup.py`` file to denote Python 3 compatibility
392 Once your code works under Python 3, you should update the classifiers in
393 your ``setup.py`` to contain ``Programming Language :: Python :: 3`` and to not
394 specify sole Python 2 support. This will tell anyone using your code that you
402 Once you are able to fully run under Python 3 you will want to make sure your
404 your tests under multiple Python interpreters is tox_. You can then integrate
405 tox with your continuous integration system so that you never accidentally break
411 comparisons simply return ``False``, but if you made a mistake in your
416 And that's mostly it! At this point your code base is compatible with both
417 Python 2 and 3 simultaneously. Your testing will also be set up so that you
419 you typically run your tests under while developing.
425 Another way to help port your code is to use a static type checker like
426 mypy_ or pytype_ on your code. These tools can be used to analyze your code as
428 your code is running under Python 3. By running a static type checker twice like
430 of Python compared to another. If you add optional type hints to your code you
431 can also explicitly state whether your APIs use textual or binary data, helping