Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to fstring where it is possible #505

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
11 changes: 4 additions & 7 deletions QuickOSM/core/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
__email__ = 'info@3liz.org'


ACTIONS_PATH = 'from QuickOSM.core.actions import Actions;'
ACTIONS_PATH = 'from QuickOSM.core.actions import Actions\n'
ACTIONS_VISIBILITY = [
Visibility.Canvas.value,
Visibility.Feature.value,
Expand Down Expand Up @@ -98,7 +98,7 @@ def add_actions(layer: QgsVectorLayer, keys: list):
QgsAction.GenericPython,
link,
(ACTIONS_PATH
+ 'Actions.run("{link}","[% "{link}" %]")'.format(link=link)),
+ f'Actions.run("{link}","[% "{link}" %]")'),
image,
False,
link,
Expand Down Expand Up @@ -132,8 +132,7 @@ def add_relaunch_action(layer: QgsVectorLayer, layer_name: str = ""):
reload = QgsAction(
QgsAction.GenericPython,
title,
ACTIONS_PATH + 'Actions.run_reload(layer_name="{layer_name}")'.format(
layer_name=layer_name),
ACTIONS_PATH + f'Actions.run_reload(layer_name="{layer_name}")',
'',
False,
title,
Expand Down Expand Up @@ -233,9 +232,7 @@ def run_sketch_line(network: str, ref: str):
level=Qgis.Warning,
duration=7)
else:
url = (
'http://www.overpass-api.de/api/sketch-line?'
'network={network}&ref={ref}').format(network=network, ref=ref)
url = f'http://www.overpass-api.de/api/sketch-line?network={network}&ref={ref}'
open_webpage(url)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion QuickOSM/core/api/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def download(self, get=False):
# We use POST instead of GET for Overpass only
# We move the "data" GET parameter into the POST request
url_query = QUrlQuery(self._url)
data = "data={}".format(url_query.queryItemValue('data'))
data = f"data={url_query.queryItemValue('data')}"
url_query.removeQueryItem('data')
self._url.setQuery(url_query)
downloader = QgsFileDownloader(
Expand Down
4 changes: 1 addition & 3 deletions QuickOSM/core/parser/osm_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ def processing_parse(self):
self.__output_dir,
self.__prefix_file + "." + self.__output_format.value.extension)
final_name = self.__prefix_file + '_' + layer
layers[layer]['layer_name'] = 'ogr:dbname=\'{path}\' table=\"{layer}\" (geom)'.format(
path=output_file, layer=final_name
)
layers[layer]['layer_name'] = f'ogr:dbname=\'{output_file}\' table=\"{final_name}\" (geom)'
elif self.__output_format in [Format.GeoJSON, Format.Shapefile]:
layers[layer]['layer_name'] = join(
self.__output_dir,
Expand Down
29 changes: 11 additions & 18 deletions QuickOSM/core/query_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ def generate_xml(self) -> str:

The query will not be valid because of Overpass templates !
"""
query = '<osm-script output="{}" timeout="{}">'.format(
self._output, self._timeout)
query = f'<osm-script output="{self._output}" timeout="{self._timeout}">'

if self._area:
nominatim = self._area
Expand All @@ -253,8 +252,7 @@ def generate_xml(self) -> str:
if nominatim and self._query_type != QueryType.AroundArea:

for i, one_place in enumerate(nominatim):
query += '<id-query area="{}" into="area_{}"/>'.format(
one_place, i)
query += f'<id-query area="{one_place}" into="area_{i}"/>'

query += '<union>'

Expand Down Expand Up @@ -290,8 +288,7 @@ def generate_xml(self) -> str:
query += f'<area-query from="area_{i}" />'

elif self._area and self._query_type == QueryType.AroundArea:
query += '<around area_coords="{}" radius="{}" />'.format(
nominatim[i], self._distance_around)
query += f'<around area_coords="{nominatim[i]}" radius="{self._distance_around}" />'

elif self._query_type == QueryType.BBox:
query = f'{query}<bbox-query bbox="custom" />'
Expand All @@ -304,8 +301,7 @@ def generate_xml(self) -> str:
query += f'<area-query from="area_{i}" />'

elif self._area and self._query_type == QueryType.AroundArea:
query += '<around area_coords="{}" radius="{}" />'.format(
nominatim[i], self._distance_around)
query += f'<around area_coords="{nominatim[i]}" radius="{self._distance_around}" />'

elif self._query_type == QueryType.BBox:
query = f'{query}<bbox-query bbox="custom" />'
Expand All @@ -327,8 +323,7 @@ def generate_oql(self) -> str:

The query will not be valid because of Overpass templates !
"""
query = '[out:{}] [timeout:{}];\n'.format(
self._output, self._timeout)
query = f'[out:{self._output}] [timeout:{self._timeout}];\n'

if self._area:
nominatim = self._area
Expand All @@ -338,8 +333,7 @@ def generate_oql(self) -> str:
if nominatim and self._query_type == QueryType.InArea:

for i, one_place in enumerate(nominatim):
query += ' area="{}" -> .area_{};\n'.format(
one_place, i)
query += f' area="{one_place}" -> .area_{i};\n'

query += '(\n'

Expand Down Expand Up @@ -375,8 +369,7 @@ def generate_oql(self) -> str:
query += f'(area.area_{i})'

elif self._area and self._query_type == QueryType.AroundArea:
query += '(around:{}, area_coords="{}")'.format(
self._distance_around, nominatim[i])
query += f'(around:{self._distance_around}, area_coords="{nominatim[i]}")'

elif self._query_type == QueryType.BBox:
query += '( bbox="custom")'
Expand All @@ -390,8 +383,7 @@ def generate_oql(self) -> str:
query += f'(area.area_{i})'

elif self._area and self._query_type == QueryType.AroundArea:
query += '(around:{}, area_coords="{}")'.format(
self._distance_around, nominatim[i])
query += f'(around:{self._distance_around}, area_coords="{nominatim[i]}")'

elif self._query_type == QueryType.BBox:
query += '( bbox="custom")'
Expand Down Expand Up @@ -449,13 +441,14 @@ def friendly_message(self) -> str:
place = self._area
if self._area is not None:
# human format a list
and_str = tr('and')
if len(self._area) == 1:
place = self._area[0] # simply unwrap the list
elif len(self._area) == 2:
place = ' {} '.format(tr('and')).join(self._area)
place = f' {and_str} '.join(self._area)
else:
place = ', '.join(self._area[:-2]) + ', '
place = place + ' {} '.format(tr('and')).join(self._area[-2:])
place = place + f' {and_str} '.join(self._area[-2:])

extent_lbl = ''
dist_lbl = ''
Expand Down
16 changes: 6 additions & 10 deletions QuickOSM/core/query_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,14 @@ def replace_bbox(self):
'been restricted.'))

if self.is_oql_query():
new_string = '{},{},{},{}'.format(
self._format_decimals_wgs84(y_min),
self._format_decimals_wgs84(x_min),
self._format_decimals_wgs84(y_max),
self._format_decimals_wgs84(x_max),
new_string = (
f'{self._format_decimals_wgs84(y_min)},{self._format_decimals_wgs84(x_min)},'
f'{self._format_decimals_wgs84(y_max)},{self._format_decimals_wgs84(x_max)}'
)
else:
new_string = 'e="{}" n="{}" s="{}" w="{}"'.format(
self._format_decimals_wgs84(x_max),
self._format_decimals_wgs84(y_max),
self._format_decimals_wgs84(y_min),
self._format_decimals_wgs84(x_min),
new_string = (
f'e="{self._format_decimals_wgs84(x_max)}" n="{self._format_decimals_wgs84(y_max)}" '
f's="{self._format_decimals_wgs84(y_min)}" w="{self._format_decimals_wgs84(x_min)}"'
)
self._query_prepared = (
re.sub(template, new_string, self._query_prepared))
Expand Down
19 changes: 8 additions & 11 deletions QuickOSM/quick_osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ def extract_zip_file():
# The folder needs to be unzipped again
shutil.rmtree(preset_translation_path)
LOGGER.info(
'The version does not match in the i18n folder, the folder needs to be unzipped : '
'old version {} versus {}'.format(
old_version, new_version
)
f'The version does not match in the i18n folder, the folder needs to be unzipped : '
f'old version {old_version} versus {new_version}'
)

if not os.path.isdir(preset_translation_path):
Expand All @@ -138,8 +136,7 @@ def extract_zip_file():
os.rename(file_path, new_file_path)
except FileExistsError:
LOGGER.critical(
'Error about existing file when extracting the ZIP file about {}'.format(
file))
f'Error about existing file when extracting the ZIP file about {file}')
else:
os.mkdir(preset_translation_path)

Expand Down Expand Up @@ -214,11 +211,11 @@ def josm_remote(self):
crs_map, crs_4326, QgsProject.instance())
extent = transform.transform(extent)

url = 'http://localhost:8111/load_and_zoom?'
query_string = 'left={}&right={}&top={}&bottom={}'.format(
extent.xMinimum(), extent.xMaximum(), extent.yMaximum(),
extent.yMinimum())
url += query_string
url = (
f'http://localhost:8111/load_and_zoom?'
f'left={extent.xMinimum()}&right={extent.xMaximum()}&'
f'top={extent.xMaximum()}&bottom={extent.yMinimum()}'
)
try:
request = urllib.request.Request(url)
result_request = urllib.request.urlopen(request)
Expand Down
17 changes: 5 additions & 12 deletions QuickOSM/quick_osm_processing/advanced/open_osm_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,19 @@ def processAlgorithm(self, parameters, context, feedback) -> Dict[str, any]:

gdal.SetConfigOption('OSM_USE_CUSTOM_INDEXING', 'NO')

points = QgsVectorLayer(
f'{file}|layername=points', 'points', 'ogr')
points = QgsVectorLayer(f'{file}|layername=points', 'points', 'ogr')
context.temporaryLayerStore().addMapLayer(points)

lines = QgsVectorLayer(
f'{file}|layername=lines', 'lines', 'ogr')
lines = QgsVectorLayer(f'{file}|layername=lines', 'lines', 'ogr')
context.temporaryLayerStore().addMapLayer(lines)

multilinestrings = QgsVectorLayer(
'{}|layername=multilinestrings'.format(
file), 'multilinestrings', 'ogr')
multilinestrings = QgsVectorLayer(f'{file}|layername=multilinestrings', 'multilinestrings', 'ogr')
context.temporaryLayerStore().addMapLayer(multilinestrings)

multipolygons = QgsVectorLayer(
f'{file}|layername=multipolygons', 'multipolygons', 'ogr')
multipolygons = QgsVectorLayer(f'{file}|layername=multipolygons', 'multipolygons', 'ogr')
context.temporaryLayerStore().addMapLayer(multipolygons)

other_relations = QgsVectorLayer(
'{}|layername=other_relations'.format(
file), 'other_relations', 'ogr')
other_relations = QgsVectorLayer(f'{file}|layername=other_relations', 'other_relations', 'ogr')
context.temporaryLayerStore().addMapLayer(other_relations)

outputs = {
Expand Down
6 changes: 2 additions & 4 deletions QuickOSM/ui/configuration_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ def setup_panel(self):
for server in config_json.get('overpass_servers', []):
if server not in OVERPASS_SERVERS:
LOGGER.info(
'Custom overpass server list added: {}'.format(
server))
f'Custom overpass server list added: {server}')
self.dialog.combo_default_overpass.addItem(server)
for server in config_json.get('nominatim_servers', []):
if server not in NOMINATIM_SERVERS:
LOGGER.info(
'Custom nominatim server list added: {}'.format(
server))
f'Custom nominatim server list added: {server}')
self.dialog.combo_default_nominatim.addItem(server)

# Set settings about the overpass API
Expand Down
2 changes: 1 addition & 1 deletion QuickOSM/ui/edit_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def update_qml_format(self):
"You can associate predefined styles with layers. You need to add QML file(s) in this folder :"
)
help_string += '<br><b>'
help_string += "<a href=\"{0}\">{0}</a>".format(folder)
help_string += f"<a href=\"{folder}\">{folder}</a>"
help_string += '</b><br><br>'
help_string += tr("The name of QML files must follow this convention")
help_string += " : "
Expand Down
2 changes: 1 addition & 1 deletion QuickOSM/ui/quick_query_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def gather_values(self) -> dict:

distance_string = None
if properties['distance']:
distance_string = '{}'.format(properties['distance'])
distance_string = str(properties['distance'])
if isinstance(properties['key'], list):
expected_name = []
nb_max = len(properties['key']) if len(properties['key']) <= 2 else 2
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ skip =
QuickOSM/qgis_plugin_tools,

[flake8]
max-line-length = 110
max-line-length = 115
ignore =
# E123 closing bracket does not match indentation of opening bracket's line
E123,
Expand Down