diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 321c341..a22e424 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,3 +30,26 @@ jobs: - name: Test with pytest run: | pytest -v + build-windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install black flake8 pytest + pip install -r requirements.txt + pip install . + - name: Check code style with Black + run: | + black -l 80 --check map_machine tests + - name: Lint with Flake8 + run: | + flake8 --max-line-length=80 --ignore=E203,W503 + - name: Test render + run: | + map-machine render -b 10.000,20.000,10.001,20.001 --cache tests/data diff --git a/map_machine/drawing.py b/map_machine/drawing.py index f4e6c09..12202e6 100644 --- a/map_machine/drawing.py +++ b/map_machine/drawing.py @@ -140,7 +140,7 @@ class SVGDrawing(Drawing): def write(self) -> None: """Write image to the SVG file.""" - with self.file_path.open("w+") as output_file: + with self.file_path.open("w+", encoding="utf-8") as output_file: self.image.write(output_file) diff --git a/map_machine/element.py b/map_machine/element.py index 1ece0d4..8dbf97f 100644 --- a/map_machine/element.py +++ b/map_machine/element.py @@ -70,6 +70,6 @@ def draw_element(options: argparse.Namespace) -> None: point.draw_main_shapes(svg) point.draw_extra_shapes(svg) point.draw_texts(svg) - with output_file_path.open("w+") as output_file: + with output_file_path.open("w+", encoding="utf-8") as output_file: svg.write(output_file) logging.info(f"Element is written to {output_file_path}.") diff --git a/map_machine/grid.py b/map_machine/grid.py index 372a74f..3ae0f85 100644 --- a/map_machine/grid.py +++ b/map_machine/grid.py @@ -196,7 +196,7 @@ class IconCollection: point += np.array((0, step)) height += step - with file_name.open("w") as output_file: + with file_name.open("w", encoding="utf-8") as output_file: svg.write(output_file) def __len__(self) -> int: diff --git a/map_machine/icon.py b/map_machine/icon.py index 7d92ebe..168e1a5 100644 --- a/map_machine/icon.py +++ b/map_machine/icon.py @@ -404,7 +404,7 @@ class Icon: shape_specification.color = color shape_specification.draw(svg, np.array((8, 8))) - with file_name.open("w") as output_file: + with file_name.open("w", encoding="utf-8") as output_file: svg.write(output_file) def is_default(self) -> bool: diff --git a/map_machine/mapcss.py b/map_machine/mapcss.py index 68530a2..eeca2bb 100644 --- a/map_machine/mapcss.py +++ b/map_machine/mapcss.py @@ -199,7 +199,9 @@ def ui(options: argparse.Namespace) -> None: options.ways, options.lifecycle, ) - with workspace.get_mapcss_file_path().open("w+") as output_file: + with workspace.get_mapcss_file_path().open( + "w+", encoding="utf-8" + ) as output_file: mapcss_writer.write(output_file) logging.info(f"MapCSS 0.2 scheme is written to {directory}.") diff --git a/map_machine/mapper.py b/map_machine/mapper.py index 6871a1e..a333862 100644 --- a/map_machine/mapper.py +++ b/map_machine/mapper.py @@ -280,5 +280,5 @@ def ui(arguments: argparse.Namespace) -> None: painter.draw(constructor) logging.info(f"Writing output SVG to {arguments.output_file_name}...") - with open(arguments.output_file_name, "w") as output_file: + with open(arguments.output_file_name, "w", encoding="utf-8") as output_file: svg.write(output_file) diff --git a/map_machine/moire_manager.py b/map_machine/moire_manager.py index 8d84b8b..50de341 100644 --- a/map_machine/moire_manager.py +++ b/map_machine/moire_manager.py @@ -307,8 +307,8 @@ class MapMachineMarkdown(MapMachineMoire, DefaultMarkdown): def convert(input_path: Path, output_path: Path) -> None: """Convert Moire file to Markdown.""" - with input_path.open() as input_file: - with output_path.open("w+") as output_file: + with input_path.open(encoding="utf-8") as input_file: + with output_path.open("w+", encoding="utf-8") as output_file: output_file.write(MapMachineMarkdown().convert(input_file.read())) diff --git a/map_machine/osm_reader.py b/map_machine/osm_reader.py index db6f843..ee95b26 100644 --- a/map_machine/osm_reader.py +++ b/map_machine/osm_reader.py @@ -361,7 +361,7 @@ class OSMData: See https://wiki.openstreetmap.org/wiki/Overpass_API """ - with file_name.open() as input_file: + with file_name.open(encoding="utf-8") as input_file: structure = json.load(input_file) node_map: Dict[int, OSMNode] = {} diff --git a/map_machine/scheme.py b/map_machine/scheme.py index c9fc57b..6110e03 100644 --- a/map_machine/scheme.py +++ b/map_machine/scheme.py @@ -306,7 +306,7 @@ class Scheme: :param file_name: name of the scheme file with tags, colors, and tag key specification """ - with file_name.open() as input_file: + with file_name.open(encoding="utf-8") as input_file: content: Dict[str, Any] = yaml.load( input_file.read(), Loader=yaml.FullLoader ) diff --git a/map_machine/server.py b/map_machine/server.py index 914797e..c5d117e 100644 --- a/map_machine/server.py +++ b/map_machine/server.py @@ -51,7 +51,7 @@ class _Handler(SimpleHTTPRequestHandler): if not png_path.exists(): if not svg_path.exists(): tile.draw(tile_path, self.cache, self.options) - with svg_path.open() as input_file: + with svg_path.open(encoding="utf-8") as input_file: cairosvg.svg2png( file_obj=input_file, write_to=str(png_path) ) diff --git a/map_machine/taginfo.py b/map_machine/taginfo.py index a819154..277705e 100644 --- a/map_machine/taginfo.py +++ b/map_machine/taginfo.py @@ -74,7 +74,7 @@ class TaginfoProjectFile: def write(self) -> None: """Write Taginfo JSON file.""" - with self.path.open("w+") as output_file: + with self.path.open("w+", encoding="utf-8") as output_file: json.dump(self.structure, output_file, indent=4, sort_keys=True) diff --git a/map_machine/tile.py b/map_machine/tile.py index 61de2bd..5c042db 100644 --- a/map_machine/tile.py +++ b/map_machine/tile.py @@ -182,12 +182,12 @@ class Tile: ) painter.draw(constructor) - with output_file_name.open("w") as output_file: + with output_file_name.open("w", encoding="utf-8") as output_file: svg.write(output_file) logging.info(f"Tile is drawn to {output_file_name}.") output_path: Path = output_file_name.with_suffix(".png") - with output_file_name.open() as input_file: + with output_file_name.open(encoding="utf-8") as input_file: cairosvg.svg2png(file_obj=input_file, write_to=str(output_path)) logging.info(f"SVG file is rasterized to {output_path}.") @@ -287,7 +287,7 @@ class Tiles: output_path: Path = file_path.with_suffix(".png") if not output_path.exists(): - with file_path.open() as input_file: + with file_path.open(encoding="utf-8") as input_file: cairosvg.svg2png( file_obj=input_file, write_to=str(output_path) ) @@ -398,14 +398,14 @@ class Tiles: map_.draw(constructor) logging.info(f"Writing output SVG {output_path}...") - with output_path.open("w+") as output_file: + with output_path.open("w+", encoding="utf-8") as output_file: svg.write(output_file) else: logging.debug(f"File {output_path} already exists.") png_path: Path = self.get_file_path(cache_path).with_suffix(".png") if not png_path.exists(): - with output_path.open() as input_file: + with output_path.open(encoding="utf-8") as input_file: cairosvg.svg2png(file_obj=input_file, write_to=str(png_path)) logging.info(f"SVG file is rasterized to {png_path}.") else: diff --git a/map_machine/ui.py b/map_machine/ui.py index 7d0885d..c885989 100644 --- a/map_machine/ui.py +++ b/map_machine/ui.py @@ -338,6 +338,9 @@ def progress_bar( subsequently) :param text: short description """ + if number == 0: + sys.stdout.write(text + "...\n") + return if number == -1: sys.stdout.write(f"100 % {length * '█'}▏{text}\n") elif number % step == 0: