Skip to content

Commit

Permalink
PyOtherSide 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thp committed Aug 5, 2022
1 parent 2a468b0 commit 63eb529
Show file tree
Hide file tree
Showing 21 changed files with 25 additions and 198 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -15,3 +15,4 @@
/qtquicktests/qtquicktests
/qtquicktests/target_wrapper.sh
/examples/__pycache__
/docs/_build
2 changes: 1 addition & 1 deletion LICENSE
Expand Up @@ -2,7 +2,7 @@ PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6

ISC License

Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Expand Up @@ -41,16 +41,16 @@

# General information about the project.
project = u'PyOtherSide'
copyright = u'2014-2020 Thomas Perl'
copyright = u'2014-2022 Thomas Perl'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '1.5'
version = '1.6'
# The full version, including alpha/beta/rc tags.
release = '1.5.9'
release = '1.6.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
180 changes: 3 additions & 177 deletions docs/index.rst
Expand Up @@ -17,7 +17,7 @@ and continuation-passing style function calls.
Qt 6 Support
============

.. versionadded:: UNRELEASED
.. versionadded:: 1.6.0

PyOtherSide now supports Qt 6 while retaining source compatibility with Qt 5.

Expand Down Expand Up @@ -1192,193 +1192,19 @@ pass a suitable ``python-config`` to ``qmake`` at configure time:
Alternatively, you can edit ``python.pri`` manually and specify the compiler
flags for compiling and linking against Python on your system.

Building for Android
--------------------

There is no Python or Qt present by default and both need to be shipped with the application.

The current solution can be summarized like this:

1. Statically cross-compile Python 3 for Android using the Android NDK
2. Statically compile PyOtherSide against the Android Python build and bundle the Python standard library inside the PyOtherSide binary
3. Use the Qt 5 SDK to make a QtQuick application - the SDK will handle bundling of your application file and of the PyOtherSide binary automatically

A more detailed guide follows. It describes how to get from the source code of the relevant components to being able to run an Android application
with a Qt Quick 2.0 GUI running on an Android device. The `gPodder` podcast aggregator serves as (full featured & fully functional!) example of such an application.

Performed in this environment:

* Fedora 20
* Qt 5.3.1 Android SDK
* latest Android SDK with API level 14 installed
* OpenJDK 1.7
* a few GB of harddrive space
* an Android 4.0+ device connected to the computer that is accessible over ``adb`` (eq. the debugging mode is enabled)

*This is just one example environment where these build instructions have been tested to work. Reasonably similar environments should work just as well.*

The build is going to be done in a folder called ``build`` in the users home directory,
lets say that the use is named ``user`` (replace accordingly for your environment).

We start in the home directory:

.. code-block:: sh
mkdir build
cd build
Now clone the needed projects, load submodules and switch to correct branches.

.. code-block:: sh
git clone --branch fixes https://github.com/thp/python3-android
git clone https://github.com/thp/pyotherside
git clone --recursive https://github.com/gpodder/gpodder-android
Next we will build Python 3 for Android. This will first download the Android NDK, then Python 3 source code, followed by crosscompiling the Python 3 code for Android on ARM.
*NOTE that this step alone can require multiple GB of harddisk space.*

.. code-block:: sh
cd python3-android
make all
As the next step we modify the ``python.pri.android`` file to point to our Python build. If should look like this as a result (remember to modify it for your environment):

.. code-block:: qmake
QMAKE_LIBS += -L/home/user/build/python3-android/build/9d-14-arm-linux-androideabi-4.8/lib -lpython3.3m -ldl -lm -lc -lssl -lcrypto
QMAKE_CXXFLAGS += -I/home/user/build/python3-android/build/9d-14-arm-linux-androideabi-4.8/include/python3.3m/
Then copy the file over the python.pri file in the PyOtherSide project directory:

.. code-block:: sh
cd ..
cp python3-android/python.pri.android pyotherside/python.pri
PyOtherSide can also help us ship & load the Python standard library if we can provide it a suitable zip bundle, which can be created like this:

.. code-block:: sh
cd python3-android/build/9d-14-arm-linux-androideabi-4.8/lib/python3.3/
zip -r pythonlib.zip *
cd ../../../../..
For PyOtherSide to include the packed Python standard library it needs to be placed in its src subfolder:

.. code-block:: sh
mv python3-android/build/9d-14-arm-linux-androideabi-4.8/lib/python3.3/pythonlib.zip pyotherside/src/
PyOtherSide will then use the qrc mechanism to compile the compressed standard library during inside it's own binary. This removes the need for us to handle its shipping & loading ourself.

Next you need to build PyOtherSide with QtCreator from the Qt 5.3 Android SDK, so make sure that the Qt 5.3 Android kit is using the exact same NDK that has been used to build Python 3 for Android. To do that go to *settings*, find the *kits* section, select the Android kit and make sure that the NDK path points to:

``/home/user/build/python3-android/sdk/android-ndk-r9d``

Next open the pyotherside/pyotherside.pro project file on QtCreator, select the Android kit and once the project loads go to the *project view* and make sure that under *run* the API level is set to 14 (this corresponds to Android 4.0 and later). The Android Python 3 build has been built for API level 14 and our PyOtherSide build should do the same to be compatible.

Also make sure that shadow build is disabled, just in case.

Once done with the configuration got to the *build* menu and select the *built pyotherside* option - this should build PyOtherSide for Android and statically compile in our Python build and also include the Python standard library zip file with qrc.

As the next step we need to move the PyOtherSide binary to the QML plugin folder for the Qt Android SDK, so that it can be fetched by the SDK when building gPodder.

Let's say we have the SDK installed in the ``/opt`` directory (default for the Qt SDK installer on Linux), giving us this path to the plugin folder:

``/opt/Qt5.3/5.3/android_armv7/qml``

First create the folder structure for the pyotherside plugin:

.. code-block:: sh
mkdir -p /opt/Qt5.3/5.3/android_armv7/qml/io/thp/pyotherside
Then copy the pyotherside binary and *qmldir* file to the folder:

.. code-block:: sh
cp pyotherside/src/libpyothersideplugin.so /opt/Qt5.3/5.3/android_armv7/qml/io/thp/pyotherside/
cp pyotherside/src/qmldir /opt/Qt5.3/5.3/android_armv7/qml/io/thp/pyotherside/
Next open the gPodder project in QtCreator (gpodder-android/gpodder-android.pro) and again make sure the Android kit is selected, that the API level 14 is used and that *shadow build* is disabled. Then just press the *Run* button and the SDK should build an Android APK that includes the libpyotherside binary (it fetched automatically from the plugins directory because is referenced in the gPodder QML source code) and deploy it to the device where gPodder should be started.

.. _gPodder: http://gpodder.org/

Building for Windows
--------------------

On Windows (tested versions: Windows 7), you need to download:

1. Qt 5 (VS 2010) from `qt-project.org downloads`_ (tested: 5.2.1)
2. `Visual C++ 2010 Express`_ with `SP1`_
3. Python 3 from `python.org Windows downloads`_ (tested: 3.3.4)

We use VS 2010 instead of MinGW, because the MinGW version of Qt depends on
working OpenGL driver, whereas the non-OpenGL version uses Direct3D via ANGLE.
Also, Python is built with Visual C++ 2010 Express (see `Compiling Python on
Windows`_), so using the same toolchain when linking all three components (Qt,
Python and PyOtherSide) together makes sense.

The necessary customizations for building PyOtherSide successfully on Windows
have been integrated recently, and are available since PyOtherSide 1.3.0.

.. _qt-project.org downloads: http://qt-project.org/downloads
.. _Visual C++ 2010 Express: http://www.visualstudio.com/en-us/downloads/download-visual-studio-vs#DownloadFamilies_4
.. _SP1: https://www.microsoft.com/en-US/download/details.aspx?id=23691
.. _python.org Windows downloads: http://python.org/downloads/windows/
.. _Compiling Python on Windows: http://docs.python.org/devguide/setup.html#windows-compiling

Once these pre-requisites are installed, you need to make some customizations
to the build setup:

1. In ``src/qmldir``: Change ``plugin pyothersideplugin`` to ``plugin
pyothersideplugin1``. This is needed, because on Windows, the library
version gets encoded into the library name.

2. In ``python.pri``: Modify it so that the Python 3 ``libs/`` folder is
added to the linker path, and link against ``-lpython33``. Also, modify
it so that the Python 3 ``include/`` folder is added to the compiler flags.

Example ``python.pri`` file for a standard Python 3.3 installation on Windows:

.. code-block:: qmake
QMAKE_LIBS += -LC:\Python33\libs -lpython33
QMAKE_CXXFLAGS += -IC:\Python33\include\
With the updated ``qmldir`` and ``python.pri`` files in place, simply open
the ``pyotherside.pro`` project file in Qt Creator, and build the project.
Configure a **Release Build**, and *disable* **Shadow Builds**.

To install PyOtherSide into your Qt installation, so that the QML import works
from other projects:

1. Make sure the PyOtherSide project is opened in Qt Creator
2. In the left column, select **Projects**
3. Make sure the **Run** tab (Run Settings) of your project is selected
4. In **Deployment**, click **Add Deploy Step** and select **Make**
5. In the **Make arguments:** field, type ``install``
6. Hit **Run** to install PyOtherSide in your local Qt folder
7. Dismiss the "Custom Executable" dialog that pops up

Known Problems:

* **Qt Resource System** importing might not fully work on Windows


ChangeLog
=========

Version UNRELEASED (YYYY-MM-DD)
Version 1.6.0 (2022-08-05)
-------------------------------

* Support for **Qt 6** (Qt 5 is still supported for now)
* Use ``PyUnicode_AsUTF8`` from Python 3.3 when converting strings; strings returned
from the converter are now valid as long as the ``PyObject`` is alive (previously
they were valid until the next string conversion or until converter was destroyed)
* Fixed ``image_loader`` and ``imageprovider_svg_data`` examples
* Removed outdated build instructions for Android and Windows

Version 1.5.9 (2020-01-17)
--------------------------
Expand Down
2 changes: 1 addition & 1 deletion pyotherside.pri
@@ -1,2 +1,2 @@
PROJECTNAME = pyotherside
VERSION = 1.5.9
VERSION = 1.6.0
2 changes: 1 addition & 1 deletion src/converter.h
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/pyobject_converter.h
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/pyotherside_plugin.cpp
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/pyotherside_plugin.h
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/qml_python_bridge.h
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/qpython.cpp
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/qpython.h
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/qpython_imageprovider.cpp
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/qpython_imageprovider.h
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/qpython_priv.cpp
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/qpython_priv.h
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/qpython_worker.cpp
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/qpython_worker.h
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion src/qvariant_converter.h
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.cpp
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.h
@@ -1,7 +1,7 @@

/**
* PyOtherSide: Asynchronous Python 3 Bindings for Qt 5 and Qt 6
* Copyright (c) 2011, 2013-2020, Thomas Perl <m@thp.io>
* Copyright (c) 2011, 2013-2022, Thomas Perl <m@thp.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down

0 comments on commit 63eb529

Please sign in to comment.