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.draw_icons(
icons_with_outline_path,
workspace.ICONS_LICENSE_PATH,
color=Color("black"),
outline=True,
outline_opacity=0.5,

View file

@ -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}."

View file

@ -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"

View file

@ -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:

View file

@ -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:

View file

@ -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";
}
"""