@@ -36,15 +36,15 @@ system will not try to upgrade said library.
36
36
37
37
With the recent changes in Python packaging this is now possible.
38
38
39
- As an example let's look at the example of the ` fictious ` library.
39
+ As an example let's look at the example of the ` fictitious ` library.
40
40
41
- - ` fictious ` 1.1, 1.2, 1.3, 1.4 are compatible Python 2.7 and 3.3+
42
- - ` fictious ` 2.0 has been released and is python 3.4+ only.
41
+ - ` fictitious ` 1.1, 1.2, 1.3, 1.4 are compatible Python 2.7 and 3.3+
42
+ - ` fictitious ` 2.0 has been released and is python 3.4+ only.
43
43
44
44
As a Python 2.7 user, if I don't pay attention, or if the library is not
45
45
correctly tagged, if I issue the following:
46
46
47
- $ python -c 'import fictious ; print(fictious .__version__)'
47
+ $ python -c 'import fictitious ; print(fictitious .__version__)'
48
48
1.3.2
49
49
$ pip install fiction --upgrade
50
50
@@ -96,10 +96,8 @@ If you are on a system for which no wheel is available, pip will try to
96
96
install a source distribution (aka ` sdist ` ).
97
97
98
98
Installing an ` sdist ` will require setuptools make sure you have setuptools
99
- ` >=24.2.0 ` (mnemonic: 2-42, [ why
100
- 42] ( https://en.wikipedia.org/wiki/The_answer_to_life_the_universe_and_everything )
101
- ?) or building Python 3 only libraries is likely to fail. In particular if
102
- library authors have taken time to mark their library as Python 3 only, the
99
+ ` >=24.2.0 ` or building Python 3 only libraries is likely to fail. In particular
100
+ if library authors have taken time to mark their library as Python 3 only, the
103
101
` python_requires ` argument to ` setup() ` may not be recognized and installation
104
102
will fail.
105
103
@@ -131,9 +129,6 @@ deployed yet but should hopefully be deployed soon.
131
129
PyPI] ( https://github.com/pypa/legacy-pypi ) have received various patches to
132
130
insure they support this new functionality.
133
131
134
- You can publish a package with the ` requires_python ` metadata ** now** , it will
135
- be correctly exposed once pypi is deployed.
136
-
137
132
# Preparing your library
138
133
139
134
@@ -163,16 +158,16 @@ setup(
163
158
)
164
159
```
165
160
166
- Changes ` >=3.3 ` accordingly depending on what version your library decides to
161
+ Change ` >=3.3 ` accordingly depending on what version your library decides to
167
162
support. In particular you can use ` >=2.6 ` or ` >=3.5 ` ! Note that this also
168
- support the _ compable with_ syntax: ` ~=2.5 ` (meaning, ` >=2.5 ` and ` <3 ` .
163
+ support the _ compable with_ syntax: ` ~=2.5 ` (meaning, ` >=2.5 ` and ` <3 ` ) .
169
164
170
165
This will make [ PyPI aware] ( https://github.com/pypa/warehouse/pull/1448 ) that
171
166
your package is Python 3.3+ only, and [ allow
172
167
pip] ( https://github.com/pypa/pip/pull/3877 ) to be [ made aware of
173
168
this] ( https://github.com/pypa/pypi-legacy/pull/506 ) .
174
169
175
- Thus as long as your user have a recent enough version of pip, and setuptools
170
+ Thus as long as your user have recent enough versions of pip and setuptools
176
171
they will get the right version of your library.
177
172
178
173
# Unit Testing and documentation
@@ -212,7 +207,7 @@ the LTS branch).
212
207
213
208
Add an error early at import at runtime with a clear error message, leave the
214
209
early import compatible Python 2 for users to not be welcomed with a useless
215
- ` SyntaxError ` . You are _ allowed _ to use multi-line strings in error messages.
210
+ ` SyntaxError ` . Don't hesitate to use multi-line strings in error messages.
216
211
217
212
Error at import time _ will_ happen on system with old version of pip and
218
213
setuptools. Keep in mind that saying the package is Python 3 only is not a lot
@@ -229,7 +224,7 @@ if sys.version_info < (3,):
229
224
230
225
Unfortunately Frobulator 6.0 and above are not compatible with Python 2
231
226
anymore, and you still ended up with this version installed on your system.
232
- That's a bummer. Sorry about that. It should not have happen . Make sure you
227
+ That's a bummer. Sorry about that. It should not have happened . Make sure you
233
228
have pip >= 9.0 to avoid this kind of issues, as well as setuptools >= 24.2:
234
229
235
230
$ pip install pip setuptools --upgrade
@@ -267,25 +262,14 @@ The regular expression to check for validity of pep440 can be find below:
267
262
268
263
` ^([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*))? `
269
264
270
- ## Depend on setuptools
271
-
272
- You can mark your library as dependent on setuptools greater than 24.3 starting
273
- now, this will insure that during the next upgrade (when the packages drop
274
- python 2 support) will have the right version of setuptools.
275
-
276
- Of course regardless of all the care you will take for your library to no break
277
- and to install only on python 2, you will likely have cases where it still end
278
- up being installed on incompatible versions of Python. Simply because users
279
- upgrades rarely and only an old version of pip or setuptools is enough to make
280
- the all update process broken.
281
265
282
266
## fail early in setup.py
283
267
284
268
Leave ` setup.py ` python 2 compatible and fail early. If you detect Python 2
285
269
raise a clear error message and ask user to make sure they have pip >9.0 (or
286
270
migrate to Python 3). You can (try to) conditionally import pip and check for
287
271
its version but this might not be the same pip. Failing early is important to
288
- make sure the Python installation does not install and incompatible version.
272
+ make sure the Python installation does not install an incompatible version.
289
273
Otherwise user code can fail at runtime arbitrary later in the future, which can
290
274
be a difficult to debug and fix. Get inspiration from the message of failure at
291
275
runtime, and adapt for installation time.
@@ -295,7 +279,7 @@ runtime, and adapt for installation time.
295
279
If you control dependant packages, Make sure to include conditional dependencies
296
280
depending on the version of Python.
297
281
298
- # Incorrect mitigations
282
+ # Non recommended mitigations
299
283
300
284
This is a collection of "mitigation" or "solutions" you will find on the web
301
285
and that you will hear about. This is an attempt to acknowledge them, and
@@ -313,6 +297,22 @@ this approach is _doable_ this can make imports confusing.
313
297
Moreover, upgrading your package may need the user to explicitly tell pip to
314
298
upgrade dependencies as ` pip install -U frob ` will only upgrade the meta-package.
315
299
300
+ ## Depend on setuptools
301
+
302
+ You can mark your library as dependent on setuptools greater than 24.3 this
303
+ will insure that during the next upgrade (when the packages drop python 2
304
+ support) will have the right version of setuptools.
305
+
306
+ Of course regardless of all the care you will take for your library to no break
307
+ and to install only on python 2, you will likely have cases where it still end
308
+ up being installed on incompatible versions of Python. Simply because users
309
+ upgrades rarely and only an old version of pip or setuptools is enough to make
310
+ the all update process broken.
311
+
312
+ Plus setuptools is rarely an actual dependency of your project but a
313
+ requirement to build wheels.
314
+
315
+
316
316
### Multiple Sdist.
317
317
318
318
Pip (used to) support a "feature" where a sdist ending in ` -pyX.Y.tar.gz ` would
@@ -341,11 +341,11 @@ can also apply to libraries that are only stopping support for 2.6, or even are
341
341
already Python 3 only, but are starting to stop support for earlier versions of
342
342
Python. For example a library releasing a Python 3.4+ only version.
343
343
344
- Python 3.3 was release end of 2012, and was the first version to support
345
- (again) ` u ` as a prefix for Unicode string. It was one of the first minor
346
- version of Python 3 that saw a majority of single-source project working both
347
- on Python 2 and Python 3. These are the Project that will likely be affected by
348
- this issue.
344
+ Python 3.3 was release at the end of end of 2012, and was the first version to
345
+ support (again) ` u ` as a prefix for Unicode string. It was one of the first
346
+ minor version of Python 3 that saw a majority of single-source project working
347
+ both on Python 2 and Python 3. These are the Project that will likely be
348
+ affected by this issue.
349
349
350
350
The introduction of Python 3 was chaotic, there are still strong argument both
351
351
in Python 2 and Python 3 camps. In the one suffering the most from this are
0 commit comments