We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

How to set up a QGIS plugin project and development environment in minutes

00:00

Formal Metadata

Title
How to set up a QGIS plugin project and development environment in minutes
Title of Series
Number of Parts
156
Author
License
CC Attribution 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
Creating a new QGIS plugin and setting up a working development environment from scratch can be daunting, especially for beginners or occasional developers. In this talk, I present a templating tool that simplifies and streamlines the plugin development process. The tool is based on Cookiecutter, a well-known command-line utility that generates projects from templates. The template (https://github.com/GispoCoding/cookiecutter-qgis-plugin) we at Gispo developed: - is highly customizable and follows the best practices for QGIS plugin development - includes features such as testing, documentation, internationalization, packaging, continuous integration and development environment creation - allows anyone to quickly start a new plugin project in minutes with minimal effort and consistent structure I demonstrate how to use the tool, how to modify the template options, and how to publish the plugin to the QGIS plugin repository. I also share some tips and tricks for developing and maintaining QGIS plugins. This talk targets anyone who is interested in creating or improving QGIS plugins, regardless of their experience or expertise.
Keywords
127
Plug-in (computing)Quaternion groupMusical ensembleIntegrated development environmentSoftware developerProjective planeLecture/Conference
Channel capacityBuildingOpen sourceSource codeSoftwareCore dumpComputing platformPlug-in (computing)Integrated development environmentSoftware developerComputer fileModal logicInternet forumDirectory serviceHome pageComputer fileSoftware developerOpen sourceDifferent (Kate Ryan album)Video gameBitPlug-in (computing)1 (number)Integrated development environmentSoftwareMetadataPresentation of a groupWindowAuthorizationLatent heatStructural loadProjective planeModal logicPhysical systemData managementDirectory serviceWave packetInformation technology consultingComputer animationLecture/Conference
Modal logicComputer filePlug-in (computing)Directory serviceVirtual realityIntegrated development environmentExecution unitSoftware testingData typeTemplate (C++)Interactive televisionPlug-in (computing)Statement (computer science)File formatLetterpress printingProjective planeLine (geometry)MathematicsCodeFunctional (mathematics)CodeLatent heatIntegrated development environmentReal numberSoftware testingText editorRule of inferenceSoftware repositoryHTTP cookieVirtual reality1 (number)VirtualizationType theoryComputer fileTemplate (C++)Unit testingRevision controlLecture/ConferenceXMLComputer animation
Template (C++)Interactive televisionPlug-in (computing)Inclusion mapAlgorithmProjective planeRule of inferenceGroup actionSampling (statistics)InternetworkingProcess (computing)Plug-in (computing)Directory serviceComputer animationSource codeJSONXML
Gamma functionInternet service providerGUI widgetTemplate (C++)Computer fileSource codeJSON
Template (C++)Plug-in (computing)Axiom of choiceIntegrated development environmentStapeldateiSet (mathematics)Variable (mathematics)Interpreter (computing)Template (C++)Virtual realityDirectory serviceIntegrated development environmentBinary fileComputer fileWindowProjective planeData structureMetropolitan area networkSimilarity (geometry)Axiom of choiceInterpreter (computing)CodeStapeldateiScripting languageVariable (mathematics)Right anglePlug-in (computing)JSONXMLComputer animationLecture/Conference
Physical systemInstallation artRevision control1 (number)Plug-in (computing)
Virtual realityInterpreter (computing)Physical systemRevision controlComputer fileInterpreter (computing)Structural loadGraphics tabletWebsitePlug-in (computing)Physical systemLink (knot theory)
Link (knot theory)Plug-in (computing)Integrated development environmentGenetic programmingDirectory serviceGastropod shellPower (physics)Scripting languageTemplate (C++)Ideal (ethics)Human migrationPlug-in (computing)Software testingTemplate (C++)Structural loadProcess (computing)PlanningLibrary (computing)Repository (publishing)Data managementCase moddingLink (knot theory)Directory serviceOperator (mathematics)CodePersonal digital assistantComputer fileData Encryption StandardShared memoryLecture/ConferenceMeeting/Interview
Installation artVirtual realityIntegrated development environmentVenn diagramRevision controlData structurePlug-in (computing)Template (C++)Lecture/ConferenceComputer animation
PiText editorCodeIntegrated development environmentConfiguration spaceComputer fileGroup actionProjective plane1 (number)Library (computing)FreewareSource codeComputer animationLecture/Conference
Sign (mathematics)Least squaresComputer-assisted translationComputer animation
Transcript: English(auto-generated)
Hi everybody, my name is Laurik Bayan and I come from GSPO. We are based in Finland and today I'm going to present to you something about QGIS plug-in development and, well, basically how to set up a plug-in project and environment for that
easily. I hope so. Yeah, first something about GSPO.
So, we are 25 people, we do consulting, developing, training, also have support for customers
and do all, I think it's at least most of the things, maybe all the things with open source software and we like to talk open source.
So, why I'm having this talk previously, setting up a plug-in project and developing environment has been quite tedious, at least on Windows.
I have a little note that the presentation has a lot of Windows specific things, but
if you are on other OS, then it is still relevant for you and there is going to be some nice tips also for you.
On Windows, at least, there has been a lot of manual work to set up the environment and when you develop a lot of plug-ins, it makes that even more tedious. If you don't have any system for setting up plug-ins, every plug-in has to be a little
bit different and different tools and it's hard to maintain. So, to make our life a little bit easier, we have developed some tools, development
tools at GSPO and now I would like to share those tools and our ideas also for
you to make, hopefully, your life easier too. I would like to see more well-structured plug-ins out there.
In the plug-in manager, I don't know how many hundreds or are there now even more than a thousand plug-ins, I don't remember, but most of those are just plain, only the
needed ones and developing those as a developer, the experience is not that good to develop
those plug-ins. What is QGIS Python plug-in? Basically, it's just a directory, there needs to be a file called metadata where
you specify the name and the author and your home page for the plug-in and things and then where everything starts, the init.py, it loads the plug-in from through that file
and then all the necessary Python files and some UI files and when you publish those,
it is just a compressed folder, a zip file, so they are not needed to make a plug-in, so how hard it could be. So, I think it's much more needed to give a good developing experience for the developer.
Here I have some ideas what I think that needs to be set up for the not specific QGIS plug-in, but I think that for any Python project, the coding, you could do that in any text editor,
but when you learn and are used to do that with a real code editor, IDE, it's not going back.
And the good practice is to use virtual Python environment for developing, so you don't miss the Python environment inside the QGIS, you should always have a virtual
environment and to make sure that your plug-in works and works also after you modify some files,
then it's useful to have unit testing included and also some way to debug your code, not just print statements inside the code, if the debugging is set up right,
you could do that debugging in the code editor and not with the print statements.
And then there should be some linting and formatting done. Linting is those rules that are how you should write the code, which functions or style of code you should use over other ones.
And formatting is basically how you, where do you put your next lines,
do you use the next line after every comma or how do you format the code. None of these changes the functionality of the code, but it makes it much more nicer to work with.
And then also type annotation checks should be used, I think so. And then also version control and CI thing, automatic tests and
also they're publishing the plug-in to the QGIS plug-in repo should be optimized also.
So there needs to be a lot of things in the plug-in project. So we have developed templates for that, it's openly available at our GitHub
and what it actually is, you can do setup interactively, it asks you questions that about your preferences, how, what features you want to include to your project.
And you use that with a cookie cutter templating tool, you can install that with pip or then maybe the recommended way how to run all the command line tools with Python
is install it with pipx, then it makes a isolated environment for each command line tool. So first thing is to install a cookie cutter and then run that second command
and how it looks like. First it asks the name of the plug-in and then the project directory, what's the name of the actual plug-in package
and if you want to add GitHub actions for the CI.
And about the license, if you want to have a sample processing algorithm in your plug-in and here it asks also the linting,
which kind of linting rules you want to use. There's a project called Hatch, it has well created linting rules, there are more than 500 rules in that, so I like that one.
And then it asks, says what to do next. I could have included this also as automatic steps but it installs some things from pipy, so I don't want to call to the internet without
user permission. And this is how it looks inside the vs code. As you can see there are
quite many files in the project and without this template you should write those by yourself. So that's why we made this template. And here are our developing dependencies.
This is not the only template out there. There is the original one, plug-in builder
created by the grand old man Gary Sherman, the guy who started the QGIS project. And then there is also another QGIS template by Ocelandia. They have
some similarities but they have made some different choices. You should check that also. So now we have the project but how to set up the actual environment, how you use the IDE.
So the IDE must know which Python interpreter to use and where the QGIS Python package is
located at and how is the Qt API. It's a binary package so the vs code at least
doesn't know how the API is, so there is also a Python package for that. Normally, previously IDE has been started with a startup script or a batch file where it sets
environment variables so it could find the right paths. And the virtual environment
as I said that should be used and all the developing dependencies should be installed inside the virtual environment instead of the QGIS Python environment so those doesn't
mess up there with the QGIS environment. Well, creating this burnup has been difficult on Windows. The osgeo4w windows has some custom structure so you have to create that with the right
executable not the one that finds from the bin directory. And then there are also some other things to keep in mind.
So to create the virtual environment we have also developed a tool for that. It works with Windows, Linux and there is already a pull request for Mac OS.
So it's a single file, you could embed that to your existing project or you can install that also with the PPX and then inside the
plugin project you just call the file and how that looks.
It detects all the PyQGIS installations from your system and then you just choose which ones you use for developing that tool. So probably you should use the LTR version to make your plugin most
compatible with the older versions. So what that tool actually does, it uses the same interpreter as QGIS.
Loads all the dependencies, Python dependencies as a system site package and creates two files. And those two files you could do manually also, but there is also always some issues with the users to get the paths right.
And to deploy your plugin just create a symbolic link from your developing directory to the directory where QGIS loads the user plugins.
And after that you should enable that plugin from the QGIS plugin manager.
And there is no need to copy any files or any other things to do. And if you make modifications to the plugin code just use the plugin reloader plugin to reload your plugin.
And in the future the template is quite old, I know that it needs some refreshment. Maybe we are considering to create operation to use copier. And then our creator it's instead quite new, needs more testing.
And yeah please test those, share your ideas, send some issues in GitHub or pull requests. Those are really welcome. Okay, thank you.
Thanks a lot for this insightful talk. Now we have the opportunity to ask questions.
Yeah great, thanks for your talk. I'm just wondering are there any plans or is there any assistance to help publish the plugins once they're developed to the QGIS repository? Or is that simple enough already, that step of the process of creating a plugin? Yeah, there is a library for that.
It's not, it's not included here. There is a QGIS plugin CI tools or I don't remember.
But it's, I think it should be included in that plugin template I showed you. Yeah and at least here is the configuration file for the tool.
I don't remember, now I don't have the library project here. But there is a GitHub action to do the publishing.
So I have another question regarding the IDE or the text editor. Like what is your recommendation or have you tried various ones? Like there's of course like VS code or PyCharm or maybe just some Notepad++, I'm not sure. So what is your recommendation or what have you experienced?
There are many who use PyCharm, that's really a good one. I like VS code. It's free so you don't have to worry about licenses.
And it's easy to just load and start to work with. Okay, all right, then thanks again. Yeah, thank you.