Fix Pylint warnings.

This commit is contained in:
Sergey Vartanov 2021-10-25 02:15:11 +03:00
parent 960a18633f
commit e9933e9f2b
5 changed files with 26 additions and 30 deletions

View file

@ -228,7 +228,7 @@ class Constructor:
if not self.check_level(line.tags): if not self.check_level(line.tags):
return return
center_point, center_coordinates = line_center(outers[0], self.flinger) center_point, _ = line_center(outers[0], self.flinger)
if self.configuration.is_wireframe(): if self.configuration.is_wireframe():
color: Color color: Color
if self.configuration.drawing_mode == DrawingMode.AUTHOR: if self.configuration.drawing_mode == DrawingMode.AUTHOR:

View file

@ -29,7 +29,7 @@ def main() -> None:
elif arguments.command == "render": elif arguments.command == "render":
from map_machine import mapper from map_machine import mapper
mapper.ui(arguments) mapper.render_map(arguments)
elif arguments.command == "tile": elif arguments.command == "tile":
from map_machine.slippy import tile from map_machine.slippy import tile
@ -44,7 +44,7 @@ def main() -> None:
elif arguments.command == "mapcss": elif arguments.command == "mapcss":
from map_machine import mapcss from map_machine import mapcss
mapcss.ui(arguments) mapcss.generate_mapcss(arguments)
elif arguments.command == "element": elif arguments.command == "element":
from map_machine.element import draw_element from map_machine.element import draw_element

View file

@ -134,8 +134,8 @@ class MapCSSWriter:
return "" return ""
selector: str = target + matcher.get_mapcss_selector(prefix) + " {\n" selector: str = target + matcher.get_mapcss_selector(prefix) + " {\n"
for element in elements: for key, value in elements.items():
selector += f" {element}: {elements[element]};\n" selector += f" {key}: {value};\n"
selector += "}\n" selector += "}\n"
return selector return selector
@ -176,7 +176,7 @@ class MapCSSWriter:
) )
def ui(options: argparse.Namespace) -> None: def generate_mapcss(options: argparse.Namespace) -> None:
"""Write MapCSS 0.2 scheme.""" """Write MapCSS 0.2 scheme."""
directory: Path = workspace.get_mapcss_path() directory: Path = workspace.get_mapcss_path()
icons_with_outline_path: Path = workspace.get_mapcss_icons_path() icons_with_outline_path: Path = workspace.get_mapcss_icons_path()

View file

@ -3,6 +3,7 @@ Simple OpenStreetMap renderer.
""" """
import argparse import argparse
import logging import logging
import sys
from pathlib import Path from pathlib import Path
from typing import Iterator, Optional from typing import Iterator, Optional
@ -133,7 +134,6 @@ class Map:
previous_height: float = 0 previous_height: float = 0
for height in sorted(constructor.heights): for height in sorted(constructor.heights):
fill: Color()
for building in constructor.buildings: for building in constructor.buildings:
if building.height < height or building.min_height > height: if building.height < height or building.min_height > height:
continue continue
@ -168,15 +168,14 @@ class Map:
nodes[node_1].add(part_1) nodes[node_1].add(part_1)
nodes[node_2].add(part_2) nodes[node_2].add(part_2)
for node in nodes: for node, parts in nodes.items():
parts: set[RoadPart] = nodes[node]
if len(parts) < 4: if len(parts) < 4:
continue continue
intersection: Intersection = Intersection(list(parts)) intersection: Intersection = Intersection(list(parts))
intersection.draw(self.svg, True) intersection.draw(self.svg, True)
def ui(arguments: argparse.Namespace) -> None: def render_map(arguments: argparse.Namespace) -> None:
""" """
Map Machine entry point. Map Machine entry point.
@ -189,7 +188,6 @@ def ui(arguments: argparse.Namespace) -> None:
cache_path.mkdir(parents=True, exist_ok=True) cache_path.mkdir(parents=True, exist_ok=True)
boundary_box: Optional[BoundaryBox] = None boundary_box: Optional[BoundaryBox] = None
input_file_names: list[Path] = []
if arguments.input_file_names: if arguments.input_file_names:
input_file_names = list(map(Path, arguments.input_file_names)) input_file_names = list(map(Path, arguments.input_file_names))
@ -213,7 +211,7 @@ def ui(arguments: argparse.Namespace) -> None:
"Specify either --input, or --boundary-box, or --coordinates " "Specify either --input, or --boundary-box, or --coordinates "
"and --size." "and --size."
) )
exit(1) sys.exit(1)
try: try:
cache_file_path: Path = ( cache_file_path: Path = (
@ -221,13 +219,11 @@ def ui(arguments: argparse.Namespace) -> None:
) )
get_osm(boundary_box, cache_file_path) get_osm(boundary_box, cache_file_path)
input_file_names = [cache_file_path] input_file_names = [cache_file_path]
except NetworkError as e: except NetworkError as error:
logging.fatal(e.message) logging.fatal(error.message)
exit(1) sys.exit(1)
scheme: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH) scheme: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH)
min_: np.ndarray
max_: np.ndarray
osm_data: OSMData osm_data: OSMData
osm_data: OSMData = OSMData() osm_data: OSMData = OSMData()

View file

@ -55,9 +55,9 @@ class Tile:
:param zoom_level: zoom level in OpenStreetMap terminology :param zoom_level: zoom level in OpenStreetMap terminology
""" """
lat_rad: np.ndarray = np.radians(coordinates[0]) lat_rad: np.ndarray = np.radians(coordinates[0])
n: float = 2.0 ** zoom_level scale: float = 2.0 ** zoom_level
x: int = int((coordinates[1] + 180.0) / 360.0 * n) x: int = int((coordinates[1] + 180.0) / 360.0 * scale)
y: int = int((1.0 - np.arcsinh(np.tan(lat_rad)) / np.pi) / 2.0 * n) y: int = int((1.0 - np.arcsinh(np.tan(lat_rad)) / np.pi) / 2.0 * scale)
return cls(x, y, zoom_level) return cls(x, y, zoom_level)
def get_coordinates(self) -> np.ndarray: def get_coordinates(self) -> np.ndarray:
@ -66,9 +66,9 @@ class Tile:
Code from https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames Code from https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
""" """
n: float = 2.0 ** self.zoom_level scale: float = 2.0 ** self.zoom_level
lon_deg: float = self.x / n * 360.0 - 180.0 lon_deg: float = self.x / scale * 360.0 - 180.0
lat_rad: float = np.arctan(np.sinh(np.pi * (1 - 2 * self.y / n))) lat_rad: float = np.arctan(np.sinh(np.pi * (1 - 2 * self.y / scale)))
lat_deg: np.ndarray = np.degrees(lat_rad) lat_deg: np.ndarray = np.degrees(lat_rad)
return np.array((lat_deg, lon_deg)) return np.array((lat_deg, lon_deg))
@ -141,8 +141,8 @@ class Tile:
""" """
try: try:
osm_data: OSMData = self.load_osm_data(cache_path) osm_data: OSMData = self.load_osm_data(cache_path)
except NetworkError as e: except NetworkError as error:
raise NetworkError(f"Map is not loaded. {e.message}") raise NetworkError(f"Map is not loaded. {error.message}")
self.draw_with_osm_data(osm_data, directory_name, configuration) self.draw_with_osm_data(osm_data, directory_name, configuration)
@ -198,12 +198,12 @@ class Tile:
assert zoom_level >= self.zoom_level assert zoom_level >= self.zoom_level
tiles: list["Tile"] = [] tiles: list["Tile"] = []
n: int = 2 ** (zoom_level - self.zoom_level) scale: int = 2 ** (zoom_level - self.zoom_level)
for i in range(n): for i in range(scale):
for j in range(n): for j in range(scale):
tile: Tile = Tile( tile: Tile = Tile(
n * self.x + i, scale * self.x + i,
n * self.y + j, scale * self.y + j,
zoom_level, zoom_level,
) )
tiles.append(tile) tiles.append(tile)