From b024c080fe73d1d0cba46b1cf563a2faec2f6435 Mon Sep 17 00:00:00 2001 From: Onur Solmaz <2453968+osolmaz@users.noreply.github.com> Date: Tue, 11 Mar 2025 18:45:09 +0100 Subject: [PATCH 1/4] Add pre-commit hook --- .pre-commit-config.yaml | 21 ++++++++ pyproject.toml | 2 + uv.lock | 104 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..3ee5dad --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +# Pre-commit hooks +# 1. Run ruff on all python files +repos: +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.9.4 + hooks: + # Run the linter. + # - id: ruff + # Run the formatter. + - id: ruff + args: ["check", "--select", "I", "--fix"] + - id: ruff-format + +# 2. Run terraform fmt on all terraform files +- repo: https://github.com/antonbabenko/pre-commit-terraform + rev: v1.97.3 + hooks: + - id: terraform_fmt + args: + - --recursive diff --git a/pyproject.toml b/pyproject.toml index 4b63ab3..cf467d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,9 @@ convert_jsondoc = "jsondoc.bin.convert_jsondoc:main" [dependency-groups] dev = [ "datamodel-code-generator>=0.25.9,<0.26", + "pre-commit>=4.1.0", "pytest>=8.3.5", + "ruff>=0.9.10", ] [tool.hatch.build.targets.sdist] diff --git a/uv.lock b/uv.lock index b509662..789c9a0 100644 --- a/uv.lock +++ b/uv.lock @@ -98,6 +98,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/12/90/3c9ff0512038035f59d279fddeb79f5f1eccd8859f06d6163c58798b9487/certifi-2024.8.30-py3-none-any.whl", hash = "sha256:922820b53db7a7257ffbda3f597266d435245903d80737e34f8a45ff3e3230d8", size = 167321 }, ] +[[package]] +name = "cfgv" +version = "3.4.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/11/74/539e56497d9bd1d484fd863dd69cbbfa653cd2aa27abfe35653494d85e94/cfgv-3.4.0.tar.gz", hash = "sha256:e52591d4c5f5dead8e0f673fb16db7949d2cfb3f7da4582893288f0ded8fe560", size = 7114 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c5/55/51844dd50c4fc7a33b653bfaba4c2456f06955289ca770a5dbd5fd267374/cfgv-3.4.0-py2.py3-none-any.whl", hash = "sha256:b7265b1f29fd3316bfcd2b330d63d024f2bfd8bcb8b0272f8e19a504856c48f9", size = 7249 }, +] + [[package]] name = "charset-normalizer" version = "3.3.2" @@ -172,6 +181,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/d5/50/83c593b07763e1161326b3b8c6686f0f4b0f24d5526546bee538c89837d6/decorator-5.1.1-py3-none-any.whl", hash = "sha256:b8c3f85900b9dc423225913c5aace94729fe1fa9763b38939a95226f02d37186", size = 9073 }, ] +[[package]] +name = "distlib" +version = "0.3.9" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/0d/dd/1bec4c5ddb504ca60fc29472f3d27e8d4da1257a854e1d96742f15c1d02d/distlib-0.3.9.tar.gz", hash = "sha256:a60f20dea646b8a33f3e7772f74dc0b2d0772d2837ee1342a00645c81edf9403", size = 613923 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/91/a1/cf2472db20f7ce4a6be1253a81cfdf85ad9c7885ffbed7047fb72c24cf87/distlib-0.3.9-py2.py3-none-any.whl", hash = "sha256:47f8c22fd27c27e25a65601af709b38e4f0a45ea4fc2e710f65755fa8caaaf87", size = 468973 }, +] + [[package]] name = "dnspython" version = "2.6.1" @@ -203,6 +221,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/b5/fd/afcd0496feca3276f509df3dbd5dae726fcc756f1a08d9e25abe1733f962/executing-2.1.0-py2.py3-none-any.whl", hash = "sha256:8d63781349375b5ebccc3142f4b30350c0cd9c79f921cde38be2be4637e98eaf", size = 25805 }, ] +[[package]] +name = "filelock" +version = "3.17.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/dc/9c/0b15fb47b464e1b663b1acd1253a062aa5feecb07d4e597daea542ebd2b5/filelock-3.17.0.tar.gz", hash = "sha256:ee4e77401ef576ebb38cd7f13b9b28893194acc20a8e68e18730ba9c0e54660e", size = 18027 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/89/ec/00d68c4ddfedfe64159999e5f8a98fb8442729a63e2077eb9dcd89623d27/filelock-3.17.0-py3-none-any.whl", hash = "sha256:533dc2f7ba78dc2f0f531fc6c4940addf7b70a481e269a5a3b93be94ffbe8338", size = 16164 }, +] + [[package]] name = "genson" version = "1.3.0" @@ -212,6 +239,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/f8/5c/e226de133afd8bb267ec27eead9ae3d784b95b39a287ed404caab39a5f50/genson-1.3.0-py3-none-any.whl", hash = "sha256:468feccd00274cc7e4c09e84b08704270ba8d95232aa280f65b986139cec67f7", size = 21470 }, ] +[[package]] +name = "identify" +version = "2.6.9" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/9b/98/a71ab060daec766acc30fb47dfca219d03de34a70d616a79a38c6066c5bf/identify-2.6.9.tar.gz", hash = "sha256:d40dfe3142a1421d8518e3d3985ef5ac42890683e32306ad614a29490abeb6bf", size = 99249 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/07/ce/0845144ed1f0e25db5e7a79c2354c1da4b5ce392b8966449d5db8dca18f1/identify-2.6.9-py2.py3-none-any.whl", hash = "sha256:c98b4322da415a8e5a70ff6e51fbc2d2932c015532d77e9f8537b4ba7813b150", size = 99101 }, +] + [[package]] name = "idna" version = "3.8" @@ -324,7 +360,9 @@ dependencies = [ [package.dev-dependencies] dev = [ { name = "datamodel-code-generator" }, + { name = "pre-commit" }, { name = "pytest" }, + { name = "ruff" }, ] [package.metadata] @@ -343,7 +381,9 @@ requires-dist = [ [package.metadata.requires-dev] dev = [ { name = "datamodel-code-generator", specifier = ">=0.25.9,<0.26" }, + { name = "pre-commit", specifier = ">=4.1.0" }, { name = "pytest", specifier = ">=8.3.5" }, + { name = "ruff", specifier = ">=0.9.10" }, ] [[package]] @@ -412,6 +452,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/2a/e2/5d3f6ada4297caebe1a2add3b126fe800c96f56dbe5d1988a2cbe0b267aa/mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d", size = 4695 }, ] +[[package]] +name = "nodeenv" +version = "1.9.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/43/16/fc88b08840de0e0a72a2f9d8c6bae36be573e475a6326ae854bcc549fc45/nodeenv-1.9.1.tar.gz", hash = "sha256:6ec12890a2dab7946721edbfbcd91f3319c6ccc9aec47be7c7e6b7011ee6645f", size = 47437 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d2/1d/1b658dbd2b9fa9c4c9f32accbfc0205d532c8c6194dc0f2a4c0428e7128a/nodeenv-1.9.1-py2.py3-none-any.whl", hash = "sha256:ba11c9782d29c27c70ffbdda2d7415098754709be8a7056d79a737cd901155c9", size = 22314 }, +] + [[package]] name = "packaging" version = "24.1" @@ -499,6 +548,22 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/88/5f/e351af9a41f866ac3f1fac4ca0613908d9a41741cfcf2228f4ad853b697d/pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669", size = 20556 }, ] +[[package]] +name = "pre-commit" +version = "4.1.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "cfgv" }, + { name = "identify" }, + { name = "nodeenv" }, + { name = "pyyaml" }, + { name = "virtualenv" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/2a/13/b62d075317d8686071eb843f0bb1f195eb332f48869d3c31a4c6f1e063ac/pre_commit-4.1.0.tar.gz", hash = "sha256:ae3f018575a588e30dfddfab9a05448bfbd6b73d78709617b5a2b853549716d4", size = 193330 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/43/b3/df14c580d82b9627d173ceea305ba898dca135feb360b6d84019d0803d3b/pre_commit-4.1.0-py2.py3-none-any.whl", hash = "sha256:d29e7cb346295bcc1cc75fc3e92e343495e3ea0196c9ec6ba53f49f10ab6ae7b", size = 220560 }, +] + [[package]] name = "prompt-toolkit" version = "3.0.47" @@ -751,6 +816,31 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/95/cc/109eb8b9863680411ae703664abacaa035820c7755acc9686d5dd02cdd2e/rpds_py-0.20.0-cp313-none-win_amd64.whl", hash = "sha256:9bc2d153989e3216b0559251b0c260cfd168ec78b1fac33dd485750a228db5a2", size = 214111 }, ] +[[package]] +name = "ruff" +version = "0.9.10" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/20/8e/fafaa6f15c332e73425d9c44ada85360501045d5ab0b81400076aff27cf6/ruff-0.9.10.tar.gz", hash = "sha256:9bacb735d7bada9cfb0f2c227d3658fc443d90a727b47f206fb33f52f3c0eac7", size = 3759776 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/73/b2/af7c2cc9e438cbc19fafeec4f20bfcd72165460fe75b2b6e9a0958c8c62b/ruff-0.9.10-py3-none-linux_armv6l.whl", hash = "sha256:eb4d25532cfd9fe461acc83498361ec2e2252795b4f40b17e80692814329e42d", size = 10049494 }, + { url = "https://files.pythonhosted.org/packages/6d/12/03f6dfa1b95ddd47e6969f0225d60d9d7437c91938a310835feb27927ca0/ruff-0.9.10-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:188a6638dab1aa9bb6228a7302387b2c9954e455fb25d6b4470cb0641d16759d", size = 10853584 }, + { url = "https://files.pythonhosted.org/packages/02/49/1c79e0906b6ff551fb0894168763f705bf980864739572b2815ecd3c9df0/ruff-0.9.10-py3-none-macosx_11_0_arm64.whl", hash = "sha256:5284dcac6b9dbc2fcb71fdfc26a217b2ca4ede6ccd57476f52a587451ebe450d", size = 10155692 }, + { url = "https://files.pythonhosted.org/packages/5b/01/85e8082e41585e0e1ceb11e41c054e9e36fed45f4b210991052d8a75089f/ruff-0.9.10-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:47678f39fa2a3da62724851107f438c8229a3470f533894b5568a39b40029c0c", size = 10369760 }, + { url = "https://files.pythonhosted.org/packages/a1/90/0bc60bd4e5db051f12445046d0c85cc2c617095c0904f1aa81067dc64aea/ruff-0.9.10-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:99713a6e2766b7a17147b309e8c915b32b07a25c9efd12ada79f217c9c778b3e", size = 9912196 }, + { url = "https://files.pythonhosted.org/packages/66/ea/0b7e8c42b1ec608033c4d5a02939c82097ddcb0b3e393e4238584b7054ab/ruff-0.9.10-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:524ee184d92f7c7304aa568e2db20f50c32d1d0caa235d8ddf10497566ea1a12", size = 11434985 }, + { url = "https://files.pythonhosted.org/packages/d5/86/3171d1eff893db4f91755175a6e1163c5887be1f1e2f4f6c0c59527c2bfd/ruff-0.9.10-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:df92aeac30af821f9acf819fc01b4afc3dfb829d2782884f8739fb52a8119a16", size = 12155842 }, + { url = "https://files.pythonhosted.org/packages/89/9e/700ca289f172a38eb0bca752056d0a42637fa17b81649b9331786cb791d7/ruff-0.9.10-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:de42e4edc296f520bb84954eb992a07a0ec5a02fecb834498415908469854a52", size = 11613804 }, + { url = "https://files.pythonhosted.org/packages/f2/92/648020b3b5db180f41a931a68b1c8575cca3e63cec86fd26807422a0dbad/ruff-0.9.10-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:d257f95b65806104b6b1ffca0ea53f4ef98454036df65b1eda3693534813ecd1", size = 13823776 }, + { url = "https://files.pythonhosted.org/packages/5e/a6/cc472161cd04d30a09d5c90698696b70c169eeba2c41030344194242db45/ruff-0.9.10-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b60dec7201c0b10d6d11be00e8f2dbb6f40ef1828ee75ed739923799513db24c", size = 11302673 }, + { url = "https://files.pythonhosted.org/packages/6c/db/d31c361c4025b1b9102b4d032c70a69adb9ee6fde093f6c3bf29f831c85c/ruff-0.9.10-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:d838b60007da7a39c046fcdd317293d10b845001f38bcb55ba766c3875b01e43", size = 10235358 }, + { url = "https://files.pythonhosted.org/packages/d1/86/d6374e24a14d4d93ebe120f45edd82ad7dcf3ef999ffc92b197d81cdc2a5/ruff-0.9.10-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:ccaf903108b899beb8e09a63ffae5869057ab649c1e9231c05ae354ebc62066c", size = 9886177 }, + { url = "https://files.pythonhosted.org/packages/00/62/a61691f6eaaac1e945a1f3f59f1eea9a218513139d5b6c2b8f88b43b5b8f/ruff-0.9.10-py3-none-musllinux_1_2_i686.whl", hash = "sha256:f9567d135265d46e59d62dc60c0bfad10e9a6822e231f5b24032dba5a55be6b5", size = 10864747 }, + { url = "https://files.pythonhosted.org/packages/ee/94/2c7065e1d92a8a8a46d46d9c3cf07b0aa7e0a1e0153d74baa5e6620b4102/ruff-0.9.10-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:5f202f0d93738c28a89f8ed9eaba01b7be339e5d8d642c994347eaa81c6d75b8", size = 11360441 }, + { url = "https://files.pythonhosted.org/packages/a7/8f/1f545ea6f9fcd7bf4368551fb91d2064d8f0577b3079bb3f0ae5779fb773/ruff-0.9.10-py3-none-win32.whl", hash = "sha256:bfb834e87c916521ce46b1788fbb8484966e5113c02df216680102e9eb960029", size = 10247401 }, + { url = "https://files.pythonhosted.org/packages/4f/18/fb703603ab108e5c165f52f5b86ee2aa9be43bb781703ec87c66a5f5d604/ruff-0.9.10-py3-none-win_amd64.whl", hash = "sha256:f2160eeef3031bf4b17df74e307d4c5fb689a6f3a26a2de3f7ef4044e3c484f1", size = 11366360 }, + { url = "https://files.pythonhosted.org/packages/35/85/338e603dc68e7d9994d5d84f24adbf69bae760ba5efd3e20f5ff2cec18da/ruff-0.9.10-py3-none-win_arm64.whl", hash = "sha256:5fd804c0327a5e5ea26615550e706942f348b197d5475ff34c19733aee4b2e69", size = 10436892 }, +] + [[package]] name = "six" version = "1.16.0" @@ -822,6 +912,20 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/ca/1c/89ffc63a9605b583d5df2be791a27bc1a42b7c32bab68d3c8f2f73a98cd4/urllib3-2.2.2-py3-none-any.whl", hash = "sha256:a448b2f64d686155468037e1ace9f2d2199776e17f0a46610480d311f73e3472", size = 121444 }, ] +[[package]] +name = "virtualenv" +version = "20.29.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "distlib" }, + { name = "filelock" }, + { name = "platformdirs" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/c7/9c/57d19fa093bcf5ac61a48087dd44d00655f85421d1aa9722f8befbf3f40a/virtualenv-20.29.3.tar.gz", hash = "sha256:95e39403fcf3940ac45bc717597dba16110b74506131845d9b687d5e73d947ac", size = 4320280 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c2/eb/c6db6e3001d58c6a9e67c74bb7b4206767caa3ccc28c6b9eaf4c23fb4e34/virtualenv-20.29.3-py3-none-any.whl", hash = "sha256:3e3d00f5807e83b234dfb6122bf37cfadf4be216c53a49ac059d02414f819170", size = 4301458 }, +] + [[package]] name = "wcwidth" version = "0.2.13" From 62c2018b99993d7a0bac0fbae4e24e71f2234412 Mon Sep 17 00:00:00 2001 From: Onur Solmaz <2453968+osolmaz@users.noreply.github.com> Date: Tue, 11 Mar 2025 18:45:46 +0100 Subject: [PATCH 2/4] Checkpoint --- .pre-commit-config.yaml | 8 - conftest.py | 13 +- jsondoc/bin/convert_jsondoc.py | 13 +- jsondoc/convert/html.py | 10 +- jsondoc/convert/markdown.py | 9 +- jsondoc/convert/utils.py | 3 +- jsondoc/models/block/__init__.py | 36 ++--- jsondoc/models/block/base/__init__.py | 12 +- .../types/bulleted_list_item/__init__.py | 9 +- jsondoc/models/block/types/code/__init__.py | 153 +++++++++--------- jsondoc/models/block/types/column/__init__.py | 5 +- .../block/types/column_list/__init__.py | 7 +- .../models/block/types/divider/__init__.py | 5 +- .../models/block/types/equation/__init__.py | 7 +- .../models/block/types/heading_1/__init__.py | 9 +- .../models/block/types/heading_2/__init__.py | 7 +- .../models/block/types/heading_3/__init__.py | 7 +- jsondoc/models/block/types/image/__init__.py | 7 +- .../types/numbered_list_item/__init__.py | 9 +- .../models/block/types/paragraph/__init__.py | 9 +- jsondoc/models/block/types/quote/__init__.py | 9 +- .../models/block/types/rich_text/__init__.py | 4 +- .../types/rich_text/equation/__init__.py | 9 +- .../block/types/rich_text/text/__init__.py | 7 +- jsondoc/models/block/types/table/__init__.py | 9 +- .../models/block/types/table_row/__init__.py | 9 +- jsondoc/models/block/types/to_do/__init__.py | 9 +- jsondoc/models/block/types/toggle/__init__.py | 7 +- jsondoc/models/file/__init__.py | 4 +- jsondoc/models/file/external/__init__.py | 5 +- jsondoc/models/file/file/__init__.py | 5 +- jsondoc/models/page/__init__.py | 27 ++-- jsondoc/models/shared_definitions/__init__.py | 38 ++--- jsondoc/serialize.py | 6 +- jsondoc/transcribe/benchmark.py | 4 +- tests/test_html_to_jsondoc.py | 7 +- 36 files changed, 256 insertions(+), 241 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3ee5dad..3a99d19 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,11 +11,3 @@ repos: - id: ruff args: ["check", "--select", "I", "--fix"] - id: ruff-format - -# 2. Run terraform fmt on all terraform files -- repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.97.3 - hooks: - - id: terraform_fmt - args: - - --recursive diff --git a/conftest.py b/conftest.py index 6df0eff..1d9354a 100644 --- a/conftest.py +++ b/conftest.py @@ -1,7 +1,9 @@ import os import sys + import pytest + # This collects tests that aren't standard pytest tests def pytest_collect_file(parent, file_path): # Special handling for test_validation.py @@ -9,16 +11,19 @@ def pytest_collect_file(parent, file_path): return ValidationTestFile.from_parent(parent, path=file_path) return None + class ValidationTestFile(pytest.File): def collect(self): # Create a special test item for test_validation.py yield ValidationTestItem.from_parent(self, name="test_validation") + class ValidationTestItem(pytest.Item): def runtest(self): # Run the test_validation.py script with "schema" as the argument import subprocess - print(f"\n{'-'*80}\nRunning test_validation.py with 'schema' argument...") + + print(f"\n{'-' * 80}\nRunning test_validation.py with 'schema' argument...") result = subprocess.run( [sys.executable, str(self.fspath), "schema"], @@ -34,17 +39,19 @@ def runtest(self): if result.returncode != 0: raise ValidationTestFailure(result.stdout, result.stderr) - print(f"test_validation.py completed successfully.\n{'-'*80}") + print(f"test_validation.py completed successfully.\n{'-' * 80}") def reportinfo(self): return self.fspath, 0, f"test_validation.py schema" + class ValidationTestFailure(Exception): def __init__(self, stdout, stderr): self.stdout = stdout self.stderr = stderr super().__init__(f"test_validation.py failed") + @pytest.hookimpl(tryfirst=True) def pytest_exception_interact(node, call, report): if isinstance(call.excinfo.value, ValidationTestFailure): @@ -52,4 +59,4 @@ def pytest_exception_interact(node, call, report): print(f"test_validation.py failed!") if failure.stderr: print(f"STDERR:\n{failure.stderr}") - print(f"{'-'*80}") \ No newline at end of file + print(f"{'-' * 80}") diff --git a/jsondoc/bin/convert_jsondoc.py b/jsondoc/bin/convert_jsondoc.py index 533e8b0..2f15206 100644 --- a/jsondoc/bin/convert_jsondoc.py +++ b/jsondoc/bin/convert_jsondoc.py @@ -1,5 +1,6 @@ import argparse import sys + import pypandoc from jsondoc.convert.html import html_to_jsondoc @@ -81,9 +82,9 @@ def convert_to_jsondoc( input_content = None if input_file is None: - assert ( - source_format is not None - ), "Source format must be specified if input file is not provided" + assert source_format is not None, ( + "Source format must be specified if input file is not provided" + ) # Read from stdin input_content = sys.stdin.read() @@ -103,9 +104,9 @@ def convert_to_jsondoc( if source_format == "jsondoc": assert target_format is not None, "Target format must be specified" - assert ( - target_format == "markdown" - ), "Currently can only convert from JSON-DOC to Markdown" + assert target_format == "markdown", ( + "Currently can only convert from JSON-DOC to Markdown" + ) if input_content is None: raise Exception( diff --git a/jsondoc/convert/html.py b/jsondoc/convert/html.py index cb238ab..edb261d 100644 --- a/jsondoc/convert/html.py +++ b/jsondoc/convert/html.py @@ -373,8 +373,7 @@ def __init__(self, **options): self.options.update(options) if self.options["strip"] is not None and self.options["convert"] is not None: raise ValueError( - "You may specify either tags to strip or tags to" - " convert, but not both." + "You may specify either tags to strip or tags to convert, but not both." ) def convert(self, html: str | bytes) -> Page | BlockBase | List[BlockBase]: @@ -382,7 +381,6 @@ def convert(self, html: str | bytes) -> Page | BlockBase | List[BlockBase]: return self.convert_soup(soup) def convert_soup(self, soup: BeautifulSoup) -> Page | BlockBase | List[BlockBase]: - children = self.process_tag(soup, convert_as_inline=False, children_only=True) children = run_final_block_transformations(children) is_page = self._is_soup_page(soup) @@ -483,9 +481,9 @@ def is_nested_node(el): # text = convert_fn(node, text, convert_as_inline) # current_level_object = convert_fn(node, convert_as_inline) convert_output = convert_fn(node, convert_as_inline) - assert isinstance( - convert_output, (ConvertOutput, NoneType) - ), f"Convert function {convert_fn} must return a ConvertOutput or None" + assert isinstance(convert_output, (ConvertOutput, NoneType)), ( + f"Convert function {convert_fn} must return a ConvertOutput or None" + ) if convert_output is not None: current_level_object = convert_output.main_object diff --git a/jsondoc/convert/markdown.py b/jsondoc/convert/markdown.py index 73d8155..8332f2a 100644 --- a/jsondoc/convert/markdown.py +++ b/jsondoc/convert/markdown.py @@ -1,6 +1,8 @@ import re from typing import List, Union + from pydantic import validate_call + from jsondoc.convert.utils import get_rich_text_from_block from jsondoc.models.block.base import BlockBase from jsondoc.models.block.types.code import CodeBlock @@ -19,7 +21,6 @@ from jsondoc.models.shared_definitions import Annotations from jsondoc.serialize import load_jsondoc, load_page - convert_heading_re = re.compile(r"convert_heading_(\d+)") line_beginning_re = re.compile(r"^", re.MULTILINE) whitespace_re = re.compile(r"[\t ]+") @@ -60,7 +61,6 @@ def chomp(text): class JsonDocToMarkdownConverter(object): - class DefaultOptions: autolinks = True bullets = "*+-" # An iterable of bullet types. @@ -90,8 +90,7 @@ def __init__(self, **options): self.options.update(options) if self.options["strip"] is not None and self.options["convert"] is not None: raise ValueError( - "You may specify either tags to strip or tags to" - " convert, but not both." + "You may specify either tags to strip or tags to convert, but not both." ) def __getattr__(self, attr): @@ -111,7 +110,6 @@ def convert_tag(block, convert_as_inline): @validate_call def convert(self, obj: str | dict | BlockBase | List[BlockBase] | Page) -> str: - if isinstance(obj, (str, dict)): jsondoc = load_jsondoc(obj) else: @@ -145,7 +143,6 @@ def _get_children_content(self, block: BlockBase, convert_as_inline: bool) -> st @validate_call def convert_block(self, block: BlockBase, convert_as_inline: bool) -> str: - type_ = block.type convert_fn = getattr(self, f"convert_{type_}_block", None) diff --git a/jsondoc/convert/utils.py b/jsondoc/convert/utils.py index 811efac..f65d493 100644 --- a/jsondoc/convert/utils.py +++ b/jsondoc/convert/utils.py @@ -1,6 +1,6 @@ import logging -from datetime import datetime, timezone import re +from datetime import datetime, timezone from typing import List, Literal, Optional, Type from bs4 import Tag @@ -109,7 +109,6 @@ def create_rich_text( color: str | None = None, annotations: Annotations | None = None, ) -> RichTextText | RichTextEquation: - if text is not None and equation is not None: raise ValueError("Only one of text or equation must be provided") diff --git a/jsondoc/models/block/__init__.py b/jsondoc/models/block/__init__.py index 348ceeb..8615cda 100644 --- a/jsondoc/models/block/__init__.py +++ b/jsondoc/models/block/__init__.py @@ -10,24 +10,24 @@ class Type(Enum): - paragraph = 'paragraph' - to_do = 'to_do' - bulleted_list_item = 'bulleted_list_item' - numbered_list_item = 'numbered_list_item' - code = 'code' - column = 'column' - column_list = 'column_list' - divider = 'divider' - equation = 'equation' - heading_1 = 'heading_1' - heading_2 = 'heading_2' - heading_3 = 'heading_3' - image = 'image' - quote = 'quote' - equation_1 = 'equation' - table = 'table' - table_row = 'table_row' - toggle = 'toggle' + paragraph = "paragraph" + to_do = "to_do" + bulleted_list_item = "bulleted_list_item" + numbered_list_item = "numbered_list_item" + code = "code" + column = "column" + column_list = "column_list" + divider = "divider" + equation = "equation" + heading_1 = "heading_1" + heading_2 = "heading_2" + heading_3 = "heading_3" + image = "image" + quote = "quote" + equation_1 = "equation" + table = "table" + table_row = "table_row" + toggle = "toggle" class Block(BlockBase): diff --git a/jsondoc/models/block/base/__init__.py b/jsondoc/models/block/base/__init__.py index e1edd7e..ba76dd0 100644 --- a/jsondoc/models/block/base/__init__.py +++ b/jsondoc/models/block/base/__init__.py @@ -12,7 +12,7 @@ class Parent(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", ) type: str block_id: Optional[str] = None @@ -21,22 +21,22 @@ class Parent(BaseModel): class CreatedBy(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", ) - object: Literal['user'] + object: Literal["user"] id: str class LastEditedBy(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", ) - object: Literal['user'] + object: Literal["user"] id: str class BlockBase(BaseModel): - object: Literal['block'] = 'block' + object: Literal["block"] = "block" id: str parent: Optional[Parent] = None type: str diff --git a/jsondoc/models/block/types/bulleted_list_item/__init__.py b/jsondoc/models/block/types/bulleted_list_item/__init__.py index df5e9e1..fd745fe 100644 --- a/jsondoc/models/block/types/bulleted_list_item/__init__.py +++ b/jsondoc/models/block/types/bulleted_list_item/__init__.py @@ -6,16 +6,17 @@ from typing import List, Optional +from pydantic import BaseModel, ConfigDict +from typing_extensions import Literal + from jsondoc.models.block.base import BlockBase from jsondoc.models.block.types.rich_text.base import RichTextBase from jsondoc.models.shared_definitions import Color -from pydantic import BaseModel, ConfigDict -from typing_extensions import Literal class BulletedListItem(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", arbitrary_types_allowed=True, ) rich_text: Optional[List[RichTextBase]] = [] @@ -26,6 +27,6 @@ class BulletedListItemBlock(BlockBase): model_config = ConfigDict( arbitrary_types_allowed=True, ) - type: Literal['bulleted_list_item'] = 'bulleted_list_item' + type: Literal["bulleted_list_item"] = "bulleted_list_item" bulleted_list_item: BulletedListItem children: Optional[List[BlockBase]] = None diff --git a/jsondoc/models/block/types/code/__init__.py b/jsondoc/models/block/types/code/__init__.py index b8dcfb7..9902f2e 100644 --- a/jsondoc/models/block/types/code/__init__.py +++ b/jsondoc/models/block/types/code/__init__.py @@ -7,90 +7,91 @@ from enum import Enum from typing import List, Optional -from jsondoc.models.block.base import BlockBase -from jsondoc.models.block.types.rich_text.base import RichTextBase from pydantic import BaseModel, ConfigDict from typing_extensions import Literal +from jsondoc.models.block.base import BlockBase +from jsondoc.models.block.types.rich_text.base import RichTextBase + class Language(Enum): - abap = 'abap' - arduino = 'arduino' - bash = 'bash' - basic = 'basic' - c = 'c' - clojure = 'clojure' - coffeescript = 'coffeescript' - c__ = 'c++' - c_ = 'c#' - css = 'css' - dart = 'dart' - diff = 'diff' - docker = 'docker' - elixir = 'elixir' - elm = 'elm' - erlang = 'erlang' - flow = 'flow' - fortran = 'fortran' - f_ = 'f#' - gherkin = 'gherkin' - glsl = 'glsl' - go = 'go' - graphql = 'graphql' - groovy = 'groovy' - haskell = 'haskell' - html = 'html' - java = 'java' - javascript = 'javascript' - json = 'json' - julia = 'julia' - kotlin = 'kotlin' - latex = 'latex' - less = 'less' - lisp = 'lisp' - livescript = 'livescript' - lua = 'lua' - makefile = 'makefile' - markdown = 'markdown' - markup = 'markup' - matlab = 'matlab' - mermaid = 'mermaid' - nix = 'nix' - objective_c = 'objective-c' - ocaml = 'ocaml' - pascal = 'pascal' - perl = 'perl' - php = 'php' - plain_text = 'plain text' - powershell = 'powershell' - prolog = 'prolog' - protobuf = 'protobuf' - python = 'python' - r = 'r' - reason = 'reason' - ruby = 'ruby' - rust = 'rust' - sass = 'sass' - scala = 'scala' - scheme = 'scheme' - scss = 'scss' - shell = 'shell' - sql = 'sql' - swift = 'swift' - typescript = 'typescript' - vb_net = 'vb.net' - verilog = 'verilog' - vhdl = 'vhdl' - visual_basic = 'visual basic' - webassembly = 'webassembly' - xml = 'xml' - yaml = 'yaml' - java_c_c___c_ = 'java/c/c++/c#' + abap = "abap" + arduino = "arduino" + bash = "bash" + basic = "basic" + c = "c" + clojure = "clojure" + coffeescript = "coffeescript" + c__ = "c++" + c_ = "c#" + css = "css" + dart = "dart" + diff = "diff" + docker = "docker" + elixir = "elixir" + elm = "elm" + erlang = "erlang" + flow = "flow" + fortran = "fortran" + f_ = "f#" + gherkin = "gherkin" + glsl = "glsl" + go = "go" + graphql = "graphql" + groovy = "groovy" + haskell = "haskell" + html = "html" + java = "java" + javascript = "javascript" + json = "json" + julia = "julia" + kotlin = "kotlin" + latex = "latex" + less = "less" + lisp = "lisp" + livescript = "livescript" + lua = "lua" + makefile = "makefile" + markdown = "markdown" + markup = "markup" + matlab = "matlab" + mermaid = "mermaid" + nix = "nix" + objective_c = "objective-c" + ocaml = "ocaml" + pascal = "pascal" + perl = "perl" + php = "php" + plain_text = "plain text" + powershell = "powershell" + prolog = "prolog" + protobuf = "protobuf" + python = "python" + r = "r" + reason = "reason" + ruby = "ruby" + rust = "rust" + sass = "sass" + scala = "scala" + scheme = "scheme" + scss = "scss" + shell = "shell" + sql = "sql" + swift = "swift" + typescript = "typescript" + vb_net = "vb.net" + verilog = "verilog" + vhdl = "vhdl" + visual_basic = "visual basic" + webassembly = "webassembly" + xml = "xml" + yaml = "yaml" + java_c_c___c_ = "java/c/c++/c#" class Code(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", arbitrary_types_allowed=True, ) caption: Optional[List[RichTextBase]] = None @@ -99,5 +100,5 @@ class Code(BaseModel): class CodeBlock(BlockBase): - type: Literal['code'] = 'code' + type: Literal["code"] = "code" code: Code diff --git a/jsondoc/models/block/types/column/__init__.py b/jsondoc/models/block/types/column/__init__.py index 90cbb06..3ac30b8 100644 --- a/jsondoc/models/block/types/column/__init__.py +++ b/jsondoc/models/block/types/column/__init__.py @@ -6,15 +6,16 @@ from typing import Any, Dict, List, Optional -from jsondoc.models.block.base import BlockBase from pydantic import ConfigDict from typing_extensions import Literal +from jsondoc.models.block.base import BlockBase + class ColumnBlock(BlockBase): model_config = ConfigDict( arbitrary_types_allowed=True, ) - type: Literal['column'] = 'column' + type: Literal["column"] = "column" column: Dict[str, Any] children: Optional[List[BlockBase]] = None diff --git a/jsondoc/models/block/types/column_list/__init__.py b/jsondoc/models/block/types/column_list/__init__.py index cc39ad1..ce18eb0 100644 --- a/jsondoc/models/block/types/column_list/__init__.py +++ b/jsondoc/models/block/types/column_list/__init__.py @@ -6,16 +6,17 @@ from typing import Any, Dict, List, Optional -from jsondoc.models.block.base import BlockBase -from jsondoc.models.block.types.column import ColumnBlock from pydantic import ConfigDict from typing_extensions import Literal +from jsondoc.models.block.base import BlockBase +from jsondoc.models.block.types.column import ColumnBlock + class ColumnListBlock(BlockBase): model_config = ConfigDict( arbitrary_types_allowed=True, ) - type: Literal['column_list'] = 'column_list' + type: Literal["column_list"] = "column_list" column_list: Dict[str, Any] children: Optional[List[ColumnBlock]] = None diff --git a/jsondoc/models/block/types/divider/__init__.py b/jsondoc/models/block/types/divider/__init__.py index 124b323..70d1d79 100644 --- a/jsondoc/models/block/types/divider/__init__.py +++ b/jsondoc/models/block/types/divider/__init__.py @@ -6,10 +6,11 @@ from typing import Any, Dict -from jsondoc.models.block.base import BlockBase from typing_extensions import Literal +from jsondoc.models.block.base import BlockBase + class DividerBlock(BlockBase): - type: Literal['divider'] = 'divider' + type: Literal["divider"] = "divider" divider: Dict[str, Any] diff --git a/jsondoc/models/block/types/equation/__init__.py b/jsondoc/models/block/types/equation/__init__.py index 1479963..b37efa1 100644 --- a/jsondoc/models/block/types/equation/__init__.py +++ b/jsondoc/models/block/types/equation/__init__.py @@ -4,18 +4,19 @@ from __future__ import annotations -from jsondoc.models.block.base import BlockBase from pydantic import BaseModel, ConfigDict from typing_extensions import Literal +from jsondoc.models.block.base import BlockBase + class Equation(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", ) expression: str class EquationBlock(BlockBase): - type: Literal['equation'] = 'equation' + type: Literal["equation"] = "equation" equation: Equation diff --git a/jsondoc/models/block/types/heading_1/__init__.py b/jsondoc/models/block/types/heading_1/__init__.py index 10fb530..f72d33f 100644 --- a/jsondoc/models/block/types/heading_1/__init__.py +++ b/jsondoc/models/block/types/heading_1/__init__.py @@ -6,16 +6,17 @@ from typing import List, Optional +from pydantic import BaseModel, ConfigDict +from typing_extensions import Literal + from jsondoc.models.block.base import BlockBase from jsondoc.models.block.types.rich_text.base import RichTextBase from jsondoc.models.shared_definitions import Color -from pydantic import BaseModel, ConfigDict -from typing_extensions import Literal class Heading1(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", arbitrary_types_allowed=True, ) rich_text: Optional[List[RichTextBase]] = [] @@ -24,5 +25,5 @@ class Heading1(BaseModel): class Heading1Block(BlockBase): - type: Literal['heading_1'] = 'heading_1' + type: Literal["heading_1"] = "heading_1" heading_1: Heading1 diff --git a/jsondoc/models/block/types/heading_2/__init__.py b/jsondoc/models/block/types/heading_2/__init__.py index dcdf449..136ee3b 100644 --- a/jsondoc/models/block/types/heading_2/__init__.py +++ b/jsondoc/models/block/types/heading_2/__init__.py @@ -6,11 +6,12 @@ from typing import List, Optional +from pydantic import BaseModel, ConfigDict +from typing_extensions import Literal + from jsondoc.models.block.base import BlockBase from jsondoc.models.block.types.rich_text.base import RichTextBase from jsondoc.models.shared_definitions import Color -from pydantic import BaseModel, ConfigDict -from typing_extensions import Literal class Heading2(BaseModel): @@ -23,5 +24,5 @@ class Heading2(BaseModel): class Heading2Block(BlockBase): - type: Literal['heading_2'] = 'heading_2' + type: Literal["heading_2"] = "heading_2" heading_2: Heading2 diff --git a/jsondoc/models/block/types/heading_3/__init__.py b/jsondoc/models/block/types/heading_3/__init__.py index f585a1b..831545e 100644 --- a/jsondoc/models/block/types/heading_3/__init__.py +++ b/jsondoc/models/block/types/heading_3/__init__.py @@ -6,11 +6,12 @@ from typing import List, Optional +from pydantic import BaseModel, ConfigDict +from typing_extensions import Literal + from jsondoc.models.block.base import BlockBase from jsondoc.models.block.types.rich_text.base import RichTextBase from jsondoc.models.shared_definitions import Color -from pydantic import BaseModel, ConfigDict -from typing_extensions import Literal class Heading3(BaseModel): @@ -23,5 +24,5 @@ class Heading3(BaseModel): class Heading3Block(BlockBase): - type: Literal['heading_3'] = 'heading_3' + type: Literal["heading_3"] = "heading_3" heading_3: Heading3 diff --git a/jsondoc/models/block/types/image/__init__.py b/jsondoc/models/block/types/image/__init__.py index d02a033..ad34b90 100644 --- a/jsondoc/models/block/types/image/__init__.py +++ b/jsondoc/models/block/types/image/__init__.py @@ -4,15 +4,16 @@ from __future__ import annotations -from jsondoc.models.block.base import BlockBase -from jsondoc.models.file.base import FileBase from pydantic import ConfigDict from typing_extensions import Literal +from jsondoc.models.block.base import BlockBase +from jsondoc.models.file.base import FileBase + class ImageBlock(BlockBase): model_config = ConfigDict( arbitrary_types_allowed=True, ) - type: Literal['image'] = 'image' + type: Literal["image"] = "image" image: FileBase diff --git a/jsondoc/models/block/types/numbered_list_item/__init__.py b/jsondoc/models/block/types/numbered_list_item/__init__.py index 8da38c5..ec5596a 100644 --- a/jsondoc/models/block/types/numbered_list_item/__init__.py +++ b/jsondoc/models/block/types/numbered_list_item/__init__.py @@ -6,16 +6,17 @@ from typing import List, Optional +from pydantic import BaseModel, ConfigDict +from typing_extensions import Literal + from jsondoc.models.block.base import BlockBase from jsondoc.models.block.types.rich_text.base import RichTextBase from jsondoc.models.shared_definitions import Color -from pydantic import BaseModel, ConfigDict -from typing_extensions import Literal class NumberedListItem(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", arbitrary_types_allowed=True, ) rich_text: Optional[List[RichTextBase]] = [] @@ -26,6 +27,6 @@ class NumberedListItemBlock(BlockBase): model_config = ConfigDict( arbitrary_types_allowed=True, ) - type: Literal['numbered_list_item'] = 'numbered_list_item' + type: Literal["numbered_list_item"] = "numbered_list_item" numbered_list_item: NumberedListItem children: Optional[List[BlockBase]] = None diff --git a/jsondoc/models/block/types/paragraph/__init__.py b/jsondoc/models/block/types/paragraph/__init__.py index 1954135..792de39 100644 --- a/jsondoc/models/block/types/paragraph/__init__.py +++ b/jsondoc/models/block/types/paragraph/__init__.py @@ -6,16 +6,17 @@ from typing import List, Optional +from pydantic import BaseModel, ConfigDict +from typing_extensions import Literal + from jsondoc.models.block.base import BlockBase from jsondoc.models.block.types.rich_text.base import RichTextBase from jsondoc.models.shared_definitions import Color -from pydantic import BaseModel, ConfigDict -from typing_extensions import Literal class Paragraph(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", arbitrary_types_allowed=True, ) rich_text: Optional[List[RichTextBase]] = [] @@ -26,6 +27,6 @@ class ParagraphBlock(BlockBase): model_config = ConfigDict( arbitrary_types_allowed=True, ) - type: Literal['paragraph'] = 'paragraph' + type: Literal["paragraph"] = "paragraph" paragraph: Paragraph children: Optional[List[BlockBase]] = None diff --git a/jsondoc/models/block/types/quote/__init__.py b/jsondoc/models/block/types/quote/__init__.py index cf1801a..bae1ed4 100644 --- a/jsondoc/models/block/types/quote/__init__.py +++ b/jsondoc/models/block/types/quote/__init__.py @@ -6,16 +6,17 @@ from typing import List, Optional +from pydantic import BaseModel, ConfigDict +from typing_extensions import Literal + from jsondoc.models.block.base import BlockBase from jsondoc.models.block.types.rich_text.base import RichTextBase from jsondoc.models.shared_definitions import Color -from pydantic import BaseModel, ConfigDict -from typing_extensions import Literal class Quote(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", arbitrary_types_allowed=True, ) rich_text: Optional[List[RichTextBase]] = [] @@ -26,6 +27,6 @@ class QuoteBlock(BlockBase): model_config = ConfigDict( arbitrary_types_allowed=True, ) - type: Literal['quote'] = 'quote' + type: Literal["quote"] = "quote" quote: Quote children: Optional[List[BlockBase]] = None diff --git a/jsondoc/models/block/types/rich_text/__init__.py b/jsondoc/models/block/types/rich_text/__init__.py index f6a71ac..25708c4 100644 --- a/jsondoc/models/block/types/rich_text/__init__.py +++ b/jsondoc/models/block/types/rich_text/__init__.py @@ -10,8 +10,8 @@ class Type(Enum): - text = 'text' - equation = 'equation' + text = "text" + equation = "equation" class Model(BaseModel): diff --git a/jsondoc/models/block/types/rich_text/equation/__init__.py b/jsondoc/models/block/types/rich_text/equation/__init__.py index f454aed..e9d048e 100644 --- a/jsondoc/models/block/types/rich_text/equation/__init__.py +++ b/jsondoc/models/block/types/rich_text/equation/__init__.py @@ -6,15 +6,16 @@ from typing import Optional -from jsondoc.models.block.types.rich_text.base import RichTextBase -from jsondoc.models.shared_definitions import Annotations from pydantic import BaseModel, ConfigDict from typing_extensions import Literal +from jsondoc.models.block.types.rich_text.base import RichTextBase +from jsondoc.models.shared_definitions import Annotations + class Equation(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", ) expression: str @@ -23,7 +24,7 @@ class RichTextEquation(RichTextBase): model_config = ConfigDict( arbitrary_types_allowed=True, ) - type: Literal['equation'] = 'equation' + type: Literal["equation"] = "equation" equation: Equation annotations: Annotations plain_text: str diff --git a/jsondoc/models/block/types/rich_text/text/__init__.py b/jsondoc/models/block/types/rich_text/text/__init__.py index 4290492..4037dd3 100644 --- a/jsondoc/models/block/types/rich_text/text/__init__.py +++ b/jsondoc/models/block/types/rich_text/text/__init__.py @@ -6,11 +6,12 @@ from typing import Optional -from jsondoc.models.block.types.rich_text.base import RichTextBase -from jsondoc.models.shared_definitions import Annotations from pydantic import BaseModel, ConfigDict from typing_extensions import Literal +from jsondoc.models.block.types.rich_text.base import RichTextBase +from jsondoc.models.shared_definitions import Annotations + class Link(BaseModel): url: str @@ -25,7 +26,7 @@ class RichTextText(RichTextBase): model_config = ConfigDict( arbitrary_types_allowed=True, ) - type: Literal['text'] = 'text' + type: Literal["text"] = "text" text: Text annotations: Annotations plain_text: str diff --git a/jsondoc/models/block/types/table/__init__.py b/jsondoc/models/block/types/table/__init__.py index 9b59aa9..d1051a6 100644 --- a/jsondoc/models/block/types/table/__init__.py +++ b/jsondoc/models/block/types/table/__init__.py @@ -6,15 +6,16 @@ from typing import List, Optional -from jsondoc.models.block.base import BlockBase -from jsondoc.models.block.types.table_row import TableRowBlock from pydantic import BaseModel, ConfigDict from typing_extensions import Literal +from jsondoc.models.block.base import BlockBase +from jsondoc.models.block.types.table_row import TableRowBlock + class Table(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", ) table_width: Optional[int] = None has_column_header: bool @@ -25,6 +26,6 @@ class TableBlock(BlockBase): model_config = ConfigDict( arbitrary_types_allowed=True, ) - type: Literal['table'] = 'table' + type: Literal["table"] = "table" table: Table children: Optional[List[TableRowBlock]] = None diff --git a/jsondoc/models/block/types/table_row/__init__.py b/jsondoc/models/block/types/table_row/__init__.py index bbded9f..eb6c31c 100644 --- a/jsondoc/models/block/types/table_row/__init__.py +++ b/jsondoc/models/block/types/table_row/__init__.py @@ -6,20 +6,21 @@ from typing import List -from jsondoc.models.block.base import BlockBase -from jsondoc.models.block.types.rich_text.base import RichTextBase from pydantic import BaseModel, ConfigDict from typing_extensions import Literal +from jsondoc.models.block.base import BlockBase +from jsondoc.models.block.types.rich_text.base import RichTextBase + class TableRow(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", arbitrary_types_allowed=True, ) cells: List[List[RichTextBase]] class TableRowBlock(BlockBase): - type: Literal['table_row'] = 'table_row' + type: Literal["table_row"] = "table_row" table_row: TableRow diff --git a/jsondoc/models/block/types/to_do/__init__.py b/jsondoc/models/block/types/to_do/__init__.py index 14441bf..9066133 100644 --- a/jsondoc/models/block/types/to_do/__init__.py +++ b/jsondoc/models/block/types/to_do/__init__.py @@ -6,16 +6,17 @@ from typing import List, Optional +from pydantic import BaseModel, ConfigDict +from typing_extensions import Literal + from jsondoc.models.block.base import BlockBase from jsondoc.models.block.types.rich_text.base import RichTextBase from jsondoc.models.shared_definitions import Color -from pydantic import BaseModel, ConfigDict -from typing_extensions import Literal class ToDo(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", arbitrary_types_allowed=True, ) rich_text: Optional[List[RichTextBase]] = [] @@ -27,6 +28,6 @@ class ToDoBlock(BlockBase): model_config = ConfigDict( arbitrary_types_allowed=True, ) - type: Literal['to_do'] = 'to_do' + type: Literal["to_do"] = "to_do" to_do: ToDo children: Optional[List[BlockBase]] = None diff --git a/jsondoc/models/block/types/toggle/__init__.py b/jsondoc/models/block/types/toggle/__init__.py index 6eeda70..ddfd017 100644 --- a/jsondoc/models/block/types/toggle/__init__.py +++ b/jsondoc/models/block/types/toggle/__init__.py @@ -6,11 +6,12 @@ from typing import List, Optional +from pydantic import BaseModel, ConfigDict +from typing_extensions import Literal + from jsondoc.models.block.base import BlockBase from jsondoc.models.block.types.rich_text.base import RichTextBase from jsondoc.models.shared_definitions import Color -from pydantic import BaseModel, ConfigDict -from typing_extensions import Literal class Toggle(BaseModel): @@ -25,6 +26,6 @@ class ToggleBlock(BlockBase): model_config = ConfigDict( arbitrary_types_allowed=True, ) - type: Literal['toggle'] = 'toggle' + type: Literal["toggle"] = "toggle" toggle: Toggle children: Optional[List[BlockBase]] = None diff --git a/jsondoc/models/file/__init__.py b/jsondoc/models/file/__init__.py index d485070..deea731 100644 --- a/jsondoc/models/file/__init__.py +++ b/jsondoc/models/file/__init__.py @@ -10,8 +10,8 @@ class Type(Enum): - external = 'external' - file = 'file' + external = "external" + file = "file" class Model(BaseModel): diff --git a/jsondoc/models/file/external/__init__.py b/jsondoc/models/file/external/__init__.py index bf00a91..b558b05 100644 --- a/jsondoc/models/file/external/__init__.py +++ b/jsondoc/models/file/external/__init__.py @@ -4,15 +4,16 @@ from __future__ import annotations -from jsondoc.models.file.base import FileBase from pydantic import BaseModel from typing_extensions import Literal +from jsondoc.models.file.base import FileBase + class External(BaseModel): url: str class FileExternal(FileBase): - type: Literal['external'] = 'external' + type: Literal["external"] = "external" external: External diff --git a/jsondoc/models/file/file/__init__.py b/jsondoc/models/file/file/__init__.py index 410b2f7..948c6a3 100644 --- a/jsondoc/models/file/file/__init__.py +++ b/jsondoc/models/file/file/__init__.py @@ -6,10 +6,11 @@ from typing import Optional -from jsondoc.models.file.base import FileBase from pydantic import AwareDatetime, BaseModel from typing_extensions import Literal +from jsondoc.models.file.base import FileBase + class File(BaseModel): url: str @@ -17,5 +18,5 @@ class File(BaseModel): class FileFile(FileBase): - type: Literal['file'] = 'file' + type: Literal["file"] = "file" file: File diff --git a/jsondoc/models/page/__init__.py b/jsondoc/models/page/__init__.py index ffb67fa..164155c 100644 --- a/jsondoc/models/page/__init__.py +++ b/jsondoc/models/page/__init__.py @@ -7,15 +7,16 @@ from enum import Enum from typing import List, Optional -from jsondoc.models.block.base import BlockBase -from jsondoc.models.block.types.rich_text.text import RichTextText from pydantic import AwareDatetime, BaseModel, ConfigDict from typing_extensions import Literal +from jsondoc.models.block.base import BlockBase +from jsondoc.models.block.types.rich_text.text import RichTextText + class Parent(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", ) type: str page_id: Optional[str] = None @@ -23,27 +24,27 @@ class Parent(BaseModel): class CreatedBy(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", ) - object: Literal['user'] = 'user' + object: Literal["user"] = "user" id: str class LastEditedBy(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", ) - object: Literal['user'] = 'user' + object: Literal["user"] = "user" id: str class Type(Enum): - emoji = 'emoji' + emoji = "emoji" class Icon(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", ) type: Type emoji: str @@ -54,23 +55,23 @@ class Title(BaseModel): arbitrary_types_allowed=True, ) id: Optional[str] = None - type: Literal['title'] = 'title' + type: Literal["title"] = "title" title: Optional[List[RichTextText]] = None class Properties(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", ) title: Optional[Title] = None class Page(BaseModel): model_config = ConfigDict( - extra='forbid', + extra="forbid", arbitrary_types_allowed=True, ) - object: Literal['page'] = 'page' + object: Literal["page"] = "page" id: str parent: Optional[Parent] = None created_time: AwareDatetime diff --git a/jsondoc/models/shared_definitions/__init__.py b/jsondoc/models/shared_definitions/__init__.py index b952d34..25dcb91 100644 --- a/jsondoc/models/shared_definitions/__init__.py +++ b/jsondoc/models/shared_definitions/__init__.py @@ -15,25 +15,25 @@ class Model(RootModel[Any]): class Color(Enum): - blue = 'blue' - blue_background = 'blue_background' - brown = 'brown' - brown_background = 'brown_background' - default = 'default' - gray = 'gray' - gray_background = 'gray_background' - green = 'green' - green_background = 'green_background' - orange = 'orange' - orange_background = 'orange_background' - yellow = 'yellow' - pink = 'pink' - pink_background = 'pink_background' - purple = 'purple' - purple_background = 'purple_background' - red = 'red' - red_background = 'red_background' - yellow_background = 'yellow_background' + blue = "blue" + blue_background = "blue_background" + brown = "brown" + brown_background = "brown_background" + default = "default" + gray = "gray" + gray_background = "gray_background" + green = "green" + green_background = "green_background" + orange = "orange" + orange_background = "orange_background" + yellow = "yellow" + pink = "pink" + pink_background = "pink_background" + purple = "purple" + purple_background = "purple_background" + red = "red" + red_background = "red_background" + yellow_background = "yellow_background" class Annotations(BaseModel): diff --git a/jsondoc/serialize.py b/jsondoc/serialize.py index 5e85319..7c41fa3 100644 --- a/jsondoc/serialize.py +++ b/jsondoc/serialize.py @@ -25,11 +25,11 @@ from jsondoc.models.block.types.rich_text.base import RichTextBase from jsondoc.models.block.types.rich_text.equation import RichTextEquation from jsondoc.models.block.types.rich_text.text import RichTextText -from jsondoc.models.file import Type as FileType from jsondoc.models.block.types.table import TableBlock from jsondoc.models.block.types.table_row import TableRowBlock from jsondoc.models.block.types.to_do import ToDoBlock from jsondoc.models.block.types.toggle import ToggleBlock +from jsondoc.models.file import Type as FileType from jsondoc.models.file.base import FileBase from jsondoc.models.page import Page from jsondoc.utils import get_nested_value, set_nested_value @@ -244,7 +244,9 @@ def load_page(obj: Union[str, Dict[str, Any]]) -> Page: @validate_call -def load_jsondoc(obj: Union[str, Dict[str, Any], List[Dict[str, Any]]]) -> Page | BlockBase | List[BlockBase]: +def load_jsondoc( + obj: Union[str, Dict[str, Any], List[Dict[str, Any]]], +) -> Page | BlockBase | List[BlockBase]: if isinstance(obj, str): obj = json.loads(obj) diff --git a/jsondoc/transcribe/benchmark.py b/jsondoc/transcribe/benchmark.py index 9dc321c..0bfef2e 100644 --- a/jsondoc/transcribe/benchmark.py +++ b/jsondoc/transcribe/benchmark.py @@ -4,8 +4,8 @@ import PIL.Image from thefuzz import fuzz -from jsondoc.transcribe.fireworks import LLAVA_YI_34B from jsondoc.transcribe.anthropic_ import HAIKU +from jsondoc.transcribe.fireworks import LLAVA_YI_34B from jsondoc.transcribe.utils import ImageInfo, Transcriber, get_alphanumeric dotenv.load_dotenv(".env") @@ -48,7 +48,6 @@ def transcribe_resize( height=None, ground_truth=None, ): - # Get image information image = PIL.Image.open(path) if height is not None: @@ -112,4 +111,3 @@ def transcribe_resize( except ValueError: print(f"Skipping resolution {height}") print("====================================================") - diff --git a/tests/test_html_to_jsondoc.py b/tests/test_html_to_jsondoc.py index 2c63fcf..19c2e8d 100644 --- a/tests/test_html_to_jsondoc.py +++ b/tests/test_html_to_jsondoc.py @@ -61,9 +61,9 @@ def _process_example(json_path): jsondoc_target = data.get("jsondoc") assert html_source is not None, f"file {json_path} does not contain field 'html'" - assert ( - jsondoc_target is not None - ), f"file {json_path} does not contain field 'jsondoc'" + assert jsondoc_target is not None, ( + f"file {json_path} does not contain field 'jsondoc'" + ) ret = html_to_jsondoc(html_source) @@ -74,7 +74,6 @@ def _process_example(json_path): def test_examples(): - current_dir = Path(__file__).parent html_jsondoc_pairs_dir = current_dir / "html_jsondoc_pairs" From 976b292de7ac5121f684dadaf6b6bfba34d6d503 Mon Sep 17 00:00:00 2001 From: Onur Solmaz <2453968+osolmaz@users.noreply.github.com> Date: Tue, 11 Mar 2025 18:46:18 +0100 Subject: [PATCH 3/4] Checkpoint --- jsondoc/models/block/types/image/external_image/__init__.py | 3 ++- jsondoc/models/block/types/image/file_image/__init__.py | 3 ++- jsondoc/transcribe/fireworks.py | 5 +++-- jsondoc/transcribe/utils.py | 1 + jsondoc/utils.py | 4 ++-- misc/hash_demo.py | 2 +- misc/test_notion_api.py | 3 ++- misc/test_notion_api2.py | 3 ++- tests/test_serialization.py | 1 + 9 files changed, 16 insertions(+), 9 deletions(-) diff --git a/jsondoc/models/block/types/image/external_image/__init__.py b/jsondoc/models/block/types/image/external_image/__init__.py index bf9761e..4728384 100644 --- a/jsondoc/models/block/types/image/external_image/__init__.py +++ b/jsondoc/models/block/types/image/external_image/__init__.py @@ -6,9 +6,10 @@ from typing import List, Optional +from pydantic import ConfigDict + from jsondoc.models.block.types.rich_text.base import RichTextBase from jsondoc.models.file.external import FileExternal -from pydantic import ConfigDict class ExternalImage(FileExternal): diff --git a/jsondoc/models/block/types/image/file_image/__init__.py b/jsondoc/models/block/types/image/file_image/__init__.py index 19e0f35..586a4de 100644 --- a/jsondoc/models/block/types/image/file_image/__init__.py +++ b/jsondoc/models/block/types/image/file_image/__init__.py @@ -6,9 +6,10 @@ from typing import List, Optional +from pydantic import ConfigDict + from jsondoc.models.block.types.rich_text.base import RichTextBase from jsondoc.models.file.file import FileFile -from pydantic import ConfigDict class FileImage(FileFile): diff --git a/jsondoc/transcribe/fireworks.py b/jsondoc/transcribe/fireworks.py index 86e8841..d8f43c6 100644 --- a/jsondoc/transcribe/fireworks.py +++ b/jsondoc/transcribe/fireworks.py @@ -1,8 +1,9 @@ import base64 -import os -import requests import json +import os + import dotenv +import requests from jsondoc.transcribe.utils import TokenPrice, Transcriber, Usage, per_mil_tok diff --git a/jsondoc/transcribe/utils.py b/jsondoc/transcribe/utils.py index 1d785d6..a4e6113 100644 --- a/jsondoc/transcribe/utils.py +++ b/jsondoc/transcribe/utils.py @@ -1,5 +1,6 @@ from decimal import Decimal from typing import Tuple + from pydantic import BaseModel diff --git a/jsondoc/utils.py b/jsondoc/utils.py index 4bc1fae..ffaa1a9 100644 --- a/jsondoc/utils.py +++ b/jsondoc/utils.py @@ -1,10 +1,10 @@ -from datetime import datetime, timezone import difflib import json import logging import time -from contextlib import contextmanager import uuid +from contextlib import contextmanager +from datetime import datetime, timezone ARBITRARY_JSON_SCHEMA_OBJECT = { "type": "object", diff --git a/misc/hash_demo.py b/misc/hash_demo.py index ca531ae..2bc0dde 100644 --- a/misc/hash_demo.py +++ b/misc/hash_demo.py @@ -1,5 +1,5 @@ -import json import hashlib +import json def hash_json_object(json_obj): diff --git a/misc/test_notion_api.py b/misc/test_notion_api.py index 5582987..5456a69 100644 --- a/misc/test_notion_api.py +++ b/misc/test_notion_api.py @@ -1,6 +1,7 @@ import os -import requests + import dotenv +import requests dotenv.load_dotenv(".env") diff --git a/misc/test_notion_api2.py b/misc/test_notion_api2.py index aa0a863..7142c76 100644 --- a/misc/test_notion_api2.py +++ b/misc/test_notion_api2.py @@ -1,6 +1,7 @@ import os -import requests + import dotenv +import requests dotenv.load_dotenv(".env") diff --git a/tests/test_serialization.py b/tests/test_serialization.py index 874f519..57848a6 100644 --- a/tests/test_serialization.py +++ b/tests/test_serialization.py @@ -1,6 +1,7 @@ import difflib import json import time + from jsondoc.serialize import load_page from jsondoc.utils import diff_strings, load_json_file, timer From b9abd556dd6f705d3226035a2571da31f15203e1 Mon Sep 17 00:00:00 2001 From: Onur Solmaz <2453968+osolmaz@users.noreply.github.com> Date: Tue, 11 Mar 2025 18:47:09 +0100 Subject: [PATCH 4/4] Checkpoint --- .flake8 | 128 -------------------------------------------------------- 1 file changed, 128 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 93a3715..0000000 --- a/.flake8 +++ /dev/null @@ -1,128 +0,0 @@ -[flake8] -max-line-length = 88 -max-complexity = 15 -extend-ignore = - # E101: Indentation contains mixed spaces and tabs - E101 - # E111: Indentation is not a multiple of four - E111 - # E112: Expected an indented block - E112 - # E113: Unexpected indentation - E113 - # E114: Indentation is not a multiple of four (comment) - E114 - # E115: Expected an indented block (comment) - E115 - # E116: Unexpected indentation (comment) - E116 - # E117: Over-indented - E117 - # E121: Continuation line under-indented for hanging indent - E121 - # E122: Continuation line missing indentation or outdented - E122 - # E123: Closing bracket does not match indentation of opening bracket's line - E123 - # E124: Closing bracket does not match visual indentation - E124 - # E125: Continuation line with same indent as next logical line - E125 - # E126: Continuation line over-indented for hanging indent - E126 - # E127: Continuation line over-indented for visual indent - E127 - # E128: Continuation line under-indented for visual indent - E128 - # E129: Visually indented line with same indent as next logical line - E129 - # E131: Continuation line unaligned for hanging indent - E131 - # E133: Closing bracket is missing indentation - E133 - # E201: Whitespace after '(' - E201, - # E202: Whitespace before ')' - E202, - # E203: Whitespace before ':' - E203, - # E211: Whitespace before '(' - E211, - # E221: Multiple spaces before operator - E221, - # E222: Multiple spaces after operator - E222, - # E223: Tab before operator - E223, - # E224: Tab after operator - E224, - # E225: Missing whitespace around operator - E225, - # E226: Missing whitespace around arithmetic operator - E226, - # E227: Missing whitespace around bitwise or shift operator - E227, - # E228: Missing whitespace around modulo operator - E228, - # E231: Missing whitespace after ',', ';', or ':' - E231, - # E241: Multiple spaces after ',' - E241, - # E242: Tab after ',' - E242, - # E251: Unexpected spaces around keyword / parameter equals - E251, - # E261: At least two spaces before inline comment - E261, - # E262: Inline comment should start with '# ' - E262, - # E265: Block comment should start with '# ' - E265, - # E266: Too many leading '#' for block comment - E266, - # E271: Multiple spaces after keyword - E271, - # E272: Multiple spaces before keyword - E272, - # E273: Tab after keyword - E273, - # E274: Tab before keyword - E274, - # E275: Missing whitespace after keyword - E275, - # E301: Expected 1 blank line, found 0 - E301, - # E302: Expected 2 blank lines, found 0 - E302, - # E303: Too many blank lines (3) - E303, - # E304: Blank lines found after function decorator - E304, - # E305: Expected 2 blank lines after end of function or class - E305, - # E306: Expected 1 blank line before a nested definition - E306, - # E401: Multiple imports on one line - E401, - # E704: multiple statements on one line (def) - E704, - # E203: whitespace before ':' - E203, - # W191: Indentation contains tabs - W191, - # W291: Trailing whitespace - W291, - # W292: No newline at end of file - W292, - # W293: Blank line contains whitespace - W293, - # W391: Blank line at end of file - W391, - # W503: line break before binary operator - W503, - # W504: line break after binary operator - W504, - # F401: imported but unused - F401, - # F841: local variable is assigned to but never used - F841