-
Notifications
You must be signed in to change notification settings - Fork 1
Home
This page will get you started for creating a MO2 python plugin.
It is possible to write a MO2 python plugin using any text editor, but this guide will focus on [Visual Studio Code]. This guide assumes that:
- You have Visual Studio Code installed with the Python extension.
- You have Python installed: https://www.python.org/downloads/.
- It is recommended but not mandatory to use the Python version that is used by MO2.
You can check the
pythonXX.dll
in the MO2 installation folder to find the Python version used by MO2 (python38.dll
means Python 3.8).
- It is recommended but not mandatory to use the Python version that is used by MO2.
You can check the
- You obviously need a valid MO2 installation: https://github.com/modorganizer2/modorganizer
- This guide is written for MO2 ≥ 2.3.0.
Note: In the following, I will refer to the MO2 installation directory as $MO2DIR
. So if you installed MO2 at C:\MO2
and you are asked to copy a file to $MO2DIR/plugins
, it refers to C:\MO2\plugins
.
Note: This part is optional but highly recommended if you want a proper environment to work with. Everything here is written to be as simple as possible but you can of course adapt it to your preferences: use a python virtual environment, use workspace settings instead of global ones, etc.
mobase
is the MO2 Python module. The module is written in C++ and thus cannot be read directly by tools such as flake8
or mypy
.
Instead, we provide stubs which can be used for auto-completion or type-checking.
The stubs for mobase
are available at https://github.com/ModOrganizer2/pystubs-generation/tree/master/stubs. You want to download the mobase.pyi
file in the folder corresponding to your MO2 version and put it under $MO2DIR/plugins/data
.
Note: It is possible to put the stubs in a different location, but we are going to use $MO2DIR/plugins/data
for PyQt5, so we might as well use it for the stubs.
We are going to configure Visual Studio Code to have auto-completion and linting (error and type checking) for the MO2 Python module.
Open settings.json
(Ctrl+Shift+P, then "Open Settings (JSON)"), and add the following entries:
"python.linting.enabled": true,
"python.linting.mypyEnabled": true,
"python.linting.flake8Enabled": true,
"python.autoComplete.extraPaths": [
"$MO2DIR\\plugins\\data",
]
There are multiply way to configure mypy
:
- You can create a
mypy.ini
file somewhere containing:
[mypy]
mypy_path = $MO2DIR\plugins\data
And then add the following to settings.json
(replace with the correct path):
"python.linting.mypyArgs": [
"--config-file=path-to-mypy.ini",
]
- You can set the
MYPYPATH
environment variable to$MO2DIR\plugins\data
.