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
Copy file name to clipboardExpand all lines: docs/backend/upgrading/version-specific-migration/upgrade-to-python3.md
+44-47Lines changed: 44 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,45 +1,42 @@
1
1
---
2
2
myst:
3
3
html_meta:
4
-
"description": "Upgrading to Python 3"
5
-
"property=og:description": "Upgrading to Python 3"
6
-
"property=og:title": "Upgrading to Python 3"
7
-
"keywords": "Upgrading, Python 3"
4
+
"description": "Upgrading to Python 3 in Plone 5.2"
5
+
"property=og:description": "Upgrading to Python 3 in Plone 5.2"
6
+
"property=og:title": "Upgrading to Python 3 in Plone 5.2"
7
+
"keywords": "Upgrading, Python 3, Plone 5.2"
8
8
---
9
9
10
10
11
11
(migrating-52-to-python3-label)=
12
12
13
13
# Migrating Plone 5.2 to Python 3
14
14
15
-
```{admonition} Description
16
-
Instructions and tips for porting Plone projects to Python 3
17
-
```
15
+
This chapter provides instructions and tips for porting Plone projects to Python 3.
18
16
19
-
```{note}
20
-
If you want to upgrade add-ons to Python 3, the list of all Plone packages that still need to be ported can be found on the GitHub project board [Python 3 porting state for Plone add-ons](https://github.com/orgs/collective/projects/1).
17
+
```{seealso}
18
+
If you want to upgrade add-ons to Python 3, the list of all Plone packages that still need to be ported can be found on the GitHub project board [Python 3 porting state for Plone add-ons](https://github.com/orgs/collective/projects/1).
21
19
```
22
20
23
-
## Make Custom Packages Python 3 Ready
21
+
## Principles
24
22
25
-
### Principles
23
+
- You should support Python 2 and 3 with the same codebase to allow it to be used in existing versions of Plone.
- We use [six](https://six.readthedocs.io) and [modernize](https://pypi.org/project/modernize) to do the first steps towards Python 3.
27
+
In general, you should follow these steps to port add-ons:
30
28
31
-
In general you should follow these steps to port add-ons:
29
+
1. Prepare `buildout` for the add-on to be ported.
30
+
2. Update code with [python-modernize](https://python-modernize.readthedocs.io/en/latest/).
31
+
3. Use [plone.recipe.precompiler](https://github.com/plone/plone.recipe.precompiler) (also called `precompiler` for brevity) to find syntax errors.
32
+
4. Start the instance and find more errors.
33
+
5. Test functionality manually.
34
+
6. Run and fix all tests.
35
+
7. Update package information.
36
+
8. Update package buildout and test setup.
32
37
33
-
1. Prepare `buildout` for the add-on to be ported.
34
-
2. Update code with [python-modernize](https://python-modernize.readthedocs.io/en/latest/).
35
-
3. Use [plone.recipe.precompiler](https://github.com/plone/plone.recipe.precompiler) (also called `precompiler` for brevity) to find syntax errors.
36
-
4. Start the instance and find more errors.
37
-
5. Test functionality manually.
38
-
6. Run and fix all tests.
39
-
7. Update package information.
40
-
8. Update package buildout and test-setup
41
38
42
-
### 1 Preparation
39
+
##1. Preparation
43
40
44
41
In the GitHub repository of the add-on:
45
42
@@ -51,13 +48,13 @@ The following section is valid until the final release of Plone 5.2.
51
48
Upon the final release of Plone 5.2, something else will take its place.
52
49
```
53
50
54
-
####Using Released Plone 5.2
51
+
### Using Released Plone 5.2
55
52
56
53
Usually it is fine to use the latest Plone 5.2 release.
57
54
The version pins for the latest release can be found for pip at [https://dist.plone.org/release/5.2-latest/requirements.txt] and for buildout at [https://dist.plone.org/release/5.2-latest/versions.cfg].
58
55
Install Plone with Python 3.6 or 3.7 and then add your addons as source using mr.developer\`.
59
56
60
-
####Using Core Development Buildout
57
+
### Using Core Development Buildout
61
58
62
59
With [buildout.coredev](https://github.com/plone/buildout.coredev) the latest development version of Plone can be used.
63
60
It contains everything for porting an add-on to Python 3.
@@ -141,7 +138,7 @@ For small packages or packages that have few dependencies, it is a good idea to
141
138
142
139
If it does not start up, you should continue with the next steps instead of trying to fix each issue as it appears.
143
140
144
-
### 2 Automated Fixing With Modernize
141
+
##2. Automated Fixing With Modernize
145
142
146
143
`python-modernize` is a utility that automatically prepares Python 2 code for porting to Python 3.
147
144
After running `python-modernize`, there is manual work ahead.
@@ -159,7 +156,7 @@ Check the [Python style guide for Plone](https://docs.plone.org/develop/stylegui
159
156
160
157
If `six` is used in the code, make sure that `six` is added to the `install_requires` list in the `setup.py` of the package.
161
158
162
-
####Installation
159
+
### Installation
163
160
164
161
Install `modernize` into your Python 3 environment with `pip`.
165
162
@@ -173,7 +170,7 @@ Install `isort` into your Python 3 environment with `pip`.
173
170
./bin/pip install isort
174
171
```
175
172
176
-
####Usage
173
+
### Usage
177
174
178
175
The following command is a dry-run. I shows all changes that `modernize` would make.
179
176
@@ -201,7 +198,7 @@ You can use `isort` to fix the order of imports:
201
198
202
199
After you run the commands above, you need to review all changes and fix what `modernizer` did not get right.
203
200
204
-
### 3 Use `precompiler`
201
+
##3. Use `precompiler`
205
202
206
203
You can make use of `plone.recipe.precompiler` to identify syntax errors quickly.
207
204
This recipe compiles all Python code already at buildout-time, not at run-time.
@@ -221,20 +218,20 @@ If you want to avoid running the complete buildout every time, you can use the `
221
218
./bin/buildout -c local.cfg install precompiler
222
219
```
223
220
224
-
### 4 Start The Instance
221
+
##4. Start The Instance
225
222
226
223
As a next step we recommend that you try to start the instance with your add-on.
227
224
This will fail on all import errors (e.g., relative imports that are not allowed in Python 3).
228
225
If it works then you can try to install the add-on.
229
226
230
227
You need to fix all issues that appear before you can do manual testing to check for big, obvious issues.
231
228
232
-
####Common Issues during startup
229
+
### Common Issues during startup
233
230
234
231
The following issues will abort your startup.
235
232
You need to fix them before you are able to test the functionality by hand or run tests.
236
233
237
-
#####A - Class Advice
234
+
#### A - Class Advice
238
235
239
236
This kind of error message:
240
237
@@ -265,17 +262,17 @@ class Group(form.BaseForm):
265
262
The same is the case for `provides(IFoo)` and some other Class advices.
266
263
These need to be replaced with their respective decorators like `@provider`.
267
264
268
-
#####B - Relative Imports
265
+
#### B - Relative Imports
269
266
270
267
Relative imports like `import permissions` are no longer permitted.
271
268
Instead use fully qualified import paths such as `from collective.package import permissions`.
272
269
273
-
#####C - Syntax Error On Importing Async
270
+
#### C - Syntax Error On Importing Async
274
271
275
272
In Python 3.7 you can no longer have a module called `async` (see <https://github.com/celery/celery/issues/4849>).
276
273
You need to rename all such files, folders or packages (like `zc.async` and `plone.app.async`).
277
274
278
-
### 5 Test functionality manually
275
+
##5. Test functionality manually
279
276
280
277
Now that the instance is running you should do the following and fix all errors as they appear.
281
278
@@ -285,7 +282,7 @@ Now that the instance is running you should do the following and fix all errors
285
282
286
283
For this step it is recommended that you have installed `Products.PDBDebugMode` to help debug and fix issues.
287
284
288
-
### 6 Run Tests
285
+
##6. Run Tests
289
286
290
287
```shell
291
288
$ ./bin/test --all -s collective.package
@@ -308,7 +305,7 @@ Search for examples of `Py23DocChecker` in Plone's packages to find a pattern wh
308
305
- Fill the fields {guilabel}`ADDON_URL` and {guilabel}`ADDON_BRANCH` with your repository's URL and the branch name ("python3" if you followed these instructions).
309
306
- Start the build with the {guilabel}`Build` button.
310
307
311
-
### 7 Update Add On Information
308
+
##7. Update Add On Information
312
309
313
310
Add the following three entries of the classifiers list in setup.py:
314
311
@@ -321,7 +318,7 @@ Add the following three entries of the classifiers list in setup.py:
321
318
322
319
Make an entry in the `CHANGES.rst` file.
323
320
324
-
### 8 Create A Test Setup That Tests In Python 2 And Python 3
321
+
##8. Create A Test Setup That Tests In Python 2 And Python 3
325
322
326
323
You need to update the buildout of the add-on you are migrating to also support Plone 5.2 and Python 3.
327
324
Since the buildout of most add-ons are different we cannot offer advice that works for all add-ons.
@@ -337,9 +334,9 @@ Always use the newest version of {py:mod}`bobtemplates.plone`!
337
334
338
335
Add-ons created like this contain a setup that allows testing in Python 2 and Python 3 and various Plone versions locally and on travis-ci using {py:mod}`tox`. Look at the files `tox.ini` and `travis.yml`.
339
336
340
-
### 9 Frequent Issues
337
+
##9. Frequent Issues
341
338
342
-
####Text and Bytes
339
+
### Text and Bytes
343
340
344
341
This is by far the biggest issue when porting to Python 3.
345
342
Read the [Conservative Python 3 Porting Guide, Strings](https://portingguide.readthedocs.io/en/latest/strings.html) to be prepared.
@@ -377,10 +374,10 @@ from six import BytesIO
377
374
```{seealso}
378
375
Here is a list of helpful references on the topic of porting Python 2 to Python 3.
0 commit comments