From 4c8036177531f03bb724ecab72873db7a8745b3e Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Wed, 7 Aug 2024 16:44:05 +0200 Subject: [PATCH] Update to fstring where it is possible --- QuickOSM/core/actions.py | 11 +++---- QuickOSM/core/api/downloader.py | 2 +- QuickOSM/core/parser/osm_parser.py | 4 +-- QuickOSM/core/query_factory.py | 29 +++++++------------ QuickOSM/core/query_preparation.py | 16 ++++------ QuickOSM/quick_osm.py | 19 +++++------- .../advanced/open_osm_file.py | 17 ++++------- QuickOSM/ui/configuration_panel.py | 6 ++-- QuickOSM/ui/edit_preset.py | 2 +- QuickOSM/ui/quick_query_panel.py | 2 +- setup.cfg | 2 +- 11 files changed, 41 insertions(+), 69 deletions(-) diff --git a/QuickOSM/core/actions.py b/QuickOSM/core/actions.py index 03b2675f..c31e71a2 100644 --- a/QuickOSM/core/actions.py +++ b/QuickOSM/core/actions.py @@ -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, @@ -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, @@ -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, @@ -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 diff --git a/QuickOSM/core/api/downloader.py b/QuickOSM/core/api/downloader.py index 9aa2c9b2..b51afd51 100644 --- a/QuickOSM/core/api/downloader.py +++ b/QuickOSM/core/api/downloader.py @@ -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( diff --git a/QuickOSM/core/parser/osm_parser.py b/QuickOSM/core/parser/osm_parser.py index 62546738..d5d8171e 100644 --- a/QuickOSM/core/parser/osm_parser.py +++ b/QuickOSM/core/parser/osm_parser.py @@ -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, diff --git a/QuickOSM/core/query_factory.py b/QuickOSM/core/query_factory.py index ca5494fb..538a480f 100644 --- a/QuickOSM/core/query_factory.py +++ b/QuickOSM/core/query_factory.py @@ -242,8 +242,7 @@ def generate_xml(self) -> str: The query will not be valid because of Overpass templates ! """ - query = ''.format( - self._output, self._timeout) + query = f'' if self._area: nominatim = self._area @@ -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 += ''.format( - one_place, i) + query += f'' query += '' @@ -290,8 +288,7 @@ def generate_xml(self) -> str: query += f'' elif self._area and self._query_type == QueryType.AroundArea: - query += ''.format( - nominatim[i], self._distance_around) + query += f'' elif self._query_type == QueryType.BBox: query = f'{query}' @@ -304,8 +301,7 @@ def generate_xml(self) -> str: query += f'' elif self._area and self._query_type == QueryType.AroundArea: - query += ''.format( - nominatim[i], self._distance_around) + query += f'' elif self._query_type == QueryType.BBox: query = f'{query}' @@ -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 @@ -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' @@ -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")' @@ -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")' @@ -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 = '' diff --git a/QuickOSM/core/query_preparation.py b/QuickOSM/core/query_preparation.py index 9ad6d16c..65679788 100644 --- a/QuickOSM/core/query_preparation.py +++ b/QuickOSM/core/query_preparation.py @@ -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)) diff --git a/QuickOSM/quick_osm.py b/QuickOSM/quick_osm.py index 1f0e75c8..016e2b69 100644 --- a/QuickOSM/quick_osm.py +++ b/QuickOSM/quick_osm.py @@ -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): @@ -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) @@ -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) diff --git a/QuickOSM/quick_osm_processing/advanced/open_osm_file.py b/QuickOSM/quick_osm_processing/advanced/open_osm_file.py index c3215ab2..32e87a8a 100644 --- a/QuickOSM/quick_osm_processing/advanced/open_osm_file.py +++ b/QuickOSM/quick_osm_processing/advanced/open_osm_file.py @@ -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 = { diff --git a/QuickOSM/ui/configuration_panel.py b/QuickOSM/ui/configuration_panel.py index 043ae23e..168d26e6 100644 --- a/QuickOSM/ui/configuration_panel.py +++ b/QuickOSM/ui/configuration_panel.py @@ -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 diff --git a/QuickOSM/ui/edit_preset.py b/QuickOSM/ui/edit_preset.py index 656424cf..cec79c97 100644 --- a/QuickOSM/ui/edit_preset.py +++ b/QuickOSM/ui/edit_preset.py @@ -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 += '
' - help_string += "{0}".format(folder) + help_string += f"{folder}" help_string += '

' help_string += tr("The name of QML files must follow this convention") help_string += " : " diff --git a/QuickOSM/ui/quick_query_panel.py b/QuickOSM/ui/quick_query_panel.py index 2941388f..48807789 100644 --- a/QuickOSM/ui/quick_query_panel.py +++ b/QuickOSM/ui/quick_query_panel.py @@ -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 diff --git a/setup.cfg b/setup.cfg index 9f124efb..be7fa352 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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,