Skip to content

Commit c50e8be

Browse files
authored
Merge branch 'main' into 149-add-styling-from-qml-file
2 parents 3d8b0d8 + f7e4c6a commit c50e8be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+982
-760
lines changed

.github/workflows/ruff.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Ruff
2+
on: [ push, pull_request ]
3+
jobs:
4+
ruff:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v3
8+
- uses: chartboost/ruff-action@v1
9+
with:
10+
src: ORStools
11+
args: format --check
12+
- uses: chartboost/ruff-action@v1
13+
with:
14+
src: ORStools
15+
args: check

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ RELEASING:
4242
## Unreleased
4343

4444
### Added
45+
- Additional parameter for the "smoothing factor" to isochrones processing algorithms ([#172](https://github.com/GIScience/orstools-qgis-plugin/issues/172))
46+
- Mention omission of configuration options when using traveling salesman
47+
- option to set location type for isochrones ([#191](https://github.com/GIScience/orstools-qgis-plugin/pull/191))
4548
- Add styling of routing output in main plugin ([#149](https://github.com/GIScience/orstools-qgis-plugin/issues/149))
4649

4750
## [1.6.0] - 2023-07-25
@@ -50,7 +53,6 @@ RELEASING:
5053
- translation mechanism ([#183](https://github.com/GIScience/orstools-qgis-plugin/pull/183))
5154
- german translation ([#183](https://github.com/GIScience/orstools-qgis-plugin/pull/183))
5255

53-
5456
## [1.5.3] - 2023-03-30
5557

5658
### Fixed

ORStools/ORStoolsPlugin.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
class ORStools:
3939
"""QGIS Plugin Implementation."""
40+
4041
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
4142

4243
def __init__(self, iface):
@@ -54,17 +55,14 @@ def __init__(self, iface):
5455
self.plugin_dir = os.path.dirname(__file__)
5556

5657
# initialize locale
57-
locale = QSettings().value('locale/userLocale')[0:2]
58-
locale_path = os.path.join(
59-
self.plugin_dir,
60-
'i18n',
61-
'orstools_{}.qm'.format(locale))
58+
locale = QSettings().value("locale/userLocale")[0:2]
59+
locale_path = os.path.join(self.plugin_dir, "i18n", "orstools_{}.qm".format(locale))
6260

6361
if os.path.exists(locale_path):
6462
self.translator = QTranslator()
6563
self.translator.load(locale_path)
6664

67-
if qVersion() > '4.3.3':
65+
if qVersion() > "4.3.3":
6866
QCoreApplication.installTranslator(self.translator)
6967

7068
def initGui(self):

ORStools/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,28 @@ def classFactory(iface): # pylint: disable=invalid-name
4141
"""
4242

4343
from .ORStoolsPlugin import ORStools
44+
4445
return ORStools(iface)
4546

4647

4748
# Define plugin wide constants
48-
PLUGIN_NAME = 'ORS Tools'
49-
DEFAULT_COLOR = '#a8b1f5'
49+
PLUGIN_NAME = "ORS Tools"
50+
DEFAULT_COLOR = "#a8b1f5"
5051
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
5152

5253
RESOURCE_PREFIX = ":plugins/ORStools/img/"
53-
CONFIG_PATH = os.path.join(BASE_DIR, 'config.yml')
54-
ENV_VARS = {'ORS_REMAINING': 'X-Ratelimit-Remaining',
55-
'ORS_QUOTA': 'X-Ratelimit-Limit'}
54+
CONFIG_PATH = os.path.join(BASE_DIR, "config.yml")
55+
ENV_VARS = {"ORS_REMAINING": "X-Ratelimit-Remaining", "ORS_QUOTA": "X-Ratelimit-Limit"}
5656

5757
# Read metadata.txt
5858
METADATA = configparser.ConfigParser()
59-
METADATA.read(os.path.join(BASE_DIR, 'metadata.txt'), encoding='utf-8')
59+
METADATA.read(os.path.join(BASE_DIR, "metadata.txt"), encoding="utf-8")
6060
today = datetime.today()
6161

62-
__version__ = METADATA['general']['version']
63-
__author__ = METADATA['general']['author']
64-
__email__ = METADATA['general']['email']
65-
__web__ = METADATA['general']['homepage']
66-
__help__ = METADATA['general']['help']
67-
__date__ = today.strftime('%Y-%m-%d')
68-
__copyright__ = f'(C) {today.year} by {__author__}'
62+
__version__ = METADATA["general"]["version"]
63+
__author__ = METADATA["general"]["author"]
64+
__email__ = METADATA["general"]["email"]
65+
__web__ = METADATA["general"]["homepage"]
66+
__help__ = METADATA["general"]["help"]
67+
__date__ = today.strftime("%Y-%m-%d")
68+
__copyright__ = f"(C) {today.year} by {__author__}"

ORStools/common/__init__.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,33 @@
2828
"""
2929

3030
PROFILES = [
31-
'driving-car',
32-
'driving-hgv',
33-
'cycling-regular',
34-
'cycling-road',
35-
'cycling-mountain',
36-
'cycling-electric',
37-
'foot-walking',
38-
'foot-hiking',
39-
'wheelchair'
40-
]
31+
"driving-car",
32+
"driving-hgv",
33+
"cycling-regular",
34+
"cycling-road",
35+
"cycling-mountain",
36+
"cycling-electric",
37+
"foot-walking",
38+
"foot-hiking",
39+
"wheelchair",
40+
]
4141

42-
DIMENSIONS = ['time', 'distance']
42+
DIMENSIONS = ["time", "distance"]
4343

44-
PREFERENCES = ['fastest', 'shortest', 'recommended']
44+
PREFERENCES = ["fastest", "shortest", "recommended"]
4545

46-
OPTIMIZATION_MODES = ['Round Trip', 'Fix Start Point', 'Fix End Point', 'Fix Start and End Point']
46+
OPTIMIZATION_MODES = ["Round Trip", "Fix Start Point", "Fix End Point", "Fix Start and End Point"]
4747

48-
AVOID_FEATURES = ['highways', 'tollways', 'ferries', 'fords', 'steps']
48+
AVOID_FEATURES = ["highways", "tollways", "ferries", "fords", "steps"]
4949

50-
AVOID_BORDERS = ['all', 'controlled', 'none']
50+
AVOID_BORDERS = ["all", "controlled", "none"]
5151

52-
ADVANCED_PARAMETERS = ["INPUT_AVOID_FEATURES", "INPUT_AVOID_BORDERS", "INPUT_AVOID_COUNTRIES", "INPUT_AVOID_POLYGONS"]
52+
ADVANCED_PARAMETERS = [
53+
"INPUT_AVOID_FEATURES",
54+
"INPUT_AVOID_BORDERS",
55+
"INPUT_AVOID_COUNTRIES",
56+
"INPUT_AVOID_POLYGONS",
57+
"INPUT_SMOOTHING",
58+
]
59+
60+
LOCATION_TYPES = ["start", "destination"]

ORStools/common/client.py

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,29 @@ def __init__(self, provider=None):
5757
"""
5858
QObject.__init__(self)
5959

60-
self.key = provider['key']
61-
self.base_url = provider['base_url']
62-
self.ENV_VARS = provider.get('ENV_VARS')
60+
self.key = provider["key"]
61+
self.base_url = provider["base_url"]
62+
self.ENV_VARS = provider.get("ENV_VARS")
6363

6464
# self.session = requests.Session()
65-
retry_timeout = provider.get('timeout')
65+
retry_timeout = provider.get("timeout")
6666

6767
self.nam = networkaccessmanager.NetworkAccessManager(debug=False, timeout=retry_timeout)
6868

6969
self.retry_timeout = timedelta(seconds=retry_timeout)
7070
self.headers = {
71-
"User-Agent": _USER_AGENT,
72-
'Content-type': 'application/json',
73-
'Authorization': provider['key']
74-
}
71+
"User-Agent": _USER_AGENT,
72+
"Content-type": "application/json",
73+
"Authorization": provider["key"],
74+
}
7575

7676
# Save some references to retrieve in client instances
7777
self.url = None
7878
self.warnings = None
7979

8080
overQueryLimit = pyqtSignal()
81-
def request(self,
82-
url,
83-
params,
84-
first_request_time=None,
85-
retry_counter=0,
86-
post_json=None):
81+
82+
def request(self, url, params, first_request_time=None, retry_counter=0, post_json=None):
8783
"""Performs HTTP GET/POST with credentials, returning the body as
8884
JSON.
8985
@@ -124,14 +120,15 @@ def request(self,
124120
# 0.5 * (1.5 ^ i) is an increased sleep time of 1.5x per iteration,
125121
# starting at 0.5s when retry_counter=1. The first retry will occur
126122
# at 1, so subtract that first.
127-
delay_seconds = 1.5**(retry_counter - 1)
123+
delay_seconds = 1.5 ** (retry_counter - 1)
128124

129125
# Jitter this value by 50% and pause.
130126
time.sleep(delay_seconds * (random.random() + 0.5))
131127

132-
authed_url = self._generate_auth_url(url,
133-
params,
134-
)
128+
authed_url = self._generate_auth_url(
129+
url,
130+
params,
131+
)
135132
self.url = self.base_url + authed_url
136133

137134
# Default to the client-level self.requests_kwargs, with method-level
@@ -140,25 +137,20 @@ def request(self,
140137

141138
# Determine GET/POST
142139
# requests_method = self.session.get
143-
requests_method = 'GET'
140+
requests_method = "GET"
144141
body = None
145142
if post_json is not None:
146143
# requests_method = self.session.post
147144
# final_requests_kwargs["json"] = post_json
148145
body = post_json
149-
requests_method = 'POST'
146+
requests_method = "POST"
150147

151-
logger.log(
152-
f"url: {self.url}\nParameters: {json.dumps(body, indent=2)}",
153-
0
154-
)
148+
logger.log(f"url: {self.url}\nParameters: {json.dumps(body, indent=2)}", 0)
155149

156150
try:
157-
response, content = self.nam.request(self.url,
158-
method=requests_method,
159-
body=body,
160-
headers=self.headers,
161-
blocking=True)
151+
response, content = self.nam.request(
152+
self.url, method=requests_method, body=body, headers=self.headers, blocking=True
153+
)
162154
except networkaccessmanager.RequestsExceptionTimeout:
163155
raise exceptions.Timeout
164156

@@ -167,7 +159,6 @@ def request(self,
167159
self._check_status()
168160

169161
except exceptions.OverQueryLimit as e:
170-
171162
# Let the instances know something happened
172163
# noinspection PyUnresolvedReferences
173164
self.overQueryLimit.emit()
@@ -176,17 +167,21 @@ def request(self,
176167
return self.request(url, params, first_request_time, retry_counter + 1, post_json)
177168

178169
except exceptions.ApiError as e:
179-
logger.log(f"Feature ID {post_json['id']} caused a {e.__class__.__name__}: {str(e)}", 2)
170+
logger.log(
171+
f"Feature ID {post_json['id']} caused a {e.__class__.__name__}: {str(e)}", 2
172+
)
180173
raise
181174

182175
raise
183176

184177
# Write env variables if successful
185178
if self.ENV_VARS:
186179
for env_var in self.ENV_VARS:
187-
configmanager.write_env_var(env_var, response.headers.get(self.ENV_VARS[env_var], 'None'))
180+
configmanager.write_env_var(
181+
env_var, response.headers.get(self.ENV_VARS[env_var], "None")
182+
)
188183

189-
return json.loads(content.decode('utf-8'))
184+
return json.loads(content.decode("utf-8"))
190185

191186
def _check_status(self):
192187
"""
@@ -202,34 +197,28 @@ def _check_status(self):
202197
"""
203198

204199
status_code = self.nam.http_call_result.status_code
205-
message = self.nam.http_call_result.text if self.nam.http_call_result.text != '' else self.nam.http_call_result.reason
200+
message = (
201+
self.nam.http_call_result.text
202+
if self.nam.http_call_result.text != ""
203+
else self.nam.http_call_result.reason
204+
)
206205

207206
if not status_code:
208-
raise Exception(f"{message}. Are your provider settings correct and the provider ready?")
207+
raise Exception(
208+
f"{message}. Are your provider settings correct and the provider ready?"
209+
)
209210

210211
elif status_code == 403:
211-
raise exceptions.InvalidKey(
212-
str(status_code),
213-
message
214-
)
212+
raise exceptions.InvalidKey(str(status_code), message)
215213

216214
elif status_code == 429:
217-
raise exceptions.OverQueryLimit(
218-
str(status_code),
219-
message
220-
)
215+
raise exceptions.OverQueryLimit(str(status_code), message)
221216
# Internal error message for Bad Request
222217
elif 400 <= status_code < 500:
223-
raise exceptions.ApiError(
224-
str(status_code),
225-
message
226-
)
218+
raise exceptions.ApiError(str(status_code), message)
227219
# Other HTTP errors have different formatting
228220
elif status_code != 200:
229-
raise exceptions.GenericServerError(
230-
str(status_code),
231-
message
232-
)
221+
raise exceptions.GenericServerError(str(status_code), message)
233222

234223
def _generate_auth_url(self, path, params):
235224
"""Returns the path and query string portion of the request URL, first
@@ -245,7 +234,7 @@ def _generate_auth_url(self, path, params):
245234
:rtype: string
246235
"""
247236

248-
if type(params) is dict:
237+
if isinstance(params, dict):
249238
params = sorted(dict(**params).items())
250239

251240
# Only auto-add API key when using ORS. If own instance, API key must

0 commit comments

Comments
 (0)