Close #98: copy license file to icon collection.

This commit is contained in:
Sergey Vartanov 2022-02-24 00:50:43 +03:00
parent 968addff4b
commit 1f4fb66c85
6 changed files with 36 additions and 15 deletions

View file

@ -190,6 +190,7 @@ def generate_mapcss(options: argparse.Namespace) -> None:
collection: IconCollection = IconCollection.from_scheme(scheme, extractor) collection: IconCollection = IconCollection.from_scheme(scheme, extractor)
collection.draw_icons( collection.draw_icons(
icons_with_outline_path, icons_with_outline_path,
workspace.ICONS_LICENSE_PATH,
color=Color("black"), color=Color("black"),
outline=True, outline=True,
outline_opacity=0.5, outline_opacity=0.5,

View file

@ -2,6 +2,7 @@
Icon grid drawing. Icon grid drawing.
""" """
import logging import logging
import shutil
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional
@ -40,7 +41,10 @@ class IconCollection:
add_all: bool = False, add_all: bool = False,
) -> "IconCollection": ) -> "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 scheme: tag specification
:param extractor: shape extractor for icon creation :param extractor: shape extractor for icon creation
@ -124,6 +128,7 @@ class IconCollection:
def draw_icons( def draw_icons(
self, self,
output_directory: Path, output_directory: Path,
license_path: Path,
by_name: bool = False, by_name: bool = False,
color: Optional[Color] = None, color: Optional[Color] = None,
outline: bool = False, outline: bool = False,
@ -132,6 +137,7 @@ class IconCollection:
""" """
:param output_directory: path to the directory to store individual SVG :param output_directory: path to the directory to store individual SVG
files for icons files for icons
:param license_path: path to the file with license
:param by_name: use names instead of identifiers :param by_name: use names instead of identifiers
:param color: fill color :param color: fill color
:param outline: if true, draw outline beneath the icon :param outline: if true, draw outline beneath the icon
@ -157,6 +163,8 @@ class IconCollection:
outline_opacity=outline_opacity, outline_opacity=outline_opacity,
) )
shutil.copy(license_path, output_directory / "LICENSE")
def draw_grid( def draw_grid(
self, self,
file_name: Path, file_name: Path,
@ -218,9 +226,12 @@ def draw_icons() -> None:
# Draw individual icons. # Draw individual icons.
icons_by_id_path: Path = workspace.get_icons_by_id_path() 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() icons_by_name_path: Path = workspace.get_icons_by_name_path()
collection.draw_icons(icons_by_id_path) collection.draw_icons(
collection.draw_icons(icons_by_name_path, by_name=True) icons_by_name_path, workspace.ICONS_LICENSE_PATH, by_name=True
)
logging.info( logging.info(
f"Icons are written to {icons_by_name_path} and {icons_by_id_path}." f"Icons are written to {icons_by_name_path} and {icons_by_id_path}."

View file

@ -21,10 +21,11 @@ class Workspace:
# Project directories and files, that are the part of the repository. # 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" DEFAULT_SCHEME_PATH: Path = SCHEME_PATH / "default.yml"
ICONS_PATH: Path = HERE / Path("icons/icons.svg") ICONS_PATH: Path = HERE / "icons" / "icons.svg"
ICONS_CONFIG_PATH: Path = HERE / Path("icons/config.json") ICONS_CONFIG_PATH: Path = HERE / "icons" / "config.json"
ICONS_LICENSE_PATH: Path = HERE / "icons" / "LICENSE"
DOCUMENTATION_PATH: Path = Path("doc") DOCUMENTATION_PATH: Path = Path("doc")
GRID_PATH: Path = DOCUMENTATION_PATH / "grid.svg" GRID_PATH: Path = DOCUMENTATION_PATH / "grid.svg"

View file

@ -104,13 +104,13 @@ def test_mapcss() -> None:
COMMAND_LINES["mapcss"], COMMAND_LINES["mapcss"],
b"INFO MapCSS 0.2 scheme is written to out/map_machine_mapcss.\n", 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 out_path.is_dir()
assert (Path("out") / "map_machine_mapcss" / "icons").is_dir() assert out_path.is_dir()
assert ( assert (out_path / "icons" / "apple.svg").is_file()
Path("out") / "map_machine_mapcss" / "icons" / "apple.svg" assert (out_path / "map_machine.mapcss").is_file()
).is_file() assert (out_path / "icons" / "LICENSE").is_file()
assert (Path("out") / "map_machine_mapcss" / "map_machine.mapcss").is_file()
def test_element() -> None: def test_element() -> None:

View file

@ -1,6 +1,7 @@
""" """
Test icon generation for nodes. Test icon generation for nodes.
""" """
from pathlib import Path
from typing import Optional from typing import Optional
from colour import Color from colour import Color
@ -23,12 +24,18 @@ def test_grid() -> None:
def test_icons_by_id() -> None: def test_icons_by_id() -> None:
"""Test individual icons drawing.""" """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: def test_icons_by_name() -> None:
"""Test drawing individual icons that have names.""" """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: def get_icon(tags: dict[str, str]) -> IconSet:

View file

@ -18,7 +18,8 @@ def test_mapcss() -> None:
selector = writer.add_selector("node", matcher) selector = writer.add_selector("node", matcher)
assert ( assert (
selector selector
== """node[natural="tree"] { == """\
node[natural="tree"] {
icon-image: "icons/tree.svg"; icon-image: "icons/tree.svg";
} }
""" """