Skip to content

Commit

Permalink
Change to use cookiecutter's native boolean variables
Browse files Browse the repository at this point in the history
This changes custom handling of yes/no choices to native boolean
variables. This kind of reverts the 3842cab and does it better.
  • Loading branch information
LKajan authored Mar 15, 2024
1 parent 2412616 commit e743fbc
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 50 deletions.
9 changes: 3 additions & 6 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"GitHub",
"None"
],
"add_vscode_config": "n",
"add_vscode_config": true,
"license": [
"GPL2",
"GPL3",
"other"
],
"include_processing": "n",
"use_qgis_plugin_tools": "y",
"include_processing": false,
"use_qgis_plugin_tools": true,
"linting": [
"hatch",
"minimal"
Expand All @@ -25,9 +25,6 @@
".github/workflows/release.yml",
"docs/push_translations.yml"
],
"_extensions": [
"local_extensions.selected"
],
"__prompts__": {
"plugin_name": "Select a name for your plugin",
"project_directory": "Name of the project directory",
Expand Down
6 changes: 3 additions & 3 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ def main():

git_init()

if is_true("{{ cookiecutter.use_qgis_plugin_tools | selected }}"):
if is_true("{{ cookiecutter.use_qgis_plugin_tools }}"):
add_plugin_tools()
else:
remove_plugin_tools()

if not is_true("{{ cookiecutter.add_vscode_config | selected }}"):
if not is_true("{{ cookiecutter.add_vscode_config }}"):
remove_vscode_files()

if "{{ cookiecutter.git_repo_url }}":
Expand All @@ -156,7 +156,7 @@ def main():
if "{{ cookiecutter.ci_provider }}".lower() != "github":
remove_github_files()

if not is_true("{{ cookiecutter.include_processing | selected }}"):
if not is_true("{{ cookiecutter.include_processing }}"):
remove_processing_files()

if "{{ cookiecutter.linting }}".lower() != "hatch":
Expand Down
6 changes: 0 additions & 6 deletions local_extensions.py

This file was deleted.

24 changes: 12 additions & 12 deletions tests/test_cookiecutter_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def session_context():
"git_repo_organization": "my-org",
"git_repo_url": "https://github.com/my-org/my-qgis-plugin",
"ci_provider": "None",
"add_vscode_config": "n",
"include_processing": "n",
"add_vscode_config": False,
"include_processing": False,
"license": "GPL2",
"use_qgis_plugin_tools": "n", # to make test run faster
"use_qgis_plugin_tools": False, # to make test run faster
}


Expand All @@ -41,9 +41,9 @@ def context(session_context: dict[str, str]):
{},
{"plugin_package": LONG_PACKAGE_NAME},
{"ci_provider": "None"},
{"add_vscode_config": "y"},
{"include_processing": "y"},
{"use_qgis_plugin_tools": "y"},
{"add_vscode_config": True},
{"include_processing": True},
{"use_qgis_plugin_tools": True},
{"license": "GPL3"},
]

Expand Down Expand Up @@ -145,10 +145,10 @@ def baked_project(self, cookies_session: Cookies) -> Result:
extra_context = {
"plugin_name": "My QGIS plugin",
"ci_provider": "None",
"add_vscode_config": "n",
"include_processing": "n",
"add_vscode_config": False,
"include_processing": False,
"license": "GPL2",
"use_qgis_plugin_tools": "n",
"use_qgis_plugin_tools": False,
}
return cookies_session.bake(extra_context=extra_context)

Expand Down Expand Up @@ -179,10 +179,10 @@ def baked_project(self, cookies_session: Cookies) -> Result:
extra_context = {
"plugin_name": "My QGIS plugin",
"ci_provider": "GitHub",
"add_vscode_config": "y",
"include_processing": "y",
"add_vscode_config": True,
"include_processing": True,
"license": "GPL2",
"use_qgis_plugin_tools": "y",
"use_qgis_plugin_tools": True,
}
return cookies_session.bake(extra_context=extra_context)

Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_directory}}/README.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

Refer to [development](docs/development.md) for developing this QGIS3 plugin.

{% if cookiecutter.add_vscode_config | selected -%}
{% if cookiecutter.add_vscode_config -%}
### VsCode setup

Select the Python interpreter with Command Palette (Ctrl+Shift+P). Select `Python: Select Interpreter` and choose
Expand Down
10 changes: 5 additions & 5 deletions {{cookiecutter.project_directory}}/docs/development.md.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Development of {{cookiecutter.project_directory}} plugin
===========================

{% if cookiecutter.use_qgis_plugin_tools| selected -%}
{% if cookiecutter.use_qgis_plugin_tools -%}
This project uses [qgis_plugin_tools](https://github.com/{{cookiecutter.git_repo_organization}}/qgis_plugin_tools) submodule,
so set git setting value: `git config --global submodule.recurse true`.

Expand All @@ -19,7 +19,7 @@ The code for the plugin is in the [{{cookiecutter.plugin_package}}](../{{cookiec
Qt with Qt Editor and Qt Linquist installed by following this
[tutorial](https://www.qgistutorials.com/en/docs/3/building_a_python_plugin.html#get-the-tools).

{% if cookiecutter.use_qgis_plugin_tools| selected -%}
{% if cookiecutter.use_qgis_plugin_tools -%}
For building the plugin use platform independent [build.py](../{{cookiecutter.project_directory}}/build.py) script.

## Setting up development environment
Expand Down Expand Up @@ -71,12 +71,12 @@ If you create or edit source files make sure that:
from ..utils.exceptions import TestException # Bad

```
{%- if cookiecutter.use_qgis_plugin_tools| selected %}
{%- if cookiecutter.use_qgis_plugin_tools %}
* they will be found by [build.py](../{{cookiecutter.plugin_package}}/build.py) script (`py_files` and `ui_files` values)
{% endif %}
* you consider adding test files for the new functionality

{%- if cookiecutter.use_qgis_plugin_tools| selected %}
{%- if cookiecutter.use_qgis_plugin_tools %}
## Deployment

Edit [build.py](../{{cookiecutter.plugin_package}}/build.py) to contain working values for *profile*, *lrelease* and *pyrcc*. If you are
Expand Down Expand Up @@ -136,7 +136,7 @@ lrelease section as well. You can however pull manually to test the process.

* Run `qgis-plugin-ci pull-translation --compile <your-transifex-token>`

{%- if cookiecutter.use_qgis_plugin_tools| selected -%}
{%- if cookiecutter.use_qgis_plugin_tools -%}
#### Translating with QT Linguistic (if Transifex not available)

The translation files are in [i18n](../{{cookiecutter.project_directory}}/resources/i18n) folder. Translatable content in python files is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ from __future__ import annotations

from typing import Callable

{% if cookiecutter.include_processing| selected -%}
{% if cookiecutter.include_processing -%}
from qgis.core import QgsApplication
{% endif -%}
from qgis.PyQt.QtCore import QCoreApplication, QTranslator
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, QWidget
from qgis.utils import iface

{% if cookiecutter.include_processing| selected -%}
{% if cookiecutter.include_processing -%}
{% endif -%}
{% if cookiecutter.plugin_package|length < 7 -%}
from {{cookiecutter.plugin_package}}.qgis_plugin_tools.tools.custom_logging import setup_logger, teardown_logger
Expand Down Expand Up @@ -112,7 +112,7 @@ class Plugin:

return action

{% if cookiecutter.include_processing| selected -%}
{% if cookiecutter.include_processing -%}
def initProcessing(self): # noqa N802
self.provider = Provider()
QgsApplication.processingRegistry().addProvider(self.provider)
Expand All @@ -127,7 +127,7 @@ class Plugin:
parent=iface.mainWindow(),
add_to_toolbar=False,
)
{%- if cookiecutter.include_processing| selected %}
{%- if cookiecutter.include_processing %}
self.initProcessing()
{%- endif %}

Expand All @@ -140,7 +140,7 @@ class Plugin:
iface.removePluginMenu(Plugin.name, action)
iface.removeToolBarIcon(action)
teardown_logger(Plugin.name)
{%- if cookiecutter.include_processing| selected %}
{%- if cookiecutter.include_processing %}
QgsApplication.processingRegistry().removeProvider(self.provider)
{%- endif %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ from __future__ import annotations

from typing import Callable

{% if cookiecutter.include_processing| selected -%}
{% if cookiecutter.include_processing -%}
from qgis.core import QgsApplication
{% endif -%}
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, QWidget
from qgis.utils import iface
{%- if cookiecutter.include_processing| selected %}
{%- if cookiecutter.include_processing %}

from {{cookiecutter.plugin_package}}.{{cookiecutter.plugin_package}}_processing.provider import Provider
{%- endif %}
Expand Down Expand Up @@ -90,7 +90,7 @@ class Plugin:

return action

{% if cookiecutter.include_processing| selected -%}
{% if cookiecutter.include_processing -%}
def initProcessing(self): # noqa N802
self.provider = Provider()
QgsApplication.processingRegistry().addProvider(self.provider)
Expand All @@ -105,7 +105,7 @@ class Plugin:
parent=iface.mainWindow(),
add_to_toolbar=False,
)
{%- if cookiecutter.include_processing| selected %}
{%- if cookiecutter.include_processing %}
self.initProcessing()
{%- endif %}

Expand All @@ -117,7 +117,7 @@ class Plugin:
for action in self.actions:
iface.removePluginMenu(Plugin.name, action)
iface.removeToolBarIcon(action)
{%- if cookiecutter.include_processing| selected %}
{%- if cookiecutter.include_processing %}
QgsApplication.processingRegistry().removeProvider(self.provider)
{%- endif %}

Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.project_directory}}/pyproject.toml.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.pytest.ini_options]
addopts = "-v"

{% if cookiecutter.use_qgis_plugin_tools| selected -%}
{% if cookiecutter.use_qgis_plugin_tools -%}
[tool.coverage.report]
omit = ["{{cookiecutter.plugin_package}}/qgis_plugin_tools/*"]

Expand All @@ -28,7 +28,7 @@ unfixable = [
"F841", # unused variables
]

{% if cookiecutter.use_qgis_plugin_tools| selected -%}
{% if cookiecutter.use_qgis_plugin_tools -%}
exclude = ["{{cookiecutter.plugin_package}}/qgis_plugin_tools"]

[[tool.mypy.overrides]]
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_directory}}/requirements-dev.in.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- if cookiecutter.add_vscode_config != "n" -%}
{%- if cookiecutter.add_vscode_config -%}
# Debugging
debugpy

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% if cookiecutter.use_qgis_plugin_tools| selected -%}
{% if cookiecutter.use_qgis_plugin_tools -%}
import os
{% endif -%}
from typing import TYPE_CHECKING
{%- if cookiecutter.use_qgis_plugin_tools| selected %}
{%- if cookiecutter.use_qgis_plugin_tools %}

from {{cookiecutter.plugin_package}}.qgis_plugin_tools.infrastructure.debugging import (
setup_debugpy, # noqa F401
Expand All @@ -13,7 +13,7 @@ from {{cookiecutter.plugin_package}}.qgis_plugin_tools.infrastructure.debugging

if TYPE_CHECKING:
from qgis.gui import QgisInterface
{%- if cookiecutter.use_qgis_plugin_tools| selected %}
{%- if cookiecutter.use_qgis_plugin_tools %}

debugger = os.environ.get("QGIS_PLUGIN_USE_DEBUGGER", "").lower()
if debugger in {"debugpy", "ptvsd", "pydevd"}:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- if cookiecutter.use_qgis_plugin_tools| selected -%}
{%- if cookiecutter.use_qgis_plugin_tools -%}
{%- include 'plugin_templates/plugin_with_submodule.py.j2' -%}
{%- else -%}
{%- include 'plugin_templates/plugin_without_submodule.py.j2' -%}
Expand Down

0 comments on commit e743fbc

Please sign in to comment.