Skip to content

Commit

Permalink
Merge branch '264-undocumented-limit-of-10-isochrone-ranges-keyerror-…
Browse files Browse the repository at this point in the history
…10' of https://github.com/GIScience/orstools-qgis-plugin into 264-undocumented-limit-of-10-isochrone-ranges-keyerror-10
  • Loading branch information
merydian committed Aug 23, 2024
2 parents 4eebbc1 + c2f8656 commit dad3af0
Show file tree
Hide file tree
Showing 20 changed files with 1,225 additions and 17 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

name: Testing

on:
pull_request:

jobs:
test_3_16:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run test 3.16
run: |
docker run -v ${GITHUB_WORKSPACE}:/src -w /src qgis/qgis:release-3_16 sh -c 'apt-get -y update && apt-get -y install xvfb && export ORS_API_KEY=${{ secrets.ORS_API_KEY }} && export DISPLAY=:0.0 && pip install -U pytest && xvfb-run pytest'
env:
DOCKER_IMAGE: ${{ steps.docker-build.outputs.FULL_IMAGE_NAME }}
test_3_22:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run test 3.22
run: |
docker run -v ${GITHUB_WORKSPACE}:/src -w /src qgis/qgis:release-3_22 sh -c 'apt-get -y update && apt-get -y install xvfb && export DISPLAY=:0.0 && export ORS_API_KEY=${{ secrets.ORS_API_KEY }} && export DISPLAY=:0.0 && pip install -U pytest && xvfb-run pytest'
env:
DOCKER_IMAGE: ${{ steps.docker-build.outputs.FULL_IMAGE_NAME }}
test_latest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run test latest
run: |
docker run -v ${GITHUB_WORKSPACE}:/src -w /src qgis/qgis:latest sh -c 'apt-get -y update && apt-get -y install xvfb && export DISPLAY=:0.0 && export ORS_API_KEY=${{ secrets.ORS_API_KEY }} && apt install python3-pytest && xvfb-run pytest'
env:
DOCKER_IMAGE: ${{ steps.docker-build.outputs.FULL_IMAGE_NAME }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
tets/
docs/wiki/OSMtools.wiki/
.idea/
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ RELEASING:
### Fixed
- Log the correct ApiError message in the isochrone processing algorithm with > 10 ranges ([#264](https://github.com/GIScience/orstools-qgis-plugin/issues/264))

## [1.8.4] - 2024-07-29

### Fixed
- issue with missing locale value for non-default user([#271](https://github.com/GIScience/orstools-qgis-plugin/issues/271))

## [1.8.3] - 2024-05-29

### Fixed
Expand Down Expand Up @@ -81,6 +86,10 @@ RELEASING:
- Improved type hints


# Unreleased
### Added
- Unit- and e2e-testing

## [1.7.1] - 2024-01-15

### Added
Expand Down Expand Up @@ -261,7 +270,8 @@ RELEASING:
- first working version of ORS Tools, after replacing OSM Tools plugin


[unreleased]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.3...HEAD
[unreleased]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.4...HEAD
[1.8.4]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.3...v1.8.4
[1.8.3]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.2...v1.8.3
[1.8.2]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.1...v1.8.2
[1.8.1]: https://github.com/GIScience/orstools-qgis-plugin/compare/v1.8.0...v1.8.1
Expand Down
3 changes: 2 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2021 HeiGIT gGmbH
Copyright (c) 2017 Nils Nolde
Copyright (c) 2019 HeiGIT gGmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 22 additions & 0 deletions ORStools/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2017 Nils Nolde
Copyright (c) 2019 HeiGIT gGmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 17 additions & 10 deletions ORStools/ORStoolsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from qgis.gui import QgisInterface
from qgis.core import QgsApplication, QgsSettings
from qgis.PyQt.QtCore import QTranslator, qVersion, QCoreApplication
from qgis.PyQt.QtCore import QTranslator, qVersion, QCoreApplication, QLocale
import os.path

from .gui import ORStoolsDialog
Expand All @@ -56,15 +56,22 @@ def __init__(self, iface: QgisInterface) -> None:
self.plugin_dir = os.path.dirname(__file__)

# initialize locale
locale = QgsSettings().value("locale/userLocale")[0:2]
locale_path = os.path.join(self.plugin_dir, "i18n", "orstools_{}.qm".format(locale))

if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)

if qVersion() > "4.3.3":
QCoreApplication.installTranslator(self.translator)
try:
locale = QgsSettings().value("locale/userLocale")
if not locale:
locale = QLocale().name()
locale = locale[0:2]

locale_path = os.path.join(self.plugin_dir, "i18n", "orstools_{}.qm".format(locale))

if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)

if qVersion() > "4.3.3":
QCoreApplication.installTranslator(self.translator)
except TypeError:
pass

def initGui(self) -> None:
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
Expand Down
2 changes: 1 addition & 1 deletion ORStools/common/directions_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def build_default_parameters(


def get_extra_info_features_directions(
response: dict, extra_info_order: list[str], to_from_values: Optional[list] = None
response: dict, extra_info_order: List[str], to_from_values: Optional[list] = None
):
extra_info_order = [
key if key != "waytype" else "waytypes" for key in extra_info_order
Expand Down
6 changes: 5 additions & 1 deletion ORStools/gui/ORStoolsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
import os
from typing import Optional

import processing
try:
import processing
except ModuleNotFoundError:
pass

import webbrowser

from qgis._core import Qgis, QgsAnnotation
Expand Down
10 changes: 7 additions & 3 deletions ORStools/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ name=ORS Tools
qgisMinimumVersion=3.4.8
description=openrouteservice routing, isochrones and matrix calculations for QGIS

version=1.8.3
version=1.8.4
author=HeiGIT gGmbH
email=support@openrouteservice.heigit.org
email=support@smartmobility.heigit.org

about=ORS Tools provides access to most of the functions of openrouteservice.org, based on OpenStreetMap. The tool set includes routing, isochrones and matrix calculations, either interactive in the map canvas or from point files within the processing framework. Extensive attributes are set for output files, incl. duration, length and start/end locations.

changelog=2024/05/29 v1.8.3
changelog=2024/07/29 v1.8.4
Fixed
- issue with missing locale value

2024/05/29 v1.8.3
Fixed
- issues with extra_info in polylines/two point layer algorithms

Expand Down
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ORS Tools QGIS plugin

![Testing](https://github.com/Merydian/orstools-qgis-plugin/actions/workflows/test.yml/badge.svg)
![Ruff](https://github.com/Merydian/orstools-qgis-plugin/actions/workflows/ruff.yml/badge.svg)

![ORS Tools](https://user-images.githubusercontent.com/23240110/122937401-3ee72400-d372-11eb-8e3b-6c435d1dd964.png)

Set of tools for QGIS to use the [openrouteservice](https://openrouteservice.org) (ORS) API.
Expand Down Expand Up @@ -120,6 +123,65 @@ where `<qgis_plugins_path>` is one of:
- Windows: `C:\Users\USER\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ORStools`
- Mac OS: `Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/ORStools`

### CI
#### Testing
The repository tests on the QGis Versions *3.16*, *3.22* and the *latest* version.
Until now, it's only possible to test one version at a time.

#### Linux
On linux machines you can run the tests with your local QGIS installation.

1. Install QGIS and make sure it's available in your currently activated environment.

You will need an ORS-API key. Either set it as an environment variable or do `export ORS_API_KEY=[Your API key here]` before you run the tests.

To run the tests do:
```shell
cd orstools-qgis-plugin
pytest
```

#### Windows
Do all the following steps in a [*WSL*](https://learn.microsoft.com/en-us/windows/wsl/install). To run tests locally you can use a [conda installation](https://github.com/opengisch/qgis-conda-builder) of the QGis version you want to test.
You will also have to install *xvfb* to run the tests on involving an interface.
Lastly, we need [*Pytest*](https://docs.pytest.org/en/8.0.x/) to run tests in general.

To do the above run use these commands:
1. Install a version of anaconda, preferrably [*miniforge*](https://github.com/conda-forge/miniforge).

2. Create and prepare the environment.

```shell
# create environment
conda create --name qgis_test
# activate environment
conda activate qgis_test
# install pip
conda install pip
```

3. Install QGis using mamba.
```shell
conda install -c conda-forge qgis=[3.16, 3.22, latest] # choose one
```

4. Install *xvfb*
```shell
sudo apt-get update
sudo apt install xvfb
```

5. Install *Pytest* using pip in testing environment.
```shell
pip install -U pytest
```

To run the tests you will need an ORS-API key:
```shell
cd orstools-qgis-plugin
export ORS_API_KEY=[Your API key here] && xvfb-run pytest
```

### Debugging
In the **PyCharm community edition** you will have to use logging and printing to inspect elements.
The First Aid QGIS plugin can probably also be used additionally.
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# developement
ruff
pytest

# testing
pyyaml
pytest
Empty file added tests/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
import yaml

from ORStools.utils.configmanager import read_config

with open("ORStools/config.yml", "r+") as file:
data = yaml.safe_load(file)


def pytest_sessionstart(session):
"""
Called after the Session object has been created and
before performing collection and entering the run test loop.
"""
if data["providers"][0]["key"] == "":
data["providers"][0]["key"] = os.environ.get("ORS_API_KEY")
with open("ORStools/config.yml", "w") as file:
yaml.dump(data, file)
else:
raise ValueError("API key is not empty.")


def pytest_sessionfinish(session, exitstatus):
"""
Called after whole test run finished, right before
returning the exit status to the system.
"""
with open("ORStools/config.yml", "w") as file:
if not data["providers"][0]["key"] == "":
data['providers'][0]['key'] = '' # fmt: skip
yaml.dump(data, file)

config = read_config()
assert config["providers"][0]["key"] == '' # fmt: skip
Loading

0 comments on commit dad3af0

Please sign in to comment.