From 22037ab5f0dd6c6dffc8db84ef61bd50130d7463 Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Fri, 24 Sep 2021 19:42:29 +0300 Subject: [PATCH 1/5] Issue #89: try GitHub actions for Windows. --- .github/workflows/test.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 321c341..5f1b77b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,3 +30,26 @@ jobs: - name: Test with pytest run: | pytest -v + build: + 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 with pytest + run: | + pytest -v From e8b1f17368b56e51f265a571e8e4a8514bbc03a3 Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Fri, 24 Sep 2021 19:44:43 +0300 Subject: [PATCH 2/5] Issue #89: fix job name. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f1b77b..7be4b9f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: - name: Test with pytest run: | pytest -v - build: + build-windows: runs-on: windows-latest steps: - uses: actions/checkout@v2 From 394ca6a9d6258af9fd9e4a6f98f3b0660909e0a4 Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Sat, 25 Sep 2021 07:35:50 +0300 Subject: [PATCH 3/5] Issue #89: remove pytest. --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7be4b9f..a22e424 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,6 +50,6 @@ jobs: - name: Lint with Flake8 run: | flake8 --max-line-length=80 --ignore=E203,W503 - - name: Test with pytest + - name: Test render run: | - pytest -v + map-machine render -b 10.000,20.000,10.001,20.001 --cache tests/data From 067b8151006e73e6846e96b2613044e8ed10d977 Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Sat, 25 Sep 2021 07:49:30 +0300 Subject: [PATCH 4/5] Issue #89: fix SVG encoding; remove progress bar. --- map_machine/mapper.py | 2 +- map_machine/ui.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/map_machine/mapper.py b/map_machine/mapper.py index d8046cf..6f29225 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/ui.py b/map_machine/ui.py index 155d32b..3f1510c 100644 --- a/map_machine/ui.py +++ b/map_machine/ui.py @@ -301,6 +301,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: From c0b4d35573c3885a181a45326a0b5f83bda6d2aa Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Sat, 25 Sep 2021 09:12:13 +0300 Subject: [PATCH 5/5] Issue #89: fix encoding. --- map_machine/drawing.py | 2 +- map_machine/element.py | 2 +- map_machine/grid.py | 2 +- map_machine/icon.py | 2 +- map_machine/mapcss.py | 4 +++- map_machine/moire_manager.py | 4 ++-- map_machine/osm_reader.py | 2 +- map_machine/scheme.py | 2 +- map_machine/server.py | 2 +- map_machine/taginfo.py | 2 +- map_machine/tile.py | 10 +++++----- 11 files changed, 18 insertions(+), 16 deletions(-) diff --git a/map_machine/drawing.py b/map_machine/drawing.py index 27976d1..cfec7dc 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 d68d944..0f399bd 100644 --- a/map_machine/element.py +++ b/map_machine/element.py @@ -69,6 +69,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 57431f6..8b9e1c1 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 168520d..bd9a9b6 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 371748d..71317b3 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/moire_manager.py b/map_machine/moire_manager.py index 23e9853..4de1937 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 80c8f94..6315cbe 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 1632841..76a1178 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 ad0d3f3..ee747a0 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 94c0cd2..9ad2592 100644 --- a/map_machine/taginfo.py +++ b/map_machine/taginfo.py @@ -73,7 +73,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 4ac46a8..77593ad 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: