Skip to content

Commit

Permalink
relock, rebuild py schema (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
bollwyvl authored Dec 10, 2024
1 parent 17d1fe3 commit cb1a56f
Show file tree
Hide file tree
Showing 7 changed files with 1,498 additions and 594 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

- [#27]
- fixes errant `idPrefix` relying on a hard-coded form key
- update form schema to accept a local file for `forms.*.props`
- updates form schema to accept a local file for `forms.*.props`
- adds in-development builds with `rattler-build`, published on ReadTheDocs
- adds `schema_errors` nunjucks filter
- adopts `@segment/ajv-human-errors` for more humane schema error messages
Expand Down
2,010 changes: 1,455 additions & 555 deletions pixi.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ platforms = ["linux-64", "osx-64", "osx-arm64", "win-64"]

all = {description = """
run ALL tasks that would lead to a release""", depends-on = [
"schema",
"fix",
"lint",
"build",
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ addopts = ["--color=yes", "-Werror", "--tb=long", "-vv"]

# robocop ######################################################################
[tool.robocop]
exclude = ["replace-set-variable-with-var", "replace-create-with-var"]
exclude = [
"replace-set-variable-with-var",
"replace-create-with-var",
"no-suite-variable",
]
configure = [
"too-many-calls-in-keyword:max_calls:20",
]
Expand Down
15 changes: 7 additions & 8 deletions scripts/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ def json_to_ts(in_path: Path, out_path: Path) -> int:
])


TYPING_HEADER = (
"from typing import Any, Dict, List, Literal, Required, TypeAlias, TypedDict, Union"
)
SCHEMA_PY_PREAMBLE = f'''
RAW_TYPING_HEADER = """from typing_extensions import Required"""

SCHEMA_PY_PREAMBLE = '''
"""Generated schema for ``urljsf``"""
# Copyright (C) urljsf contributors.
# Distributed under the terms of the Modified BSD License.
Expand All @@ -110,9 +109,9 @@ def json_to_ts(in_path: Path, out_path: Path) -> int:
import sys
if sys.version_info >= (3, 11): # pragma: no cover
{TYPING_HEADER}
from typing import Any, Literal, TypeAlias, TypedDict, Union, Required
else: # pragma: no cover
{TYPING_HEADER.replace(", Required,", ",").replace(", TypeAlias,", ",")}
from typing import Any, Literal, TypedDict, Union
from typing_extensions import Required, TypeAlias
'''

Expand All @@ -124,14 +123,14 @@ def json_to_py(in_path: Path, out_path: Path) -> int:
"""
args = [
"jsonschema-gentypes",
"--python-version=3.11",
"--python-version=3.9",
f"--json-schema={in_path}",
f"--python={out_path}",
]

def _fix() -> int:
"""Fix python output."""
raw = out_path.read_text(**UTF8).replace(TYPING_HEADER, "")
raw = out_path.read_text(**UTF8).split(RAW_TYPING_HEADER)[1]
raw = f"{SCHEMA_PY_PREAMBLE}{raw}"
out_path.write_text(raw, **UTF8)
return 0
Expand Down
46 changes: 23 additions & 23 deletions src/urljsf/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import sys

if sys.version_info >= (3, 11): # pragma: no cover
from typing import Any, Dict, List, Literal, Required, TypeAlias, TypedDict, Union
from typing import Any, Literal, Required, TypeAlias, TypedDict, Union
else: # pragma: no cover
from typing import Any, Dict, List, Literal, TypedDict, Union
from typing import Any, Literal, TypedDict, Union

from typing_extensions import Required, TypeAlias

Expand All @@ -25,7 +25,7 @@
"""


AnInlineObject = Dict[str, Any]
AnInlineObject = dict[str, Any]
"""
An Inline Object.
Expand Down Expand Up @@ -167,7 +167,7 @@ class AnyForm(TypedDict, total=False):
"""


_AnyStyle = Union[str, Dict[str, Any]]
_AnyStyle = Union[str, dict[str, Any]]
"""
A CSS rule, or a nested selector object containing more rules
Expand All @@ -183,7 +183,7 @@ class AnyForm(TypedDict, total=False):
""" a `nunjucks` template as a simple string """


_AnyTemplateAnyof1 = List[str]
_AnyTemplateAnyof1 = list[str]
"""
a template as a list of strings that will be concatenated before being rendered
Expand All @@ -192,14 +192,14 @@ class AnyForm(TypedDict, total=False):
"""


_Checks = Dict[str, "_AnyTemplate"]
_Checks = dict[str, "_AnyTemplate"]
"""
`nunjucks` templates keyed by the label displayed to a form user: any evaluating
to a non-whitespace string will be considered _failing_.
"""


_Forms = Dict[str, "AnyForm"]
_Forms = dict[str, "AnyForm"]
""" forms used to build and populate a URL """


Expand Down Expand Up @@ -237,10 +237,10 @@ class _Props(TypedDict, total=False):
focusOnFirstError: bool
""" If set to true, then the first field with an error will receive the focus when the form is submitted with errors """

formContext: Dict[str, Any]
formContext: dict[str, Any]
""" globals for custom UI """

formData: Dict[str, Any]
formData: dict[str, Any]
""" The data for the form, used to prefill a form with existing data """

id: str
Expand Down Expand Up @@ -273,7 +273,7 @@ class _Props(TypedDict, total=False):
readonly: bool
""" It's possible to make the whole form read-only by setting the `readonly` prop. The `readonly` prop is then forwarded down to each field of the form. If you just want to make some fields read-only, see the `ui:readonly` parameter in `uiSchema` """

schema: Dict[str, Any]
schema: dict[str, Any]
""" The JSON schema object for the form """

showErrorList: _PropsShowerrorlist
Expand Down Expand Up @@ -303,11 +303,11 @@ class _Props(TypedDict, total=False):
"""The values for the 'When this prop is set to `top` or 'bottom', a list of errors (or the custom error list defined in the `ErrorList`) will also show. When set to false, only inline input validation errors will be shown. Set to `top` by default' enum"""


_Styles = Dict[str, "_AnyStyle"]
_Styles = dict[str, "_AnyStyle"]
""" CSS rules, or nested selector objects containing more rules """


_Templates = Union[Dict[str, "_AnyTemplate"], "_TemplatesTyped"]
_Templates = Union[dict[str, "_AnyTemplate"], "_TemplatesTyped"]
"""
[nunjucks](https://mozilla.github.io/nunjucks/templating.html) strings
(or lists of strings) that control how strings are built from forms.
Expand Down Expand Up @@ -337,7 +337,7 @@ class _TemplatesTyped(TypedDict, total=False):
""" Default value of the field path 'urljsf no_bootstrap' """


_Uischema = Union[Dict[str, "_UischemaAdditionalproperties"], "_UischemaTyped"]
_Uischema = Union[dict[str, "_UischemaAdditionalproperties"], "_UischemaTyped"]
"""
WARNING: Normally the types should be a mix of each other instead of Union.
Expand All @@ -346,7 +346,7 @@ class _TemplatesTyped(TypedDict, total=False):


_UischemaAdditionalproperties = Union[
"_Uischema", Union[str, Union[int, float], Dict[str, Any], List[Any], bool, None]
"_Uischema", Union[str, Union[int, float], dict[str, Any], list[Any], bool, None]
]
""" Aggregation type: anyOf """

Expand Down Expand Up @@ -386,7 +386,7 @@ class _TemplatesTyped(TypedDict, total=False):
# | Aggregation type: anyOf
"emptyValue": "_UischemaUiColonOptionsEmptyvalue",
# | Will disable any of the enum options specified in the array (by value)
"enumDisabled": List[Union[str, Union[int, float], bool]],
"enumDisabled": list[Union[str, Union[int, float], bool]],
# | Allows a user to provide a list of labels for enum values in the schema
# |
# | Aggregation type: anyOf
Expand All @@ -411,7 +411,7 @@ class _TemplatesTyped(TypedDict, total=False):
"readonly": bool,
# | Provides a means to set the initial height of a textarea widget
"rows": Union[int, float],
"style": Dict[str, Any],
"style": dict[str, Any],
# | custom overrides for urlsjf grid
"urljsf:grid": "_UischemaUiColonOptionsUrljsfColonGrid",
"widget": str,
Expand All @@ -424,7 +424,7 @@ class _TemplatesTyped(TypedDict, total=False):
bool,
Union[int, float],
str,
Dict[str, Any],
dict[str, Any],
"_UischemaUiColonOptionsEmptyvalueAnyof",
None,
]
Expand All @@ -447,7 +447,7 @@ class _TemplatesTyped(TypedDict, total=False):
Union[int, float],
str,
"_UischemaUiColonOptionsEnumnamesAnyof",
List[Union[str, Union[int, float], Dict[str, Any], List[Any], bool, None]],
list[Union[str, Union[int, float], dict[str, Any], list[Any], bool, None]],
None,
]
"""
Expand All @@ -469,7 +469,7 @@ class _TemplatesTyped(TypedDict, total=False):
Union[int, float],
str,
"_UischemaUiColonOptionsOrderAnyof",
List[Union[str, Union[int, float], Dict[str, Any], List[Any], bool, None]],
list[Union[str, Union[int, float], dict[str, Any], list[Any], bool, None]],
None,
]
"""
Expand All @@ -489,15 +489,15 @@ class _TemplatesTyped(TypedDict, total=False):
class _UischemaUiColonOptionsUrljsfColonGrid(TypedDict, total=False):
"""custom overrides for urlsjf grid"""

addButton: List[str]
children: Dict[str, List[str]]
default: List[str]
addButton: list[str]
children: dict[str, list[str]]
default: list[str]


class _UrljsfNunjucks(TypedDict, total=False):
"""options for the `nunjucks` environment"""

filters: List[_UrljsfNunjucksFiltersItem]
filters: list[_UrljsfNunjucksFiltersItem]
"""
filters to ensure in `nunjucks` templates
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1933,9 +1933,9 @@ __metadata:
linkType: hard

"electron-to-chromium@npm:^1.5.41":
version: 1.5.71
resolution: "electron-to-chromium@npm:1.5.71"
checksum: fa86e53aa78f5f11efd922c44eccc3110a08e022e08129361af0e0534e40916f53512e86da51c39b73e4342b22e33862e0bc0568b1f95e325b03e66626c0a15f
version: 1.5.72
resolution: "electron-to-chromium@npm:1.5.72"
checksum: 4fc182082285fc99942d4881fb99c507dd97b01c930a3fe7a60bb7d03dd981db4755deb69e7787f7e7d2420b7109ec4724625ba1ce2795460892a184acbe2571
languageName: node
linkType: hard

Expand Down Expand Up @@ -3314,9 +3314,9 @@ __metadata:
linkType: hard

"node-releases@npm:^2.0.18":
version: 2.0.18
resolution: "node-releases@npm:2.0.18"
checksum: ef55a3d853e1269a6d6279b7692cd6ff3e40bc74947945101138745bfdc9a5edabfe72cb19a31a8e45752e1910c4c65c77d931866af6357f242b172b7283f5b3
version: 2.0.19
resolution: "node-releases@npm:2.0.19"
checksum: 917dbced519f48c6289a44830a0ca6dc944c3ee9243c468ebd8515a41c97c8b2c256edb7f3f750416bc37952cc9608684e6483c7b6c6f39f6bd8d86c52cfe658
languageName: node
linkType: hard

Expand Down

0 comments on commit cb1a56f

Please sign in to comment.