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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
@@ -172,19 +172,20 @@ they will get the right version of your library.
It is recommended **not** to invoke `setup.py` directly either with `install` or
`develop` subcommands. These may not correctly resolve dependencies, and can
install incompatible versions of dependencies. Please recommend and use `pip
install .` and `pip install -e .` for regular and developerinstall.
install .` and `pip install -e .` for regular and developerinstalls, respectively.
Check in scripts, and documentation that the correct installation command is
Check in scripts and documentation that the correct installation command is
used.
# Recommended Mitigations
These are not mandatory but should make the transition seamless by warning your
user early enough _and_ providing useful error messages.
users early enough _and_ providing useful error messages.
## Runtime warning on master
Add a warning at _runtime_ early on master (before switching to Python 3 only)
Add a warning at _runtime_ that triggers early on master
(before switching to Python 3 only)
```
import warnings
Expand All
@@ -196,19 +197,20 @@ if sys.version_info < (3,):
UserWarning)
```
Your Python 2userhave a chance to upgrade, or get off master, (for example on
the LTS branch).
Your Python 2users willhave a chance to upgrade, or get off master,
(for example onthe LTS branch).
## Fail early at import time
Add an error early at import at runtime with a clear error message, leave the
early import compatible Python 2 for users to not be welcomed with a useless
`SyntaxError`. Don't hesitate to use multi-line strings in error messages.
Add an error early through import at runtime with a clear error message, leave the
early import compatible Python 2 as users will not feel welcomed with a useless
`SyntaxError` due to their Python 2 usage. Don't hesitate to use multi-line strings
in error messages.
Error at import time _will_ happen onsystem with old version of pip and
Error at import time _will_ happen onsystems with old version of pip and
setuptools. Keep in mind that saying the package is Python 3 only is not a lot
more helpful than aSyntax error. The most reasonable reason would be out of
data pip and setuptools:
more helpful than a`SyntaxError`. The most reasonable reason would be
out-of-date pip and setuptools:
```
Expand All
@@ -220,7 +222,7 @@ if sys.version_info < (3,):
Unfortunately Frobulator 6.0 and above are not compatible with Python 2
anymore, and you still ended up with this version installed on your system.
That's a bummer. Sorry about that. It should not have happened. Make sure you
That's a bummer; sorry about that. It should not have happened. Make sure you
have pip ≥ 9.0 to avoid this kind of issues, as well as setuptools ≥ 24.2:
$ pip install pip setuptools --upgrade
Expand All
@@ -247,14 +249,15 @@ https://i.am.an/url
## Watch out for beta releases
Make sure your version number match pep 440 or you will get surprises during
beta in particular as the `sdist` and `wheel` will appear as being different
versions, in particular sdist (during beta/rc/post) can appear with a greater
version number than wheels. Pip thus try to install the sdist instead of the
wheel, which have more chance of failing, in particular with pre 24.2 versions
of setuptools.
Make sure your version number matches
[PEP 440](https://www.python.org/dev/peps/pep-0440/) or you will get surprises
during beta, in particular as the `sdist` and `wheel` will appear as being
different versions (the sdist (during beta/rc/post) can appear with
a greater version number than wheels). Pip thus will try to install the sdist
instead of the wheel, which has more chance of failing, in particular with
pre-24.2 versions of setuptools.
The regular expression to check for validity of pep440 can befind below:
The regular expression to check for validity of pep440 can befound below:
^
([1-9]\\d*!)?
Expand All
@@ -268,11 +271,11 @@ The regular expression to check for validity of pep440 can be find below:
## fail early in setup.py
Leave `setup.py` python 2 compatible and fail early. If you detect Python 2
raise a clear error message and ask user to make sure they have pip > 9.0 (or
raise a clear error message and asktheuser to make sure they have pip > 9.0 (or
migrate to Python 3). You can (try to) conditionally import pip and check for
its version but this might not be the same pip. Failing early is important to
make sure the Python installation does not install an incompatible version.
Otherwise user code can fail at runtimearbitrary later in the future, which can
Otherwise user code can fail at runtimearbitrarily later in the future, which can
be a difficult to debug and fix. Get inspiration from the message of failure at
runtime, and adapt for installation time.
Expand All
@@ -281,7 +284,7 @@ runtime, and adapt for installation time.
If you control dependant packages, Make sure to include conditional dependencies
depending on the version of Python.
# Nonrecommended mitigations
# Non-recommended mitigations
This is a collection of "mitigation" or "solutions" you will find on the web
and that you will hear about. This is an attempt to acknowledge them, and
Expand All
@@ -290,65 +293,66 @@ implement them.
### Use a meta-package.
It is possible to release a meta-package that has _virtually_ no code andrely
on conditional dependency to install its actual core code on the user system.
It is possible to release a meta-package that has _virtually_ no code andrelies
onaconditional dependency to install its actual core code on the user system.
For example, Frob-6.0 could be a meta-package which depends on
Frob-real-py2 on Python < 3.0, and Frob-real-py3 on Python ≥ 3.4. While
this approach is _doable_ this can make imports confusing.
## Depend on setuptools
You can mark your library as dependent on setuptools greater than 24.3 this
You can mark your library as dependent on setuptools greater than 24.3asthis
will insure that during the next upgrade (when the packages drop python 2
support) will have the right version of setuptools.
Of course regardless of all the care you will take for your library to no break
and to install only on python 2, you will likely have cases where itstill end
up being installed on incompatible versions of Python. Simply because users
upgrades rarely and only an old version of pip or setuptools is enough to make
theallupdate process broken.
and to install only on python 2, you will likely have cases where itwill still
endup being installed on incompatible versions of Python. Simply because users
upgrade rarely and only an old version of pip or setuptools is enough to make
the update process broken.
Plus setuptools is rarely an actual dependency of your project but a
requirement to build wheels.
### MultipleSdist.
### Multiplesdist files
Pip (used to) support a "feature" where a sdist ending in `-pyX.Y.tar.gz` would
only be seen as compatible on Python X.Y, thus it used to be possible to
publish multiple sdist of a package targeting various python version.
Though itis not possible anymore to upload multiple sdist on PyPI. This
solution isthus not possible.
Itis not possible anymore to upload multiple sdistfileson PyPI, so this
solution isno longer tenable.
### Wheel only ?
Releasing a package only usingwheel for a given python version is doable, but
Releasing a package only usingwheels for a given python version is doable, but
this will break downstream packages that may require the original source to
reproducethe build.
reproducetheir build.
# Why allthat?
# Why all*this* ?!?
You might wonder why all this, it's 2016 already, so how comeall these
issues ? Python 3 has been out for 8+ years now !
You might wonder why all this, it's 2016 already, so how comethis is now an
issue ? Python 3 has been out for 8+ years now !
Well there are many reasonsto this, first of all, this issue mostlyaffect
Well there are many reasonsfor this. First of all, this issue mostlyaffects
libraries that are currently python 2 and Python 3 compatible at the same time.
Many libraries have transitioned from Python 2-only to Python 2 + 3. And the
issue of transitioning to Python 3 only is relatively recent. Technically it
can also apply to libraries that are only stopping support for 2.6, orevenare
already Python 3 only, but are starting to stopsupport for earlier versions of
Python. For example a library releasing a Python 3.4+ only version.
can also apply to libraries that are only stopping support for 2.6, or are even
already Python 3 only, but are starting to stopsupporting earlier versions of
Python (for example a library releasing a Python 3.4+ only version).
Python 3.3 wasrelease at the end of 2012, and was the first version to
Python 3.3 wasreleased at the end of 2012, and was the first version to
support (again) `u` as a prefix for Unicode string. It was one of the first
minorversion of Python 3 that saw a majority of single-sourceproject working
both on Python 2 and Python 3. These are theProject that will likely be
minorversions of Python 3 that saw a majority of single-sourceprojects working
both on Python 2 and Python 3. These are theprojects that will likely be
affected by this issue.
The introduction of Python 3 was chaotic, there are still strong argument both
in Python 2 and Python 3 camps. In the one suffering the most from this are
users. Starting with the fact that inevitably some libraries will stop support
for Python 2 and release Python 3 only library. And that inevitably some system
will will not be upgraded to Python 3 how can we _ensure_ that users get the
_least_ breakage as possible ? And what are the best practices to follow.
The introduction of Python 3 was chaotic; there are still strong arguments in both
the Python 2 and Python 3 camps. Regardless of what side you take, the ones suffering
the most from this are users (starting with the fact that inevitably some libraries
will stop supporting for Python 2 and release Python 3 only library). Inevitably, some
systems and people will will not be upgraded to Python 3, so this document hopefully
helps to _ensure_ that users get the _least_ breakage as possible and what are the best
practices are to follow.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.