| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,14 +1,21 @@ | |||
| 1 | 1 | --- | |
| 2 | 2 | --- | |
| 3 | 3 | ||
| 4 | - | ||
| 5 | 4 | Add note here to explain that this does _not_ prevent _nor_ discourage library | |
| 6 | 5 | author to release 2 version of their software one Python 3 only and the other | |
| 7 | 6 | python 2. | |
| 8 | 7 | ||
| 9 | 8 | This actually made the above easier and less-likely to break. | |
| 10 | 9 | ||
| 11 | 10 | ||
| 11 | + Too long, did not read: | ||
| 12 | + | ||
| 13 | + - Help and encourage users to install **pip 9.0+** | ||
| 14 | + - Help and encourage users to install **setuptools 24.3+** | ||
| 15 | + - Use **`setup(..., python_requires='>=3.3')`** new option. | ||
| 16 | + - **Fail** early at **install time** if on Python 2. | ||
| 17 | + | ||
| 18 | + | ||
| 12 | 19 | # As a user | |
| 13 | 20 | ||
| 14 | 21 | ## Install Pip 9.0 | |
@@ -21,27 +28,49 @@ the community strong. | |||
| 21 | 28 | ||
| 22 | 29 | Make sure you have Pip >= 9.0, this is especially important if you have Python | |
| 23 | 30 | 2 installations. Having pip 9.0+ will not insure that you install will not | |
| 24 | - break, but they are more likely not to. Having a version off pip <9.0 can lead | ||
| 31 | + break, but they are more likely not to. Having a version off pip < 9.0 can lead | ||
| 25 | 32 | your system to try to upgrade to non-compatible versions of Python packages | |
| 26 | 33 | even if these are marked as non-compatible. | |
| 27 | 34 | ||
| 28 | 35 | Help as many other _users_ as possible to install pip >=9.0, for the | |
| 29 | 36 | transition, it is the slowest part of the ecosystem to update, and is the only | |
| 30 | - piece that concerns all installations: | ||
| 37 | + piece that concerns all installations. | ||
| 38 | + | ||
| 39 | + The simplest way to make sure all is up to date is to run the following for | ||
| 40 | + each installation of Python: | ||
| 31 | 41 | ||
| 32 | 42 | pip install --upgrade setuptools pip | |
| 33 | 43 | ||
| 44 | + This will install the latest version of pip and setuptools. | ||
| 45 | + | ||
| 46 | + You can issue the following to see the version of pip: | ||
| 47 | + | ||
| 48 | + pip --version | ||
| 49 | + | ||
| 50 | + | ||
| 51 | + | ||
| 34 | 52 | ## Setuptools | |
| 35 | 53 | ||
| 36 | 54 | If you are on a system that will not install python wheel and use `setuptools`, | |
| 37 | 55 | make sure you have setuptools >=24.2.0, or building Python 3 only libraries | |
| 38 | - might fail, even on Python 2. | ||
| 56 | + might fail. In particular if authors have taken time to mark their library as | ||
| 57 | + Python 3 only, the `python_requires` argument to `setup()` will not be | ||
| 58 | + recognize and installation will fail. | ||
| 59 | + | ||
| 60 | + Use the following to check setuptools version : | ||
| 61 | + | ||
| 62 | + python -c 'import setuptools; print(setuptools.__version__) | ||
| 63 | + | ||
| 64 | + Again make sure tu upgrade pip and setuptools to make sure you have an up to | ||
| 65 | + date system: | ||
| 66 | + | ||
| 67 | + pip install --upgrade setuptools pip | ||
| 39 | 68 | ||
| 40 | 69 | ## Local package index | |
| 41 | 70 | ||
| 42 | 71 | If you are using a custom local package index, for example if you are working | |
| 43 | 72 | at a company with private packages, make sure it implement correctly | |
| 44 | - [pep-503](https://www.python.org/dev/peps/pep-0503/) and let pip knows about | ||
| 73 | + [pep-503](https://www.gg python.org/dev/peps/pep-0503/) and let pip knows about | ||
| 45 | 74 | the `python_requires` field. | |
| 46 | 75 | ||
| 47 | 76 | ## The state of PyPI | |
@@ -53,20 +82,21 @@ deployed yet but should hopefully be deployed soon. | |||
| 53 | 82 | # Preparing your library | |
| 54 | 83 | ||
| 55 | 84 | ||
| 56 | - | ||
| 57 | 85 | As a library author one of the most important factor in a smooth transition is | |
| 58 | 86 | planning and communication, letting your user base know in advance that the | |
| 59 | 87 | transition is happening and what step to take is critical for a transition. | |
| 60 | 88 | ||
| 61 | 89 | For your library code here the steps you need to take to ensure that | |
| 62 | 90 | installation will fail in the least number of case: | |
| 63 | 91 | ||
| 64 | - You need to release your new packages version with [setuptools] version 24.2.0 | ||
| 65 | - or above, or use one of the alternate package manager that can set the | ||
| 66 | - [`python_require`] metadata field. Without this, pip 9.0 **will try** to | ||
| 67 | - install non-compatible version of your software on Python 2. This version of | ||
| 68 | - setuptools is recent (July 20, 2016) and this possible thank to the [work of | ||
| 69 | - Xavier Fernandez](https://github.com/pypa/setuptools/pull/631) | ||
| 92 | + You need to release your new packages version with | ||
| 93 | + [setuptools](https://pypi.python.org/pypi/setuptools) version 24.2.0 or above. | ||
| 94 | + You can also use one of the alternate package manager that can set the | ||
| 95 | + [Requires-Python](https://www.python.org/dev/peps/pep-0345/#requires-python) | ||
| 96 | + metadata field. Without this, pip 9.0 **will try** to install non-compatible | ||
| 97 | + version of your software on Python 2. This version of setuptools is recent | ||
| 98 | + (July 20, 2016) and this possible thank to the [work of Xavier | ||
| 99 | + Fernandez](https://github.com/pypa/setuptools/pull/631) | ||
| 70 | 100 | ||
| 71 | 101 | Add the following to your `setup.py` | |
| 72 | 102 | ||
@@ -81,8 +111,10 @@ setup( | |||
| 81 | 111 | Changes `>=3.3` accordingly depending on what version your library decides to | |
| 82 | 112 | support. | |
| 83 | 113 | ||
| 84 | - This will make [PyPI aware](linkto mike's PR on warehouse) that your package is | ||
| 85 | - Python 3 only, and [allow pip](link to pip's PR) to be [made aware of this](link to PyPI PR). | ||
| 114 | + This will make [PyPI aware](https://github.com/pypa/warehouse/pull/1448) that | ||
| 115 | + your package is Python 3 only, and [allow | ||
| 116 | + pip](https://github.com/pypa/pip/pull/3877) to be [made aware of | ||
| 117 | + this](https://github.com/pypa/pypi-legacy/pull/506). | ||
| 86 | 118 | ||
| 87 | 119 | ||
| 88 | 120 | - Add a warning at _runtime_ early on master (before switching to Python 3 | |
@@ -131,17 +163,26 @@ installed, and try to check how to prevent that for future users. | |||
| 131 | 163 | This this page for more information : url to here for example. | |
| 132 | 164 | """) | |
| 133 | 165 | ||
| 166 | + ``` | ||
| 167 | + | ||
| 134 | 168 | ||
| 135 | 169 | ||
| 136 | - - Make sure your version number match pep440 or you will get surprises during | ||
| 137 | - beta in particular as the `sdist` and `wheel` will appear as being different | ||
| 138 | - versions, in particular sdist (during beta/rc/post) might appear with a | ||
| 139 | - greater version number than wheels... and pip will try to install the sdist | ||
| 140 | - instead of the wheel... The regular expression is trickier than expected: | ||
| 170 | + Make sure your version number match pep440 or you will get surprises during | ||
| 171 | + beta in particular as the `sdist` and `wheel` will appear as being different | ||
| 172 | + versions, in particular sdist (during beta/rc/post) can appear with a greater | ||
| 173 | + version number than wheels. Pip thus try to install the sdist instead of the | ||
| 174 | + wheel, which have more chance of failing, in particular with pre 24.2 versions | ||
| 175 | + of setuptools. | ||
| 176 | + | ||
| 177 | + The regular expression to check for validity of pep440 can be find below: | ||
| 141 | 178 | ||
| 142 | 179 | `^([1-9]\\d*!)?(0|[1-9]\\d*)(\\.(0|[1-9]\\d*))*((a|b|rc)(0|[1-9]\\d*))?(\\.post(0|[1-9]\\d*))?(\\.dev(0|[1-9]\\d*))?` | |
| 143 | 180 | ||
| 144 | - - depend on setuptools greater than 24.3 | ||
| 181 | + | ||
| 182 | + | ||
| 183 | + You can mark your library as dependent on setuptools greater than 24.3 starting | ||
| 184 | + now, this will insure that during the next upgrade (when the packages drop | ||
| 185 | + python 2 support) will have the right version of setuptools. | ||
| 145 | 186 | ||
| 146 | 187 | ||
| 147 | 188 | ||
@@ -156,11 +197,17 @@ the all update process broken. | |||
| 156 | 197 | - Leave `setup.py` python 2 compatible and fail early. If you detect Python 2 | |
| 157 | 198 | raise a clear error message and ask user to make sure they have pip >9.0 (or | |
| 158 | 199 | migrate to Python 3). You can (try to) conditionally import pip and check for | |
| 159 | - its version but this might not be the same pip. | ||
| 200 | + its version but this might not be the same pip. Failing early is important to | ||
| 201 | + make sure the Python installation does not install and incompatible version. | ||
| 202 | + Otherwise user code can fail at runtime arbitrary later in the future, which | ||
| 203 | + can be a difficult to debug and fix. | ||
| 160 | 204 | ||
| 161 | 205 | - If you control dependant packages, Make sure to include conditional | |
| 162 | 206 | dependencies depending on the version of Python. | |
| 163 | 207 | ||
| 208 | + - Regardless of whether the installation step fails on Python 2, implement a | ||
| 209 | + similar check in the top level import of your package. | ||
| 210 | + | ||
| 164 | 211 | ||
| 165 | 212 | # Alternative mitigation | |
| 166 | 213 | ||
@@ -171,12 +218,55 @@ implement them. | |||
| 171 | 218 | ||
| 172 | 219 | ### Use a meta-package. | |
| 173 | 220 | ||
| 221 | + It is possible to release a meta-package that has _virtually_ no code and rely | ||
| 222 | + on conditional dependency to install its actual core code on the user system. | ||
| 223 | + For example, Frob-6.0 could be a meta-package which depends on | ||
| 224 | + Frob-real-py2 on Python <3.0, and Frob-real-py3 on Python >= 3.4. While | ||
| 225 | + this approach is _doable_ this can make import confusing. | ||
| 226 | + | ||
| 227 | + Moreover, upgrading your package may need the user to explicitly tell pip to | ||
| 228 | + upgrade dependencies as `pip install frob` will only upgrade the meta-package. | ||
| 229 | + | ||
| 230 | + ### Multiple Sdist. | ||
| 231 | + | ||
| 232 | + Pip (used to) support a "feature" where a sdist ending in `-pyX.Y.tar.gz` would | ||
| 233 | + only be seen as compatible on Python X.Y, thus it used to be possible to | ||
| 234 | + publish multiple sdist of a package targeting various python version. | ||
| 235 | + | ||
| 236 | + Though it is not possible anymore to upload multiple sdist on PyPI. This | ||
| 237 | + solution is thus not possible. | ||
| 238 | + | ||
| 239 | + ### Wheel only ? | ||
| 240 | + | ||
| 241 | + Break downstream packages. | ||
| 242 | + | ||
| 243 | + | ||
| 174 | 244 | ||
| 175 | 245 | ||
| 176 | 246 | # Why all that ? | |
| 177 | 247 | ||
| 178 | - You might wonder why all this, it's 2016 already, so how come all these issues ? | ||
| 179 | - Python 3 has been out for 8+ years now ! | ||
| 248 | + You might wonder why all this, it's 2016 already, so how come all these | ||
| 249 | + issues ? Python 3 has been out for 8+ years now ! | ||
| 250 | + | ||
| 251 | + Well there are many reasons to this, first of all, this issue mostly affect | ||
| 252 | + libraries that are currently python 2 and Python 3 compatible at the same time. | ||
| 253 | + Many libraries have transitioned from Python 2-only to Python 2 + 3. And the | ||
| 254 | + issue of transitioning to Python 3 only is relatively recent. Technically it | ||
| 255 | + can also apply to libraries that are only stopping support for 2.6, or even are | ||
| 256 | + already Python 3 only, but are starting to stop support for earlier versions of | ||
| 257 | + Python. For example a library releasing a Python 3.4+ only version. | ||
| 258 | + | ||
| 259 | + Python 3.3 was release end of 2012, and was the first version to support | ||
| 260 | + (again) `u` as a prefix for Unicode string. It was one of the first minor | ||
| 261 | + version of Python 3 that saw a majority of single-source project working both | ||
| 262 | + on Python 2 and Python 3. These are the Project that will likely be affected by | ||
| 263 | + this issue. | ||
| 264 | + | ||
| 265 | + The introduction of Python 3 was chaotic, there are still strong argument both | ||
| 266 | + in Python 2 and Python 3 camps. In the one suffering the most from this are | ||
| 267 | + users. Starting with the fact that inevitably some libraries will stop support | ||
| 268 | + for Python 2 and release Python 3 only library. And that inevitably some system | ||
| 269 | + will will not be upgraded to Python 3 how can we _ensure_ that users get the | ||
| 270 | + _least_ breakage as possible ? And what are the best practices to follow. | ||
| 180 | 271 | ||
| 181 | - Well there are many reasons to this, | ||
| 182 | 272 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments