diff options
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | docs/extensions.md | 8 | ||||
-rw-r--r-- | examples/examples.pro | 1 | ||||
-rw-r--r-- | examples/numpysetup/__init__.py | 60 | ||||
-rw-r--r-- | examples/numpysetup/setup.py | 62 | ||||
-rw-r--r-- | plugins/pythonextensions/pythonextensionsplugin.cpp | 28 | ||||
-rw-r--r-- | plugins/pythonextensions/pythonextensionsplugin.h | 1 |
7 files changed, 7 insertions, 164 deletions
@@ -125,16 +125,13 @@ The following process allows the plugin to work: 1. At compile time, Shiboken generates a huge amount of C++ code that allows a few classes from the Core plugin and utils library to be - accessed from Python. + accessed from Python. 2. When QtCreator is executed, the C++ plugin searches the standard QtCreator plugin directories for a directory named `python`, the first directory found is the Python extension directory. - - Now, each package in this directory represents it's own Python extension. - For each package the C++ plugin checks whether it - contains a `setup.py`. If it does, this setup script is executed. - - After all the setup scripts have been executed, each package is loaded - with `import`, which executes the initialization code in its - `__init__.py`. + Each python package in this directory represents it's own Python extension. + Each package is loaded with `import`, which executes the initialization + code in its `__init__.py`. 3. Now all Python extensions have registered their actions / menus / etc., which can be triggered from the QtCreator interface. diff --git a/docs/extensions.md b/docs/extensions.md index 6d4998d..4b3689a 100644 --- a/docs/extensions.md +++ b/docs/extensions.md @@ -117,13 +117,11 @@ are reserved for the ExtensionManager. Unless you know exactly what you are doin touch any of these variables. ## Installing dependencies -There are two ways you can install dependencies. If you need very fine-grained control over how -extension looks like before it can be run, you can supply a `setup.py` script, which is run -separately before your extension is started. An example of such a script can be found in the example -extension `examples/numpysetup`. -If you only want to install dependencies, you can also include a standard Python `requirements.txt` +If you want to install dependencies, you can include a standard Python `requirements.txt` file in your extension folder. **Note that this file is pip installed _once_.** After the initial pip install, a new file called `requirements.txt.installed` is created in the extensions folder. To run the install again, this file simply has to be deleted. **Be careful to remove this file, when distributing your extension in a .zip file.** + +Otherwise you can do any setup you need in your extension's initialization code. diff --git a/examples/examples.pro b/examples/examples.pro index 58de286..fc65149 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -8,7 +8,6 @@ include($$IDE_SOURCE_TREE/qtcreator.pri) inst_examples.files = \ macroexpander \ - numpysetup \ projects \ requirerequests \ smallmenu \ diff --git a/examples/numpysetup/__init__.py b/examples/numpysetup/__init__.py deleted file mode 100644 index cf67157..0000000 --- a/examples/numpysetup/__init__.py +++ /dev/null @@ -1,60 +0,0 @@ -############################################################################# -## -## Copyright (C) 2018 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Python Extensions Plugin for QtCreator. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -# This example illustrates the use of external -# Python modules - -import numpy as np -from PythonExtension import QtCreator -from PySide2.QtWidgets import QMessageBox - -def dotProduct(): - a = np.array([1,2,3], float) - b = np.array([4,5,6], float) - return np.dot(a, b) - -def show(): - box = QMessageBox() - box.setText("[1,2,3] * [4,5,6] = {}".format(dotProduct())) - box.exec_() - -# Add this to the "Window" menu -menu = QtCreator.Core.ActionManager.actionContainer("QtCreator.Menu.Window") -menu.menu().addAction("Show dot product", show) diff --git a/examples/numpysetup/setup.py b/examples/numpysetup/setup.py deleted file mode 100644 index 901bbe4..0000000 --- a/examples/numpysetup/setup.py +++ /dev/null @@ -1,62 +0,0 @@ -############################################################################# -## -## Copyright (C) 2018 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Python Extensions Plugin for QtCreator. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -# Setup script that installs required modules. -# If you simply want to make sure a Python -# module is installed, you can use this script -# directly. -# The modules are installed locally for QtCreator -# and are not accessible from the system Python. - -import importlib, subprocess, sys -from PythonExtension import PluginInstance as instance - -def setup(modules=None): - def install(module): - cmd = "{0} -m pip install -I -t {1} {2}".format(sys.executable, instance.pythonPackagePath(), module) - subprocess.call(cmd.split()) - for module in modules: - try: - importlib.import_module(module) - except ImportError: - install(module) - -if __name__ == "__main__": - setup(["numpy"]) diff --git a/plugins/pythonextensions/pythonextensionsplugin.cpp b/plugins/pythonextensions/pythonextensionsplugin.cpp index f0ddcc5..bb8c18a 100644 --- a/plugins/pythonextensions/pythonextensionsplugin.cpp +++ b/plugins/pythonextensions/pythonextensionsplugin.cpp @@ -105,8 +105,6 @@ bool PythonExtensionsPlugin::delayedInitialize() initializeOptionalBindings(); // Pip install any requirements known for the script installRequirements(); - // Run the setup for each extension that requires it - setupPythonExtensions(); // Python plugins are initialized here, to avoid blocking on startup initializePythonExtensions(); return true; @@ -225,32 +223,6 @@ void PythonExtensionsPlugin::installRequirements() } } -void PythonExtensionsPlugin::setupPythonExtensions() -{ - // Run the setup.py file for all extensions that provide it. - // later, there might be a way to determine if the setup needs - // to run. - QDir extension_dir = extensionDir(); - if (!extension_dir.exists()) - return; - - QStringList extension_list = extensionList(); - for (const QString &extension : extension_list) { - QFile extension_setup(extension_dir.absolutePath() + "/" + extension + "/setup.py"); - if (extension_setup.open(QIODevice::ReadOnly)) { - QTextStream in(&extension_setup); - QString setup_code = in.readAll(); - if (!PyUtil::runScriptWithPath( - setup_code.toStdString(), - QString(extension_dir.absolutePath() + "/" + extension).toStdString() - )) { - qWarning() << "Failed to setup extension" << extension; - Core::MessageManager::write(Constants::MESSAGE_MANAGER_PREFIX + tr("Failed to setup extension ") + extension); - } - } - } -} - void PythonExtensionsPlugin::initializePythonExtensions() { // Search python directory in plugin paths diff --git a/plugins/pythonextensions/pythonextensionsplugin.h b/plugins/pythonextensions/pythonextensionsplugin.h index a920911..053fbc2 100644 --- a/plugins/pythonextensions/pythonextensionsplugin.h +++ b/plugins/pythonextensions/pythonextensionsplugin.h @@ -58,7 +58,6 @@ private: void initializePythonBindings(); void initializeOptionalBindings(); void installRequirements(); - void setupPythonExtensions(); void initializePythonExtensions(); }; |