From 99efba4fc39eed86ea03884a9bde2e5de265d1a8 Mon Sep 17 00:00:00 2001 From: OllisGit <24205767+OllisGit@users.noreply.github.com> Date: Sun, 12 Apr 2020 11:31:14 +0200 Subject: [PATCH 1/3] Update python3_migration.rst Added "Explicit imports" description --- docs/plugins/python3_migration.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/plugins/python3_migration.rst b/docs/plugins/python3_migration.rst index 90f08149e..37ce935af 100644 --- a/docs/plugins/python3_migration.rst +++ b/docs/plugins/python3_migration.rst @@ -242,6 +242,30 @@ future import: from __future__ import absolute_imports +Explicit imports +................ + +Sometimes it is necessary to use an import statement that is explicitly related to a specific python version. +You can do this in differnt ways: + +.. code-block:: python + + try: + import queue + except ImportError: + import Queue as queue + +or + +.. code-block:: python + + import sys + is_py2 = sys.version[0] == '2' + if is_py2: + import Queue as queue + else: + import queue as queue + You can read more about this specific issue in the `cheat sheet `__ and also in `the book `__. From bd2a72d178dde36b76bf6d7cbc0d7879bd9dfe57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 14 Apr 2020 14:33:42 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9D=20docs:=20Minor=20changes=20fo?= =?UTF-8?q?r=20version=20specific=20imports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fixed a section that got misplaced by the PR. --- docs/plugins/python3_migration.rst | 31 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/docs/plugins/python3_migration.rst b/docs/plugins/python3_migration.rst index 37ce935af..a01de01b3 100644 --- a/docs/plugins/python3_migration.rst +++ b/docs/plugins/python3_migration.rst @@ -218,7 +218,7 @@ You can read more about this specific issue in the corresponding section of the `Python porting guide `__ and also in the `cheat sheet `__. -.. _sec-plugins-python3-pitfalls-imports: +.. _sec-plugins-python3-pitfalls-absolute-imports: Absolute imports ................ @@ -242,11 +242,18 @@ future import: from __future__ import absolute_imports -Explicit imports -................ +You can read more about this specific issue in the +`cheat sheet `__ and also in +`the book `__. -Sometimes it is necessary to use an import statement that is explicitly related to a specific python version. -You can do this in differnt ways: +.. _sec-plugins-python3-pitfalls-version-specific-imports: + +Version specific imports +........................ + +Sometimes it is necessary to use an import statement that is explicitly related to a specific Python version, e.g. due to +a package change between Python 2 and 3. You can do this by first trying the Python 3 import and if that doesn't work +out trying the Python 2 import instead: .. code-block:: python @@ -255,20 +262,16 @@ You can do this in differnt ways: except ImportError: import Queue as queue -or +This should be the preferred method of handling situations like this. If you actually do need to do explicit version +specific imports that cannot be handled this way, you can check for the Python version like this: .. code-block:: python import sys - is_py2 = sys.version[0] == '2' - if is_py2: - import Queue as queue + if sys.version[0] == '2': + # Python 2 specific imports else: - import queue as queue - -You can read more about this specific issue in the -`cheat sheet `__ and also in -`the book `__. + # Python 3 specific imports .. _sec-plugins-python3-pitfalls-intdiv: From 63e915c8cc4aeac08a1700fa414fde01e471a1c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 14 Apr 2020 14:34:29 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9D=20docs:=20Update=20install=20O?= =?UTF-8?q?ctoPi=20instructions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/plugins/python3_migration.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/plugins/python3_migration.rst b/docs/plugins/python3_migration.rst index a01de01b3..b5ad65780 100644 --- a/docs/plugins/python3_migration.rst +++ b/docs/plugins/python3_migration.rst @@ -70,7 +70,7 @@ Then create an editable install of your plugin, start the server and start testi .. note:: - If you want to migrate your existing OctoPrint install *on OctoPi* to Python 3, I suggest to first make a + If you want to migrate your existing OctoPrint install *on OctoPi 0.17.0* to Python 3, I suggest to first make a :ref:`backup `, then move the existing venv ``/home/pi/oprint`` out of the way and create a new one based on Python 3 (which should already be present on current OctoPi images): @@ -79,7 +79,7 @@ Then create an editable install of your plugin, start the server and start testi mv ~/oprint ~/oprint.py2 virtualenv --python=/usr/bin/python3 oprint source ~/oprint/bin/activate - pip install "OctoPrint>=1.4.0rc1" + pip install "OctoPrint>=1.4.0" sudo service octoprint restart .. _sec-plugins-python3-markup: