From 1f4fb66c85720476b7a30138b0da51a10d6a48e8 Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Thu, 24 Feb 2022 00:50:43 +0300 Subject: [PATCH] Close #98: copy license file to icon collection. --- map_machine/mapcss.py | 1 + map_machine/pictogram/icon_collection.py | 17 ++++++++++++++--- map_machine/workspace.py | 7 ++++--- tests/test_command_line.py | 12 ++++++------ tests/test_icons.py | 11 +++++++++-- tests/test_mapcss.py | 3 ++- 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/map_machine/mapcss.py b/map_machine/mapcss.py index ef19881..35d3cc3 100644 --- a/map_machine/mapcss.py +++ b/map_machine/mapcss.py @@ -190,6 +190,7 @@ def generate_mapcss(options: argparse.Namespace) -> None: collection: IconCollection = IconCollection.from_scheme(scheme, extractor) collection.draw_icons( icons_with_outline_path, + workspace.ICONS_LICENSE_PATH, color=Color("black"), outline=True, outline_opacity=0.5, diff --git a/map_machine/pictogram/icon_collection.py b/map_machine/pictogram/icon_collection.py index 1f30f6a..1b4b8db 100644 --- a/map_machine/pictogram/icon_collection.py +++ b/map_machine/pictogram/icon_collection.py @@ -2,6 +2,7 @@ Icon grid drawing. """ import logging +import shutil from dataclasses import dataclass from pathlib import Path from typing import Optional @@ -40,7 +41,10 @@ class IconCollection: add_all: bool = False, ) -> "IconCollection": """ - Collect all possible icon combinations in grid. + Collect all possible icon combinations. + + This collection won't contain icons for tags matched with regular + expressions. E.g. traffic_sign=maxspeed; maxspeed=42. :param scheme: tag specification :param extractor: shape extractor for icon creation @@ -124,6 +128,7 @@ class IconCollection: def draw_icons( self, output_directory: Path, + license_path: Path, by_name: bool = False, color: Optional[Color] = None, outline: bool = False, @@ -132,6 +137,7 @@ class IconCollection: """ :param output_directory: path to the directory to store individual SVG files for icons + :param license_path: path to the file with license :param by_name: use names instead of identifiers :param color: fill color :param outline: if true, draw outline beneath the icon @@ -157,6 +163,8 @@ class IconCollection: outline_opacity=outline_opacity, ) + shutil.copy(license_path, output_directory / "LICENSE") + def draw_grid( self, file_name: Path, @@ -218,9 +226,12 @@ def draw_icons() -> None: # Draw individual icons. icons_by_id_path: Path = workspace.get_icons_by_id_path() + collection.draw_icons(icons_by_id_path, workspace.ICONS_LICENSE_PATH) + icons_by_name_path: Path = workspace.get_icons_by_name_path() - collection.draw_icons(icons_by_id_path) - collection.draw_icons(icons_by_name_path, by_name=True) + collection.draw_icons( + icons_by_name_path, workspace.ICONS_LICENSE_PATH, by_name=True + ) logging.info( f"Icons are written to {icons_by_name_path} and {icons_by_id_path}." diff --git a/map_machine/workspace.py b/map_machine/workspace.py index 99dd7b3..d76d337 100644 --- a/map_machine/workspace.py +++ b/map_machine/workspace.py @@ -21,10 +21,11 @@ class Workspace: # Project directories and files, that are the part of the repository. - SCHEME_PATH: Path = HERE / Path("scheme") + SCHEME_PATH: Path = HERE / "scheme" DEFAULT_SCHEME_PATH: Path = SCHEME_PATH / "default.yml" - ICONS_PATH: Path = HERE / Path("icons/icons.svg") - ICONS_CONFIG_PATH: Path = HERE / Path("icons/config.json") + ICONS_PATH: Path = HERE / "icons" / "icons.svg" + ICONS_CONFIG_PATH: Path = HERE / "icons" / "config.json" + ICONS_LICENSE_PATH: Path = HERE / "icons" / "LICENSE" DOCUMENTATION_PATH: Path = Path("doc") GRID_PATH: Path = DOCUMENTATION_PATH / "grid.svg" diff --git a/tests/test_command_line.py b/tests/test_command_line.py index 790c70b..fb2bebc 100644 --- a/tests/test_command_line.py +++ b/tests/test_command_line.py @@ -104,13 +104,13 @@ def test_mapcss() -> None: COMMAND_LINES["mapcss"], b"INFO MapCSS 0.2 scheme is written to out/map_machine_mapcss.\n", ) + out_path: Path = Path("out") / "map_machine_mapcss" - assert (Path("out") / "map_machine_mapcss").is_dir() - assert (Path("out") / "map_machine_mapcss" / "icons").is_dir() - assert ( - Path("out") / "map_machine_mapcss" / "icons" / "apple.svg" - ).is_file() - assert (Path("out") / "map_machine_mapcss" / "map_machine.mapcss").is_file() + assert out_path.is_dir() + assert out_path.is_dir() + assert (out_path / "icons" / "apple.svg").is_file() + assert (out_path / "map_machine.mapcss").is_file() + assert (out_path / "icons" / "LICENSE").is_file() def test_element() -> None: diff --git a/tests/test_icons.py b/tests/test_icons.py index c662054..b6d97f1 100644 --- a/tests/test_icons.py +++ b/tests/test_icons.py @@ -1,6 +1,7 @@ """ Test icon generation for nodes. """ +from pathlib import Path from typing import Optional from colour import Color @@ -23,12 +24,18 @@ def test_grid() -> None: def test_icons_by_id() -> None: """Test individual icons drawing.""" - COLLECTION.draw_icons(workspace.get_icons_by_id_path()) + path: Path = workspace.get_icons_by_id_path() + COLLECTION.draw_icons(path, workspace.ICONS_LICENSE_PATH) + assert (path / "tree.svg").is_file() + assert (path / "LICENSE").is_file() def test_icons_by_name() -> None: """Test drawing individual icons that have names.""" - COLLECTION.draw_icons(workspace.get_icons_by_name_path(), by_name=True) + path: Path = workspace.get_icons_by_name_path() + COLLECTION.draw_icons(path, workspace.ICONS_LICENSE_PATH, by_name=True) + assert (path / "Röntgen tree.svg").is_file() + assert (path / "LICENSE").is_file() def get_icon(tags: dict[str, str]) -> IconSet: diff --git a/tests/test_mapcss.py b/tests/test_mapcss.py index d93537c..b64abc6 100644 --- a/tests/test_mapcss.py +++ b/tests/test_mapcss.py @@ -18,7 +18,8 @@ def test_mapcss() -> None: selector = writer.add_selector("node", matcher) assert ( selector - == """node[natural="tree"] { + == """\ +node[natural="tree"] { icon-image: "icons/tree.svg"; } """