Skip to content

Commit

Permalink
markdownlinting
Browse files Browse the repository at this point in the history
  • Loading branch information
griembauer committed Nov 28, 2024
1 parent 592d943 commit 46ce1a9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
22 changes: 11 additions & 11 deletions How-to-create-a-GRASS-GIS-addon.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## How does it work at all?
# How does it work at all?

GRASS GIS is written in more than one programming language. While most
of the source code is written in C, about 30% is written in Python. A
Expand Down Expand Up @@ -33,15 +33,15 @@ A GRASS python module consists of
- either a python script (most easy with one script as whole addon)
- or C code

### Reuse & Recycle... and refactor!
### Reuse & Recycle... and refactor

- it helps if GRASS GIS source code is there to look at
- best to look at existing GRASS addons
- [r.mapcalc.simple](https://github.com/OSGeo/grass/tree/master/scripts/r.mapcalc.simple)
- [v.example](https://github.com/mundialis/v.example)
- ...
- inside the GRASS GIS source code all python modules are in folder 'scripts'
- or see <https://grasswiki.osgeo.org/wiki/Category:Python>, especially <https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library>
- or see [https://grasswiki.osgeo.org/wiki/Category:Python](https://grasswiki.osgeo.org/wiki/Category:Python), especially [https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library](https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library)
- use `r.blend --script` and it will generate how it would look like as addon (like a template, not a copy of source code!) (will always create generic long version)
- use of predefinded functions `import grass.script as grass` (e.g. `grass.run_command`, `grass.message`, `grass.fatal`, `grass.warning`, `grass.read_command`)
- See [script documentation](https://grass.osgeo.org/grass-devel/manuals/libpython/script.html) for more usage examples
Expand All @@ -53,7 +53,7 @@ A GRASS python module consists of
- add linting workflow
- add workflow to run tests
- Submitting rules:
- https://github.com/OSGeo/grass/blob/master/CONTRIBUTING.md
- [https://github.com/OSGeo/grass/blob/master/CONTRIBUTING.md](https://github.com/OSGeo/grass/blob/master/CONTRIBUTING.md)

### Structure (here `r.blend` as example)

Expand All @@ -63,27 +63,27 @@ A GRASS python module consists of

1. `# % ` comments are important (ignored by python but important for parser)

- See https://grass.osgeo.org/grass-devel/manuals/g.parser.html
- See [https://grass.osgeo.org/grass-devel/manuals/g.parser.html](https://grass.osgeo.org/grass-devel/manuals/g.parser.html)

```shell
r.blend -c first=aspect second=elevation output=elev_shade_blend
```

###### `# % module`
#### `# % module`

- including `keyword` to make it appear in keyword searches and lists

###### `# % options`
#### `# % options`

- (e.g. 'input', 'output', 'first'), some are predefined (predefined or custom, predefined is more convenient but also needs more knowledge to use)
- key is key in command line (e.g. 'first')
- answer is default values
- access them in main function like `options['first']`
- there are also [standard options](%22https://grass.osgeo.org/grass-devel/manuals/parser_standard_options.html) which can be extended

###### `# % flag`
#### `# % flag`

###### `# % rules`
#### `# % rules`

- define dependencies between options, required options and more. See official [docs](https://grass.osgeo.org/grass-devel/manuals/g.parser.html#conditional-parameters)

Expand Down Expand Up @@ -131,7 +131,7 @@ A GRASS python module consists of
- use existing functions: esp. from PyGRASS

- [PyGRASS API description](https://grass.osgeo.org/grass-devel/manuals/libpython/pygrass_index.html)
- PyGRASS paper: An Object Oriented Python Application Programming Interface (API) for GRASS: https://www.mdpi.com/2220-9964/2/1/201/htm
- PyGRASS paper: An Object Oriented Python Application Programming Interface (API) for GRASS: [https://www.mdpi.com/2220-9964/2/1/201/htm](https://www.mdpi.com/2220-9964/2/1/201/htm)

```python
# i18N
Expand Down Expand Up @@ -249,7 +249,7 @@ For more information on standardized messages see [here](https://trac.osgeo.org/
### Steps on GitHub

- Every addon gets its own GitHub repo
- default location is at https://github.com/mundialis. If needed they can be integrated somewhere else as submodule.
- default location is at [https://github.com/mundialis](https://github.com/mundialis). If needed they can be integrated somewhere else as submodule.
- Choose "GPL3" as license
- Copy code to new repository (not via `git remote` if sensitive information are included)
- Release new addon in GitHub with 1.0.0
Expand Down
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Steps when releasing:

- Run in terminal
```
#!/bin/bash
ESTIMATED_VERSION=1.0.0
REPO_NAME=mundialis/grass-gis-helpers
Expand Down
3 changes: 3 additions & 0 deletions markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
default: true
MD038: false # no-space-in-code Spaces inside code span elements
43 changes: 43 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Ruff configuration file: ruff.toml

# Define the required version for Ruff
required-version = ">=0.7.0"

line-length = 79

# Specify directories or files to be excluded from Ruff linting, in addition to default exclusions
extend-exclude = [
".git",
"__pycache__",
".env",
".venv",
"env",
"venv",
"ENV",
"env.bak",
"venv.bak",
"ctypes",
"pydispatch",
]

# Uncomment the following sections as needed

# [format]
# Format settings for Ruff (quote-style and indent-style)
# quote-style = "double"
# indent-style= "tab"

# [lint]
# Define linting rules selection and ignore list
# select = [
# "A", # flake8-builtins (A)
# "COM", # flake8-commas
# "PL", # Pylint
# ]
ignore = [
"F821", # Undefined name `_`
]

# [lint.per-file-ignores]
# Define file-specific linting rule ignores
# "lib_dop/r_dop_import_lib.py" = ["ERA001", "PLR2004"]

0 comments on commit 46ce1a9

Please sign in to comment.