Repository: googlefonts/glyphsLib

Issue:
Add support for instance properties
When opening and saving a Glyphs file, the `properties` section gets removed in each instance as illustrated below.

```diff
-properties = (
-{
-key = familyNames;
-values = (
-{
-language = dflt;
-value = "Proxima Nova ExCn";
-}
-);
-},
-{
-key = styleMapFamilyNames;
-values = (
-{
-language = dflt;
-value = "Proxima Nova ExCn Black";
-}
-);
-},
-{
-key = postscriptFontName;
-value = "ProximaNovaExCn-Black";
-},
-{
-key = preferredFamilyNames;
-values = (
-{
-language = dflt;
-value = "Proxima Nova Extra Condensed";
-}
-);
-}
-);
```


<img width="1381" alt="Skärmavbild 2023-02-20 kl  11 07 34" src="https://user-images.githubusercontent.com/57440/220078027-a8fcc93e-3aeb-4352-9f0d-4b36ad959624.png">

Discussion:
IvanUkhov: I have confirmed that this preserves instance properties. The error below is arguably unrelated to the cahnge.
anthrotype: @IvanUkhov codecov flakiness is unrelated (see https://github.com/codecov/codecov-action/issues/837), right now we can only either keep retrying until the upload of the coverage file is successful or just ignore it..

I'll take a look at the PR, thanks
anthrotype: > I have confirmed that this preserves instance properties.
anthrotype: > I have confirmed that this preserves instance properties.

nice. If it's not too much trouble, mind adding a small test?

Patch:
diff --git a/Lib/glyphsLib/classes.py b/Lib/glyphsLib/classes.py
index ba9c08d2..1b8b5e64 100755
--- a/Lib/glyphsLib/classes.py
+++ b/Lib/glyphsLib/classes.py
@@ -3195,6 +3195,8 @@ class GSInstance(GSBase):
         writer.writeObjectKeyValue(self, "linkStyle", "if_true")
         writer.writeObjectKeyValue(self, "manualInterpolation", "if_true")
         writer.writeObjectKeyValue(self, "name")
+        if writer.format_version > 2:
+            writer.writeObjectKeyValue(self, "properties", condition="if_true")
         writer.writeObjectKeyValue(
             self, "weight", default="Regular", keyName="weightClass"
         )


Test patch:
diff --git a/tests/builder/instances_test.py b/tests/builder/instances_test.py
index 8a4e5415..e7920164 100644
--- a/tests/builder/instances_test.py
+++ b/tests/builder/instances_test.py
@@ -147,6 +147,22 @@ def test_glyphs3_instance_filtering():
     assert len(doc.instances) == 2
 
 
+def test_glyphs3_instance_properties(tmpdir):
+    expected_num_properties = [0, 0, 1, 1, 1, 1]
+
+    file = "InstanceFamilyName-G3.glyphs"
+    font = glyphsLib.GSFont(os.path.join(DATA, file))
+
+    for instance, num in zip(font.instances, expected_num_properties):
+        assert len(instance.properties) == num
+
+    font.save(tmpdir / file)
+    font = glyphsLib.GSFont(tmpdir / file)
+
+    for instance, num in zip(font.instances, expected_num_properties):
+        assert len(instance.properties) == num
+
+
 def test_rename_glyphs(tmpdir):
     font = glyphsLib.GSFont(os.path.join(DATA, "RenameGlyphsTest.glyphs"))
     instance_dir = tmpdir.ensure_dir("instance_ufo")