How to set up a QGIS plugin project and development environment in minutes
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
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 | 10.5446/68481 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
| |
Keywords |
FOSS4G Europe 2024 Tartu63 / 156
6
33
35
53
55
59
61
67
70
87
97
99
102
103
104
105
107
111
121
122
123
124
125
126
127
128
134
144
150
151
155
00:00
Plug-in (computing)Quaternion groupMusical ensembleIntegrated development environmentSoftware developerProjective planeLecture/Conference
00:40
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
05:52
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
11:05
Template (C++)Interactive televisionPlug-in (computing)Inclusion mapAlgorithmProjective planeRule of inferenceGroup actionSampling (statistics)InternetworkingProcess (computing)Plug-in (computing)Directory serviceComputer animationSource codeJSONXML
12:53
Gamma functionInternet service providerGUI widgetTemplate (C++)Computer fileSource codeJSON
13:22
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
17:31
Physical systemInstallation artRevision control1 (number)Plug-in (computing)
18:11
Virtual realityInterpreter (computing)Physical systemRevision controlComputer fileInterpreter (computing)Structural loadGraphics tabletWebsitePlug-in (computing)Physical systemLink (knot theory)
18:52
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
21:15
Installation artVirtual realityIntegrated development environmentVenn diagramRevision controlData structurePlug-in (computing)Template (C++)Lecture/ConferenceComputer animation
21:34
PiText editorCodeIntegrated development environmentConfiguration spaceComputer fileGroup actionProjective plane1 (number)Library (computing)FreewareSource codeComputer animationLecture/Conference
22:53
Sign (mathematics)Least squaresComputer-assisted translationComputer animation
Transcript: English(auto-generated)
00:00
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
00:32
easily. I hope so. Yeah, first something about GSPO.
00:43
So, we are 25 people, we do consulting, developing, training, also have support for customers
01:01
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.
01:22
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.
01:47
I have a little note that the presentation has a lot of Windows specific things, but
02:01
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.
02:20
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
02:48
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
03:12
tools at GSPO and now I would like to share those tools and our ideas also for
03:25
you to make, hopefully, your life easier too. I would like to see more well-structured plug-ins out there.
03:44
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
04:08
needed ones and developing those as a developer, the experience is not that good to develop
04:23
those plug-ins. What is QGIS Python plug-in? Basically, it's just a directory, there needs to be a file called metadata where
04:44
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
05:08
and then all the necessary Python files and some UI files and when you publish those,
05:20
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.
06:02
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,
06:28
but when you learn and are used to do that with a real code editor, IDE, it's not going back.
06:46
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
07:07
environment and to make sure that your plug-in works and works also after you modify some files,
07:22
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,
07:49
you could do that debugging in the code editor and not with the print statements.
08:01
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.
08:27
And formatting is basically how you, where do you put your next lines,
08:41
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.
09:10
And then also type annotation checks should be used, I think so. And then also version control and CI thing, automatic tests and
09:32
also they're publishing the plug-in to the QGIS plug-in repo should be optimized also.
09:45
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
10:02
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.
10:29
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
10:49
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
11:06
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
11:28
and if you want to add GitHub actions for the CI.
11:43
And about the license, if you want to have a sample processing algorithm in your plug-in and here it asks also the linting,
12:02
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.
12:23
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
12:47
user permission. And this is how it looks inside the vs code. As you can see there are
13:04
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.
13:29
This is not the only template out there. There is the original one, plug-in builder
13:48
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
14:08
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.
14:34
So the IDE must know which Python interpreter to use and where the QGIS Python package is
14:43
located at and how is the Qt API. It's a binary package so the vs code at least
15:00
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
15:24
environment variables so it could find the right paths. And the virtual environment
15:45
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
16:03
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
16:31
executable not the one that finds from the bin directory. And then there are also some other things to keep in mind.
16:46
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.
17:08
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
17:25
plugin project you just call the file and how that looks.
17:40
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
18:06
compatible with the older versions. So what that tool actually does, it uses the same interpreter as QGIS.
18:22
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.
18:49
And to deploy your plugin just create a symbolic link from your developing directory to the directory where QGIS loads the user plugins.
19:10
And after that you should enable that plugin from the QGIS plugin manager.
19:21
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.
19:42
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.
20:04
And yeah please test those, share your ideas, send some issues in GitHub or pull requests. Those are really welcome. Okay, thank you.
20:27
Thanks a lot for this insightful talk. Now we have the opportunity to ask questions.
20:42
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.
21:03
It's not, it's not included here. There is a QGIS plugin CI tools or I don't remember.
21:27
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.
21:46
I don't remember, now I don't have the library project here. But there is a GitHub action to do the publishing.
22:03
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?
22:25
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.
22:42
And it's easy to just load and start to work with. Okay, all right, then thanks again. Yeah, thank you.