Repository: abey79/vpype

Issue:
Add a `--no-date` option to `write`
Rationale: when auto-generating SVG under VCS (e.g. based on .vpy files), the creation date in the SVG file is annoying because it generates unwanted diff.


Discussion:

Resolving patch:
diff --git a/vpype/io.py b/vpype/io.py
--- a/vpype/io.py
+++ b/vpype/io.py
@@ -621,6 +621,7 @@ def write_svg(
     show_pen_up: bool = False,
     color_mode: str = "default",
     use_svg_metadata: bool = False,
+    set_date: bool = True,
 ) -> None:
     """Create a SVG from a :py:class:`Document` instance.
 
@@ -665,6 +666,8 @@ def write_svg(
         color_mode: "default" (system property), "none" (no formatting), "layer" (one color per
             layer), "path" (one color per path)
         use_svg_metadata: apply ``svg_``-prefixed properties as SVG attributes
+        set_date: controls whether the current date and time is set in the SVG's metadata
+            (disabling it is useful for auto-generated SVG under VCS)
     """
 
     # compute bounds
@@ -713,8 +716,9 @@ def write_svg(
     fmt.text = "image/svg+xml"
     source = ElementTree.SubElement(work, "dc:source")
     source.text = source_string
-    date = ElementTree.SubElement(work, "dc:date")
-    date.text = datetime.datetime.now().isoformat()
+    if set_date:
+        date = ElementTree.SubElement(work, "dc:date")
+        date.text = datetime.datetime.now().isoformat()
     dwg.set_metadata(metadata)
 
     color_idx = 0
diff --git a/vpype_cli/write.py b/vpype_cli/write.py
--- a/vpype_cli/write.py
+++ b/vpype_cli/write.py
@@ -169,7 +169,12 @@
     "--restore-attribs",
     is_flag=True,
     default=False,
-    help="[SVG only] attempt to restore SVG attributes from properties",
+    help="[SVG only] attempt to restore SVG attributes from properties.",
+)
+@click.option(
+    "--dont-set-date",
+    is_flag=True,
+    help="[SVG only] do not add date metadata (useful for auto-generated SVG under VCS).",
 )
 @click.option(
     "-d", "--device", type=TextType(), help="[HPGL only] Type of the plotter device."
@@ -203,6 +208,7 @@ def write(
     center: bool,
     layer_label: str | None,
     restore_attribs: bool,
+    dont_set_date: bool,
     pen_up: bool,
     color_mode: str,
     device: str | None,
@@ -238,6 +244,7 @@ def write(
             show_pen_up=pen_up,
             color_mode=color_mode,
             use_svg_metadata=restore_attribs,
+            set_date=not dont_set_date,
         )
     elif file_format == "hpgl":
         if not page_size:


Test patch:
diff --git a/tests/test_files.py b/tests/test_files.py
--- a/tests/test_files.py
+++ b/tests/test_files.py
@@ -494,3 +494,15 @@ def test_read_by_attr_stdin_sets_source_properties(monkeypatch):
     doc = vpype_cli.execute(f"read -a stroke -a fill -")
     assert vp.METADATA_FIELD_SOURCE not in doc.metadata
     assert doc.sources == set()
+
+
+def test_write_set_date(capsys):
+    vpype_cli.execute("line 0 0 10 10 write -f svg -")
+    output = capsys.readouterr().out
+    assert "<dc:date>" in output
+
+
+def test_write_dont_set_date(capsys):
+    vpype_cli.execute("line 0 0 10 10 write -f svg --dont-set-date -")
+    output = capsys.readouterr().out
+    assert "<dc:date>" not in output