Skip to main content

QGIS plugin development and packaging tools, which make managing runtime dependencies easy.

Project description

qgis-plugin-dev-tools

QGIS plugin development and packaging tools, which make managing runtime dependencies easy.

Prerequisites

Your plugin package must be available to import from the python environment this tool is run in. For example, running python -c "import your_plugin_package_name" should not fail. Additionally, any dependency libraries must also be available in the python environment, so a dependency to some_pypi_package needs something like pip install some_pypi_package for this tool to work.

Limitations

Bundling works by copying the code as-is and replacing the imports in all bundled files, so native library dependencies and other special cases might not work. To be safe, only depend on pure python libraries. Also verify the result zip works, since some import statements or sys.modules usage might not be supported.

Setup

Install this library with pip install qgis-plugin-dev-tools.

Create a pyproject.toml tool section:

[tool.qgis_plugin_dev_tools]
plugin_package_name = "your_plugin_package_name"

If the plugin runtime depends on external libraries, add the distribution names to runtime_requires list as abstract dependencies.

[tool.qgis_plugin_dev_tools]
plugin_package_name = "your_plugin_package_name"
runtime_requires = [
    "some_pypi_package"
]

If the plugin runtime dependencies have many dependencies themselves, it is possible to include those recursively with auto_add_recursive_runtime_dependencies. Alternatively, all the requirements can be listed in runtime_requires.

[tool.qgis_plugin_dev_tools]
plugin_package_name = "your_plugin_package_name"
runtime_requires = [
    "some_pypi_package"
]
auto_add_recursive_runtime_dependencies = true

If the plugin runtime dependencies do not work with the aforementioned configuration, the dependencies can be added to the Python Path with use_dangerous_vendor_sys_path_append flag. This method might be unsafe if there are conflicts between dependency versions of different plugins.

[tool.qgis_plugin_dev_tools]
plugin_package_name = "your_plugin_package_name"
runtime_requires = [
    "some_pypi_package_with_binary_files"
]
use_dangerous_vendor_sys_path_append = true

By default build version number is read from changelog top-most second level heading having format ## version anything. This behaviour is configurable with version_number_source to use plugin package distribution metadata. Optionally, the version number can also be provided as an argument for the build script using qpdt b --version 0.1.0-rc2.

[tool.qgis_plugin_dev_tools]
plugin_package_name = "your_plugin_package_name"
version_number_source = "distribution"  # or "changelog" (default if missing)

Plugin packaging

Run qgis-plugin-dev-tools build (short qpdt b) to package the plugin and any runtime dependencies to a standard QGIS plugin zip file, that can be installed and published.

By default config is read from pyproject.toml, changelog notes from CHANGELOG.md, version from changelog, and package is created in a dist directory in the current working directory. Changelog contents and version number are inserted to the metadata.txt file, so the version and changelog sections do not need manual updates.

Plugin publishing

Run qgis-plugin-dev-tools publish <file> (short qpdt publish <file>) to publish a previously built plugin zip file to QGIS plugin repository.

By default username and password are read from QPDT_PUBLISH_USERNAME and QPDT_PUBLISH_PASSWORD environment variables.

Plugin development mode

Run qgis-plugin-dev-tools start (short qpdt s) to launch QGIS with the plugin installed and ready for development.

By default config is read from pyproject.toml and runtime config from .env in the current working directory. Extra environment files can be passed using -e flag. .env must configure the executable path, and may configure debugger, profile name and any extra runtime variables necessary for the plugin.

QGIS_EXECUTABLE_PATH= # path to qgis-bin/qgis-bin-ltr or .exe equivalents, necessary
# DEBUGGER_LIBRARY= # debugpy/pydevd to start a debugger on init, library must be installed to the environment
# DEVELOPMENT_PROFILE_NAME= # name of the profile that qgis is launched with, otherwise uses default

# any other variables are added to the runtime QGIS environment
# SOMETHING=something

Development mode bootstraps the launched QGIS to have access to any packages available to the launching python environment, setups enviroment variables, configures a debugger, and installs and enables the developed plugin package.

Additionally editable installs for the plugin dependencies are supported. For example with a dependency to some_pypi_package, use pip install -e /path/to/some_pypi_package to provide some_pypi_package in editable mode from a local directory, and use Plugin Reloader to refresh new code when its changed on disk. This will also reload the declared dependencies.

Developing multiple plugins

Development mode also enables using and developing multiple plugins easily if certain requirements are satisfied for all extra plugins:

  • Extra plugin must be installable python packages
  • Extra plugin must have entry point in group "qgis_plugin_dev_tools"
  • Extra plugin needs to be installed in the same python environment where this tool is run in

Extra plugins are loaded on launch and reloaded together with the main plugin if Plugin Reloader is used.

Development of qgis-plugin-dev-tools

See development readme.

License & copyright

Licensed under GNU GPL v3.0.

Copyright (C) 2022 National Land Survey of Finland.

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

0.6.2 - 2023-09-27

  • Fix: Fix issues with bundling requirements of the requirements recursively

0.6.1 - 2023-09-06

  • update author email

0.6.0 - 2023-02-17

  • Feat: Support dependencies having package references in .ui files

0.5.0 - 2022-11-09

  • Feat: Add publish command to cli
  • Fix: Support build without actually importing the code
  • Fix: Preserve case for key names in metadata file

0.4.0 - 2022-11-01

  • Feat: Add an option to get version from distribution metadata
  • Fix: Rewrite imports correctly when dependency name is a prefix of the plugin package name

0.3.0 - 2022-09-02

  • Feat: Add an option to append vendor package to the Python Path
  • Feat: Add an option to bundle requirements of the requirements recursively
  • Feat: Add module packages and .pyd files to the bundle if found
  • Feat: Add version as an optional build argument
  • Chore: Drop support from Python < 3.9

0.2.1 - 2022-07-07

  • Fix: Correct some plain import rewrites

0.2.0 - 2022-06-13

  • Feat: enable extra plugins in development mode

0.1.2 - 2022-05-30

  • Fix: use UTF-8 encoding for file reads/writes

0.1.1 - 2022-05-16

  • Fix: rewrite runtime requirement imports correctly

0.1.0 - 2022-05-12

  • Initial release: start and build commands with minimal configuration options.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qgis-plugin-dev-tools-0.6.2.tar.gz (37.9 kB view details)

Uploaded Source

Built Distribution

qgis_plugin_dev_tools-0.6.2-py3-none-any.whl (44.9 kB view details)

Uploaded Python 3

File details

Details for the file qgis-plugin-dev-tools-0.6.2.tar.gz.

File metadata

  • Download URL: qgis-plugin-dev-tools-0.6.2.tar.gz
  • Upload date:
  • Size: 37.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for qgis-plugin-dev-tools-0.6.2.tar.gz
Algorithm Hash digest
SHA256 06925106fa94592ee7cc5890acdeeb2fe9cc71eefe6982268e4497987790740b
MD5 f6287327736d158bdbcf83b56329dc70
BLAKE2b-256 69d08c23c78561b4ad741777800cbe4a98ad94493ec49fb0c70eef2f2b9af87b

See more details on using hashes here.

Provenance

File details

Details for the file qgis_plugin_dev_tools-0.6.2-py3-none-any.whl.

File metadata

File hashes

Hashes for qgis_plugin_dev_tools-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7edef2a26cd824c6740a672c57a97b70166d54653c5df1ea007d7b87de3222e3
MD5 db87d9ceb977fb804432be8ffb8da674
BLAKE2b-256 efb835d35da2d339c83e7f281b1bd33ec3d6f1600c9271c8498e8cfc7e8b3328

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page