Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ on:

jobs:

flake8:
ruff:
runs-on: ubuntu-latest
steps:

- name: Setup Python 3.9
- name: Setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.12
architecture: x64

- name: Checkout
Expand All @@ -43,8 +43,11 @@ jobs:
- name: Install Python requirements
run: pip install -r requirements/dev.txt

- name: Run flake8
run: flake8
- name: Run ruff linter
run: ruff check

- name: Run ruff formatter
run: ruff format --check

tests-unit:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -73,7 +76,7 @@ jobs:
run: pytest tests/unit/

release:
needs: [flake8, tests-unit]
needs: [ruff, tests-unit]

runs-on: ubuntu-latest
if: github.repository_owner == 'Artelia' && contains(github.ref, 'refs/tags/')
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
*.pyc
.idea/workspace.xml
.idea/*
.vscode/*
__pycache__
*.qm
*.zip
.env
.venv
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
exclude: ".venv|__pycache__|tests/dev/|tests/fixtures/"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
args:
- --maxkb=500
- id: check-case-conflict
- id: check-toml
- id: check-xml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: trailing-whitespace
args:
- --markdown-linebreak-ext=md

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.12.12"
hooks:
- id: ruff
args:
- --fix
- --target-version=py312
types_or:
- python
- pyi
- id: ruff-format
args:
- --line-length=120
- --target-version=py312
types_or:
- python
- pyi
41 changes: 41 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
// Editor
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active",
"files.associations": {
"./requirements/*.txt": "pip-requirements",
"metadata.txt": "ini",
"**/*.model3": "xml",
"**/*.ts": "xml",
"**/*.ui": "xml"
},
// Python
"python.analysis.autoFormatStrings": false, // breaking PyQt translation
"python.analysis.typeCheckingMode": "off",
"python.terminal.activateEnvInCurrentTerminal": true,
"python.terminal.activateEnvironment": true,
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports.ruff": "explicit",
"source.fixAll.ruff": "explicit"
},
"editor.rulers": [
120
],
"editor.wordWrapColumn": 120,
},

// Ruff
"ruff.importStrategy": "fromEnvironment",
"ruff.configuration": "./pyproject.toml",

// Tests
"python.testing.unittestEnabled": true,
"python.testing.pytestEnabled": true,
// Extensions
"autoDocstring.docstringFormat": "sphinx",
"python-envs.defaultEnvManager": "ms-python.python:venv",
"python-envs.pythonProjects": [],
}
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Contributing Guidelines

First off, thanks for considering to contribute to this project!

These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.

## Git hooks

We use git hooks through [pre-commit](https://pre-commit.com/) to enforce and automatically check some "rules". Please install them (`pre-commit install`) before to push any commit.

See the relevant configuration file: `.pre-commit-config.yaml`.

## Code Style

Make sure your code *roughly* follows [PEP-8](https://www.python.org/dev/peps/pep-0008/) and keeps things consistent with the rest of the code:

- docstrings: [sphinx-style](https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html#the-sphinx-docstring-format) is used to write technical documentation.
- formatting: [ruff formatter](https://docs.astral.sh/ruff/formatter/) is used to automatically format the code without debate.
- sorted imports: [ruff linter](https://docs.astral.sh/ruff/linter/) is used to sort imports
- static analisis: [ruff linter](https://docs.astral.sh/ruff/linter/) is used to catch some dizziness and keep the source code healthy.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
# Mesh Tools
# Mesh Tools

Tools for management of data using Mesh format for Telemac or Uhaina
More informations on Telemac could be found on [Open Telemac-Mascaret website]("http://www.opentelemac.org/")
More informations on Uhaina could be found (soon)

## Installation

Use the QGIS Plugins menu to install the Mesh Tools Plugin

## Development
Some makefile methods require to install few dependecies.

For translations `make transup` and `make transcompile`:
This project is configured with the following tools:

```bash
apt install qttools5-dev-tools pyqt5-dev-tools
```
- [ruff](https://docs.astral.sh/ruff/) to format the code without any existential question and sort import

For code formating `make black`:
Code rules are enforced with [pre-commit](https://pre-commit.com/) hooks.
Static code analisis is based on: Flake8

```bash
pip install black isort
```
See also: [contribution guidelines](CONTRIBUTING.md).

## License

Mesh_Tools plugin is free software.
You can redistribute it anf/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation.
3 changes: 0 additions & 3 deletions help/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# MeshTools documentation build configuration file, created by
# sphinx-quickstart on Sun Feb 12 17:11:03 2012.
Expand All @@ -11,8 +10,6 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
10 changes: 5 additions & 5 deletions mesh_tools/__about__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#! python3 # noqa: E265

"""
Metadata about the package to easily retrieve informations about it.
See: https://packaging.python.org/guides/single-sourcing-package-version/
Metadata about the package to easily retrieve informations about it.
See: https://packaging.python.org/guides/single-sourcing-package-version/
"""

# ############################################################################
Expand Down Expand Up @@ -50,7 +50,7 @@ def plugin_metadata_as_dict() -> dict:
if PLG_METADATA_FILE.is_file():
config.read(PLG_METADATA_FILE.resolve(), encoding="UTF-8")
return {s: dict(config.items(s)) for s in config.sections()}
raise IOError(f"Plugin metadata.txt not found at: {PLG_METADATA_FILE}")
raise OSError(f"Plugin metadata.txt not found at: {PLG_METADATA_FILE}")


# ############################################################################
Expand All @@ -65,7 +65,7 @@ def plugin_metadata_as_dict() -> dict:
__email__ = __plugin_md__.get("general").get("email")
__keywords__ = [t.strip() for t in __plugin_md__.get("general").get("repository").split("tags")]
__license__ = "GPLv3"
__summary__ = f'{__plugin_md__.get("general").get("description")}\n{__plugin_md__.get("general").get("about")}'
__summary__ = f"{__plugin_md__.get('general').get('description')}\n{__plugin_md__.get('general').get('about')}"

__title__ = __plugin_md__.get("general").get("name")
__title_clean__ = "".join(e for e in __title__ if e.isalnum())
Expand All @@ -91,6 +91,6 @@ def plugin_metadata_as_dict() -> dict:
print("Version : " + __version__)
print("Description : " + __summary__)
print(
f'Pour : {plugin_md.get("general").get("qgisminimumversion")} < QGIS < {plugin_md.get("general").get("qgismaximumversion", "3.99")}'
f"Pour : {plugin_md.get('general').get('qgisminimumversion')} < QGIS < {plugin_md.get('general').get('qgismaximumversion', '3.99')}"
)
print(__title_clean__)
1 change: 0 additions & 1 deletion mesh_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
MeshTools
Expand Down
11 changes: 4 additions & 7 deletions mesh_tools/libs/MeshUtils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

"""
/***************************************************************************
MeshUtils
Expand All @@ -22,9 +20,8 @@
* *
***************************************************************************/
"""
import functools

from typing import Optional
import functools

from qgis.core import (
QgsCoordinateTransform,
Expand Down Expand Up @@ -120,14 +117,14 @@ def xyFromN(nativeMesh: QgsMesh, n: int, mesh_xorm: QgsCoordinateTransform, laye
return point, error

@staticmethod
def createVerticesSpatialIndex(nativeMesh: QgsMesh, xform: Optional[QgsCoordinateTransform] = None):
def createVerticesSpatialIndex(nativeMesh: QgsMesh, xform: QgsCoordinateTransform | None = None):
spindex = QgsSpatialIndex()

count = nativeMesh.vertexCount()
offset = 0
batch_size = 10
while offset < count:
lst_ft = list()
lst_ft = []
iterations = min(batch_size, count - offset)
for i in range(iterations):
ft = QgsFeature()
Expand Down Expand Up @@ -158,7 +155,7 @@ def computeNeighbors(nativeMesh: QgsMesh) -> dict:
for vertex in verticies:
neighbors = list(verticies)
neighbors.remove(vertex)
if vertex in dico.keys():
if vertex in dico:
for neighbor in neighbors:
if neighbor not in dico[vertex]:
dico[vertex].append(neighbor)
Expand Down
37 changes: 0 additions & 37 deletions mesh_tools/libs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,37 +0,0 @@
# -*- coding: utf-8 -*-

"""
/***************************************************************************
classFactory
A QGIS plugin
Tools for management of Data on mesh (Telemac, Uhaina)
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2021-03-24
git sha : $Format:%H$
copyright : (C) 2021 by Artelia/BRGM/ISL
email : a@a
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""


# noinspection PyPep8Naming
def classFactory(iface): # pylint: disable=invalid-name
"""Load MeshTools class from file MeshTools.

:param iface: A QGIS interface instance.
:type iface: QgsInterface
"""
#
from .mesh_tools import MeshTools

return MeshTools(iface)
4 changes: 1 addition & 3 deletions mesh_tools/libs/create_shp_dlg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

"""
/***************************************************************************
dlg_create_culvert_shapefile
Expand Down Expand Up @@ -35,7 +33,7 @@

class dlg_create_shapefile(QDialog, FORM_CLASS):
def __init__(self, name, crs_mesh=None, parent=None):
super(dlg_create_shapefile, self).__init__()
super().__init__()
self.setupUi(self)
self.tr = parent.tr
self.setWindowTitle(self.tr("New {} layer", self.__class__.__name__).format(name))
Expand Down
Loading