mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-22 13:36:26 +02:00
Move command list from configuration to code.
Standart commands are now in ui.py instead of .github/workflows/test.yml.
This commit is contained in:
parent
eeb4512b55
commit
972e4798b0
4 changed files with 23 additions and 54 deletions
|
@ -99,7 +99,7 @@ Icons are used to visualize tags for nodes and areas. Unlike other renderers, M
|
|||
|
||||
Feel free to request new icons via issues for whatever you want to see on the map. No matter how frequently the tag is used in OpenStreetMap since final goal is to cover all tags. However, common used tags have priority, other things being equal.
|
||||
|
||||
Generate icon grid and sets of individual icons with \m {\command {Test icon generation}}. It will create \m {out/icon_grid.svg} file, and SVG files in \m {out/icons_by_id} directory where files are named using shape identifiers (e.g. \m {power_tower_portal_2_level.svg}) and in \m {icons_by_name} directory where files are named using shape names (e.g. \m {Röntgen portal two-level transmission tower.svg}). Files from the last directory are used in OpenStreetMap wiki (e.g. \ref {https://wiki.openstreetmap.org/wiki/File:R%C3%B6ntgen_portal_two-level_transmission_tower.svg} {\m {File:Röntgen_portal_two-level_transmission_tower.svg}}).
|
||||
Generate icon grid and sets of individual icons with \m {\command {icons}}. It will create \m {out/icon_grid.svg} file, and SVG files in \m {out/icons_by_id} directory where files are named using shape identifiers (e.g. \m {power_tower_portal_2_level.svg}) and in \m {icons_by_name} directory where files are named using shape names (e.g. \m {Röntgen portal two-level transmission tower.svg}). Files from the last directory are used in OpenStreetMap wiki (e.g. \ref {https://wiki.openstreetmap.org/wiki/File:R%C3%B6ntgen_portal_two-level_transmission_tower.svg} {\m {File:Röntgen_portal_two-level_transmission_tower.svg}}).
|
||||
|
||||
\3 {Shape combination} {shape_combination}
|
||||
|
||||
|
@ -283,7 +283,7 @@ Map configuration options used by \m {render} and \m {tile} commands:
|
|||
|
||||
\2 {MapCSS 0.2 generation} {mapcss-0-2-generation}
|
||||
|
||||
Command \m {mapcss} is used to generate MapCSS scheme. \m {\command {Test MapCSS 0.2 generation}} will create \m {out/map_machine_mapcss} directory with simple MapCSS 0.2 scheme adding icons from Röntgen icon set to nodes and areas\: \m {.mapcss} file and directory with icons.
|
||||
Command \m {mapcss} is used to generate MapCSS scheme. \m {\command {mapcss}} will create \m {out/map_machine_mapcss} directory with simple MapCSS 0.2 scheme adding icons from Röntgen icon set to nodes and areas\: \m {.mapcss} file and directory with icons.
|
||||
|
||||
To create MapCSS with Map Machine style also for ways and relations, run \m {map-machine mapcss --ways}.
|
||||
|
||||
|
@ -292,7 +292,7 @@ To create MapCSS with Map Machine style also for ways and relations, run \m {map
|
|||
\3 {Use Map Machine as JOSM map paint style}
|
||||
|
||||
\list
|
||||
{Run \m {\command {Test MapCSS 0.2 generation}}.}
|
||||
{Run \m {\command {mapcss}}.}
|
||||
{Open \ref {https://josm.openstreetmap.de/} {JOSM}.}
|
||||
{Go to \kbd {Preferences} → Third tab on the left → \kbd {Map Paint Styles}.}
|
||||
{Active styles: press \kbd {+}.}
|
||||
|
|
|
@ -6,12 +6,12 @@ from abc import ABC
|
|||
from pathlib import Path
|
||||
from typing import Any, Union
|
||||
|
||||
import yaml
|
||||
from moire.default import Default, DefaultHTML, DefaultMarkdown, DefaultWiki
|
||||
from moire.moire import Tag
|
||||
|
||||
from map_machine import ui
|
||||
from map_machine.icon import ShapeExtractor
|
||||
from map_machine.ui import COMMANDS
|
||||
from map_machine.workspace import workspace
|
||||
|
||||
__author__ = "Sergey Vartanov"
|
||||
|
@ -115,34 +115,6 @@ class ArgumentParser(argparse.ArgumentParser):
|
|||
return Tag("table", table)
|
||||
|
||||
|
||||
class TestConfiguration:
|
||||
"""
|
||||
GitHub Actions test configuration.
|
||||
"""
|
||||
|
||||
def __init__(self, test_config: Path) -> None:
|
||||
self.steps: dict[str, Any] = {}
|
||||
|
||||
with test_config.open() as input_file:
|
||||
content: dict[str, Any] = yaml.load(
|
||||
input_file, Loader=yaml.FullLoader
|
||||
)
|
||||
steps: list[dict[str, Any]] = content["jobs"]["build"]["steps"]
|
||||
for step in steps:
|
||||
if "name" not in step:
|
||||
continue
|
||||
self.steps[step["name"]] = step
|
||||
|
||||
def get_command(self, name: str) -> str:
|
||||
"""Get shell script commands for the test."""
|
||||
return self.steps[name]["run"].strip()
|
||||
|
||||
|
||||
test_configuration: TestConfiguration = TestConfiguration(
|
||||
workspace.GITHUB_TEST_PATH
|
||||
)
|
||||
|
||||
|
||||
class MapMachineMoire(Default, ABC):
|
||||
"""
|
||||
Moire extension stub for Map Machine.
|
||||
|
@ -170,12 +142,8 @@ class MapMachineMoire(Default, ABC):
|
|||
return ""
|
||||
|
||||
def command(self, args: Arguments) -> str:
|
||||
"""
|
||||
Bash command from GitHub Actions configuration.
|
||||
|
||||
See .github/workflows/test.yml
|
||||
"""
|
||||
return test_configuration.get_command(self.clear(args[0]))
|
||||
"""Bash command from integration tests."""
|
||||
return "map-machine " + " ".join(COMMANDS[self.clear(args[0])])
|
||||
|
||||
def icon(self, args: Arguments) -> str:
|
||||
"""Image with Röntgen icon."""
|
||||
|
@ -225,12 +193,12 @@ class MapMachineHTML(MapMachineMoire, DefaultHTML):
|
|||
"""Simple table. First row is treated as header."""
|
||||
content: str = ""
|
||||
cell: str = "".join(
|
||||
["<th>" + self.parse(td, inblock=True) + "</th>" for td in arg[0]]
|
||||
["<th>" + self.parse(td, in_block=True) + "</th>" for td in arg[0]]
|
||||
)
|
||||
content += f"<tr>{cell}</tr>"
|
||||
for tr in arg[1:]:
|
||||
cell: str = "".join(
|
||||
["<td>" + self.parse(td, inblock=True) + "</td>" for td in tr]
|
||||
["<td>" + self.parse(td, in_block=True) + "</td>" for td in tr]
|
||||
)
|
||||
content += f"<tr>{cell}</tr>"
|
||||
return f"<table>{content}</table>"
|
||||
|
|
|
@ -14,6 +14,14 @@ __email__ = "me@enzet.ru"
|
|||
BOXES: str = " ▏▎▍▌▋▊▉"
|
||||
BOXES_LENGTH: int = len(BOXES)
|
||||
|
||||
COMMANDS: dict[str, list[str]] = {
|
||||
"render": ["render", "-b", "10.000,20.000,10.001,20.001"],
|
||||
"icons": ["icons"],
|
||||
"mapcss": ["mapcss"],
|
||||
"element": ["element", "--node", "amenity=bench,material=wood"],
|
||||
"tile": ["tile", "--coordinates", "50.000,40.000"],
|
||||
}
|
||||
|
||||
|
||||
def parse_options(args: list[str]) -> argparse.Namespace:
|
||||
"""Parse Map Machine command-line options."""
|
||||
|
|
|
@ -10,6 +10,8 @@ __email__ = "me@enzet.ru"
|
|||
from xml.etree import ElementTree
|
||||
from xml.etree.ElementTree import Element
|
||||
|
||||
from map_machine.ui import COMMANDS
|
||||
|
||||
|
||||
def error_run(arguments: list[str], message: bytes) -> None:
|
||||
"""Run command that should fail and check error message."""
|
||||
|
@ -38,13 +40,7 @@ def test_wrong_render_arguments() -> None:
|
|||
def test_render() -> None:
|
||||
"""Test `render` command."""
|
||||
run(
|
||||
[
|
||||
"render",
|
||||
"-b",
|
||||
"10.000,20.000,10.001,20.001",
|
||||
"--cache",
|
||||
"tests/data",
|
||||
],
|
||||
COMMANDS["render"] + ["--cache", "tests/data"],
|
||||
b"INFO Writing output SVG to out/map.svg...\n",
|
||||
)
|
||||
with Path("out/map.svg").open() as output_file:
|
||||
|
@ -58,7 +54,7 @@ def test_render() -> None:
|
|||
def test_icons() -> None:
|
||||
"""Test `icons` command."""
|
||||
run(
|
||||
["icons"],
|
||||
COMMANDS["icons"],
|
||||
b"INFO Icon grid is written to out/icon_grid.svg.\n"
|
||||
b"INFO Icons are written to out/icons_by_name and out/icons_by_id.\n",
|
||||
)
|
||||
|
@ -73,7 +69,7 @@ def test_icons() -> None:
|
|||
def test_mapcss() -> None:
|
||||
"""Test `mapcss` command."""
|
||||
run(
|
||||
["mapcss"],
|
||||
COMMANDS["mapcss"],
|
||||
b"INFO MapCSS 0.2 scheme is written to out/map_machine_mapcss.\n",
|
||||
)
|
||||
|
||||
|
@ -87,10 +83,7 @@ def test_mapcss() -> None:
|
|||
|
||||
def test_element() -> None:
|
||||
"""Test `element` command."""
|
||||
run(
|
||||
["element", "--node", "amenity=bench,material=wood"],
|
||||
b"INFO Element is written to out/element.svg.\n",
|
||||
)
|
||||
run(COMMANDS["element"], b"INFO Element is written to out/element.svg.\n")
|
||||
|
||||
assert (Path("out") / "element.svg").is_file()
|
||||
|
||||
|
@ -98,7 +91,7 @@ def test_element() -> None:
|
|||
def test_tile() -> None:
|
||||
"""Test `tile` command."""
|
||||
run(
|
||||
["tile", "--coordinates", "50.000,40.000", "--cache", "tests/data"],
|
||||
COMMANDS["tile"] + ["--cache", "tests/data"],
|
||||
b"INFO Tile is drawn to out/tiles/tile_18_160199_88904.svg.\n"
|
||||
b"INFO SVG file is rasterized to out/tiles/tile_18_160199_88904.png.\n",
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue