From 51e64a431c7f04dfd10e7ed0ee91f78d9657c4ab Mon Sep 17 00:00:00 2001 From: Tim Davies Date: Thu, 29 Feb 2024 15:45:30 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=A8=20Update=20black=20formatter?= =?UTF-8?q?=20and=20format=20project?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 15 +++------------ src/converter/base.py | 8 +++++--- src/converter/style.py | 16 ++++++++++------ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c139498..7e89dbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,17 +3,13 @@ name = "fig2sketch" readme = "README.md" requires-python = ">=3.10" dynamic = ["version"] -dependencies = [ - "Pillow==9.3.0", - "fonttools==4.38.0", - "appdirs==1.4.4", -] +dependencies = ["Pillow==9.3.0", "fonttools==4.38.0", "appdirs==1.4.4"] [project.scripts] fig2sketch = "fig2sketch:main" [build-system] -requires = [ "setuptools>=41", "setuptools-git-versioning<2", ] +requires = ["setuptools>=41", "setuptools-git-versioning<2"] build-backend = "setuptools.build_meta" [tool.setuptools-git-versioning] @@ -21,12 +17,7 @@ enabled = true [project.optional-dependencies] fast = ["fig-kiwi==0.1.0"] -dev = [ - "black==22.10.0", - "mypy==0.991", - "pytest==7.2.0", - "fig-kiwi==0.1.0", -] +dev = ["black==24.2.0", "mypy==0.991", "pytest==7.2.0", "fig-kiwi==0.1.0"] [tool.black] line-length = 99 diff --git a/src/converter/base.py b/src/converter/base.py index 8eb49cc..3794ea9 100644 --- a/src/converter/base.py +++ b/src/converter/base.py @@ -104,9 +104,11 @@ def base_shape(fig_node: dict) -> _BaseShape: return { **base_styled(fig_node), # type: ignore # Sketch smooth corners are a boolean, but here it's a percent. Use an arbitrary threshold - "pointRadiusBehaviour": PointRadiusBehaviour.V1_SMOOTH - if fig_node.get("cornerSmoothing", 0) > 0.4 - else PointRadiusBehaviour.V1, + "pointRadiusBehaviour": ( + PointRadiusBehaviour.V1_SMOOTH + if fig_node.get("cornerSmoothing", 0) > 0.4 + else PointRadiusBehaviour.V1 + ), } diff --git a/src/converter/style.py b/src/converter/style.py index 58190f1..79483d5 100644 --- a/src/converter/style.py +++ b/src/converter/style.py @@ -63,12 +63,16 @@ def convert(fig_node: dict) -> Style: sketch_style = Style( do_objectID=utils.gen_object_id(fig_node["guid"], b"style"), borderOptions=BorderOptions( - lineCapStyle=LINE_CAP_STYLE[fig_node["strokeCap"]] - if "strokeCap" in fig_node - else BorderOptions.__dict__["lineCapStyle"], - lineJoinStyle=LINE_JOIN_STYLE[fig_node["strokeJoin"]] - if "strokeJoin" in fig_node - else BorderOptions.__dict__["lineCapStyle"], + lineCapStyle=( + LINE_CAP_STYLE[fig_node["strokeCap"]] + if "strokeCap" in fig_node + else BorderOptions.__dict__["lineCapStyle"] + ), + lineJoinStyle=( + LINE_JOIN_STYLE[fig_node["strokeJoin"]] + if "strokeJoin" in fig_node + else BorderOptions.__dict__["lineCapStyle"] + ), dashPattern=fig_node.get("dashPattern", []), ), borders=[convert_border(fig_node, b) for b in fig_node.get("strokePaints", [])], From f58d6e9b30a86ecd272502ad1c4861110acec77e Mon Sep 17 00:00:00 2001 From: Tim Davies Date: Thu, 29 Feb 2024 15:48:04 +0000 Subject: [PATCH 2/3] Updates font SHA1 hashes and sketch model UUID values in integration tests Co-authored-by: Dmitry Rodionov --- tests/integration/test_structure.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_structure.py b/tests/integration/test_structure.py index 17c6134..645e9f7 100644 --- a/tests/integration/test_structure.py +++ b/tests/integration/test_structure.py @@ -91,11 +91,11 @@ def test_document(sketch_doc): assert doc["fontReferences"] == [ { "_class": "fontReference", - "do_objectID": "45406576-C7A2-4277-9C6E-B60F3D54ECC3", + "do_objectID": "46BF164E-CB00-4E1A-A5DE-9E6EB74A4F1F", "fontData": { "_class": "MSJSONFileReference", "_ref_class": "MSFontData", - "_ref": "fonts/07f64e2c2cfb24e6899ca67886d4ca9ed1c089c1", + "_ref": "fonts/be10cc8996f037af7331dc965bae42ef33478700", }, "fontFamilyName": "Inter", "fontFileName": "Inter-Regular.ttf", @@ -116,7 +116,7 @@ def test_document(sketch_doc): [ "images/616d10a80971e08c6b43a164746afac1972c7ccc.png", "images/92e4d5e0c24ffd632c3db3264e62cc907c2f5e29", - "fonts/07f64e2c2cfb24e6899ca67886d4ca9ed1c089c1", + "fonts/be10cc8996f037af7331dc965bae42ef33478700", ], ) def test_file_hashes(sketch_doc, img): @@ -223,7 +223,7 @@ def test_files(sketch_doc): "images/92e4d5e0c24ffd632c3db3264e62cc907c2f5e29", "pages/8F292FCA-49C0-4E31-957E-93FB2D1A7231.json", "pages/A4E5259A-9CE6-49D9-B4A1-A8062C205347.json", - "fonts/07f64e2c2cfb24e6899ca67886d4ca9ed1c089c1", + "fonts/be10cc8996f037af7331dc965bae42ef33478700", "document.json", "user.json", "meta.json", From c6f28b57c14e9d1ec8009b6a5ef650c0ff9b1f8e Mon Sep 17 00:00:00 2001 From: Tim Davies Date: Thu, 29 Feb 2024 15:52:41 +0000 Subject: [PATCH 3/3] Fix mypy errors --- src/converter/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/converter/base.py b/src/converter/base.py index 3794ea9..e74c45f 100644 --- a/src/converter/base.py +++ b/src/converter/base.py @@ -56,13 +56,13 @@ def base_layer(fig_node: dict) -> _BaseLayer: return { "do_objectID": utils.gen_object_id(fig_node["guid"]), "name": fig_node["name"], - "booleanOperation": -1, + "booleanOperation": BooleanOperation.NONE, "exportOptions": export_options(fig_node.get("exportSettings", [])), **positioning.convert(fig_node), # type: ignore "isFixedToViewport": False, "isLocked": fig_node["locked"], "isVisible": fig_node["visible"], - "layerListExpandedType": 0, + "layerListExpandedType": LayerListStatus.COLLAPSED, "nameIsFixed": False, "resizingConstraint": resizing_constraint(fig_node), "resizingType": ResizeType.STRETCH,