Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from overture.schema.common import (
OvertureFeature,
)
from overture.schema.system.model_constraint import no_extra_fields
from overture.schema.system.primitive import (
from overture.schema.system.geometric import (
Geometry,
GeometryType,
GeometryTypeConstraint,
)
from overture.schema.system.model_constraint import no_extra_fields
from overture.schema.system.string import CountryCodeAlpha2, StrippedString


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pydantic import BaseModel, Field

from overture.schema.system.primitive import float64, int32
from overture.schema.system.numeric import float64, int32
from overture.schema.system.string import WikidataId

Depth = NewType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
OvertureFeature,
)
from overture.schema.common.cartography import CartographicallyHinted
from overture.schema.system.primitive import (
from overture.schema.system.geometric import (
Geometry,
GeometryType,
GeometryTypeConstraint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from overture.schema.common.models import Stacked
from overture.schema.common.names import Named
from overture.schema.system.primitive import (
from overture.schema.system.geometric import (
Geometry,
GeometryType,
GeometryTypeConstraint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from overture.schema.common.models import Stacked
from overture.schema.common.names import Named
from overture.schema.system.primitive import (
from overture.schema.system.geometric import (
Geometry,
GeometryType,
GeometryTypeConstraint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
OvertureFeature,
)
from overture.schema.common.cartography import CartographicallyHinted
from overture.schema.system.primitive import (
from overture.schema.system.geometric import (
Geometry,
GeometryType,
GeometryTypeConstraint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from overture.schema.common.models import Stacked
from overture.schema.common.names import Named
from overture.schema.system.primitive import (
from overture.schema.system.geometric import (
Geometry,
GeometryType,
GeometryTypeConstraint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from overture.schema.common.models import Stacked
from overture.schema.common.names import Named
from overture.schema.system.primitive import (
from overture.schema.system.geometric import (
Geometry,
GeometryType,
GeometryTypeConstraint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import BaseModel, Field

from overture.schema.system.doc import DocumentedEnum
from overture.schema.system.primitive import float64, int32
from overture.schema.system.numeric import float64, int32
from overture.schema.system.string import HexColor


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from overture.schema.common import OvertureFeature
from overture.schema.common.models import Stacked
from overture.schema.common.names import Named
from overture.schema.system.primitive import (
from overture.schema.system.geometric import (
Geometry,
GeometryType,
GeometryTypeConstraint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from overture.schema.common import OvertureFeature
from overture.schema.common.models import Stacked
from overture.schema.common.names import Named
from overture.schema.system.primitive import (
from overture.schema.system.geometric import (
Geometry,
GeometryType,
GeometryTypeConstraint,
Expand Down
2 changes: 1 addition & 1 deletion packages/overture-schema-codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module structure. Link computation and reverse references enable cross-page navi

**Rendering** consumes specs and owns all presentation decisions. Markdown output uses
Jinja2 templates for feature pages (with field tables, constraint sections, and
examples), enum pages, NewType pages, and aggregate primitive/geometry reference pages.
examples), enum pages, NewType pages, and aggregate numeric/geometry reference pages.

`markdown/pipeline.py` orchestrates the full pipeline without I/O, returning
`list[RenderedPage]`. The CLI writes files to disk with Docusaurus frontmatter.
Expand Down
2 changes: 1 addition & 1 deletion packages/overture-schema-codegen/docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ to registered primitives.

### Markdown renderer

Jinja2 templates for feature, enum, NewType, primitives, and geometry pages.
Jinja2 templates for feature, enum, NewType, numeric, and geometry pages.
`render_feature()` expands MODEL-kind fields inline with dot-notation (e.g.,
`sources[].dataset`), stopping at cycle boundaries. `format_type()` in
`markdown/type_format.py` converts `TypeInfo` into link-aware display strings using
Expand Down
28 changes: 15 additions & 13 deletions packages/overture-schema-codegen/docs/walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,13 @@ discriminator attribute. For Segment, it finds `subtype` and builds the mapping:
`{"road": RoadSegment, "rail": RailSegment, "water": WaterSegment}` by checking each
member for single-value `Literal` fields on the discriminator.

### Primitive extraction
### Numeric and geometry extraction

`partition_numeric_and_geometry_types` reads a module's `__all__` exports. NewType
exports are numeric primitives; non-constraint class exports are geometry types.
`partition_numeric_and_geometry_types` reads the numeric and geometric modules'
`__all__` exports. NewType exports of the numeric module are numeric types;
non-constraint class exports of the geometric module are geometry types.

`extract_numerics` builds `NumericSpec` objects. For each primitive name it resolves
`extract_numerics` builds `NumericSpec` objects. For each numeric type name it resolves
the object from the module, calls `extract_newtype` for the type analysis, then extracts
numeric bounds from constraints. `extract_numeric_bounds` scans constraint objects for
`ge`/`gt`/`le`/`lt` attributes and packs them into an `Interval`.
Expand Down Expand Up @@ -454,9 +455,9 @@ independent `if` statements, not `elif`.
`build_placement_registry` builds the complete mapping from type names to output file
paths. Three tiers:

Aggregate pages come first. All numeric primitives point to
`system/primitive/primitives.md`. All geometry types point to
`system/primitive/geometry.md`. These are hardcoded paths since the types share a single
Aggregate pages come first. All numeric types point to
`system/numeric.md`. All geometry types point to
`system/geometry.md`. These are hardcoded paths since the types share a single
reference page.

Feature specs get individual pages. Output directories derive from
Expand Down Expand Up @@ -538,7 +539,7 @@ Six Jinja2 templates in `markdown/templates/`. `feature.md.jinja2` renders a fie
with Name, Type, and Description columns, an optional Constraints section, an optional
Examples section, and a "Used By" partial. `enum.md.jinja2` renders a bullet list of
values. `newtype.md.jinja2` shows underlying type and constraints with provenance links.
`primitives.md.jinja2` and `geometry.md.jinja2` render aggregate reference pages.
`numeric.md.jinja2` and `geometry.md.jinja2` render aggregate reference pages.
`_used_by.md.jinja2` is an included partial.

The Jinja2 environment registers `linkify_urls` as a filter, which wraps bare URLs in
Expand Down Expand Up @@ -580,7 +581,7 @@ truncate at 100 characters. Lists and dicts use compact bracket/brace notation.

### Aggregate pages

`render_primitives_from_specs` sorts primitives by bit-width key (prefix then numeric
`render_numeric_from_specs` sorts numeric types by bit-width key (prefix then numeric
width), groups into signed integers, unsigned integers, and floats, and formats ranges.
Integer ranges show both bounds as a compact "lower to upper" form; `int64`-scale bounds
use `2^63` notation for readability. `render_geometry_from_values` produces a
Expand Down Expand Up @@ -636,8 +637,8 @@ Eight steps:
1. **Expand model trees** with a shared cache across all features, so sub-models
referenced by multiple features extract once.

2. **Partition primitive and geometry names** from the system primitive module's
`__all__` exports.
2. **Partition numeric and geometry names** from the system numeric and geometric
modules' `__all__` exports.

3. **Collect supplementary types** by walking expanded feature trees.

Expand All @@ -650,7 +651,7 @@ Eight steps:
7. **Render each supplementary type** -- dispatching to `render_enum`, `render_newtype`,
or `render_feature` (for sub-models) based on spec type.

8. **Render aggregate pages** for primitives and geometry.
8. **Render aggregate pages** for numeric types and geometry.

The return value is `list[RenderedPage]` -- frozen dataclasses carrying content, output
path, and a boolean `is_feature` flag. The caller decides what to do with them.
Expand Down Expand Up @@ -713,7 +714,8 @@ two NewType layers and an `Annotated` layer, producing a `TypeInfo` with
`FieldSpec.model` references. The shared cache ensures sub-models referenced by multiple
features (like `Sources`) extract once. Union-kind fields skip inline expansion.

**Layout.** `partition_numeric_and_geometry_types` reads the system module's exports.
**Layout.** `partition_numeric_and_geometry_types` reads the system numeric and
geometric modules' exports.
`collect_all_supplementary_types` walks Segment's expanded fields and discovers
referenced enums (like `Subtype`), semantic NewTypes (like `Id`, `Sources`), and
sub-models. The walk follows `FieldSpec.model` references down the tree, and for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from annotated_types import Ge, Gt, Interval, Le, Lt, MaxLen, MinLen

from overture.schema.system.primitive import GeometryTypeConstraint
from overture.schema.system.geometric import GeometryTypeConstraint
from overture.schema.system.ref import Reference

from .docstring import first_docstring_line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

__all__ = [
"GEOMETRY_PAGE",
"PRIMITIVES_PAGE",
"NUMERIC_PAGE",
"build_placement_registry",
"resolve_output_path",
]

# Aggregate page paths.
PRIMITIVES_PAGE = PurePosixPath("system/primitive/primitives.md")
GEOMETRY_PAGE = PurePosixPath("system/primitive/geometry.md")
NUMERIC_PAGE = PurePosixPath("system/numeric.md")
GEOMETRY_PAGE = PurePosixPath("system/geometry.md")


def build_placement_registry(
Expand Down Expand Up @@ -86,7 +86,7 @@ def _aggregate_page_entries(
) -> dict[TypeIdentity, PurePosixPath]:
"""Pre-populate registry entries for types documented on aggregate pages."""
entries: dict[TypeIdentity, PurePosixPath] = dict.fromkeys(
numeric_names, PRIMITIVES_PAGE
numeric_names, NUMERIC_PAGE
)
entries.update(dict.fromkeys(geometry_names, GEOMETRY_PAGE))
return entries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from dataclasses import dataclass
from pathlib import PurePosixPath

import overture.schema.system.primitive as _system_primitive
from overture.schema.system.primitive import GeometryType
import overture.schema.system.geometric as _system_geometric
import overture.schema.system.numeric as _system_numeric
from overture.schema.system.geometric import GeometryType

from ..extraction.examples import ExampleRecord, load_examples
from ..extraction.model_extraction import expand_model_tree
Expand All @@ -31,7 +32,7 @@
from .link_computation import LinkContext
from .path_assignment import (
GEOMETRY_PAGE,
PRIMITIVES_PAGE,
NUMERIC_PAGE,
build_placement_registry,
resolve_output_path,
)
Expand All @@ -40,7 +41,7 @@
render_feature,
render_geometry_from_values,
render_newtype,
render_primitives_from_specs,
render_numeric_from_specs,
render_pydantic_type,
)
from .reverse_references import UsedByEntry, compute_reverse_references
Expand Down Expand Up @@ -112,22 +113,24 @@ def _render_supplement(


def partition_numeric_and_geometry_types(
types_module: object,
numeric_module: object,
geometric_module: object,
) -> tuple[list[TypeIdentity], list[TypeIdentity]]:
"""Discover numeric and geometry types from a module's exports.
"""Discover numeric and geometry types from their source modules' exports.

NewType exports are numeric types.
Non-constraint class/enum exports are geometry types.
NewType exports of *numeric_module* are numeric types.
Non-constraint class/enum exports of *geometric_module* are geometry types.
"""
module_all: list[str] = getattr(types_module, "__all__", [])
numerics: list[TypeIdentity] = []
geometries: list[TypeIdentity] = []

for name in module_all:
obj = getattr(types_module, name)
for name in getattr(numeric_module, "__all__", []):
obj = getattr(numeric_module, name)
if is_newtype(obj):
numerics.append(TypeIdentity(obj, name))
elif isinstance(obj, type) and not name.endswith("Constraint"):

geometries: list[TypeIdentity] = []
for name in getattr(geometric_module, "__all__", []):
obj = getattr(geometric_module, name)
if isinstance(obj, type) and not name.endswith("Constraint"):
geometries.append(TypeIdentity(obj, name))

return numerics, geometries
Expand All @@ -148,7 +151,7 @@ def generate_markdown_pages(
expand_model_tree(spec, cache)

numeric_names, geometry_names = partition_numeric_and_geometry_types(
_system_primitive
_system_numeric, _system_geometric
)
all_specs = collect_all_supplementary_types(feature_specs)
registry = build_placement_registry(
Expand All @@ -172,8 +175,8 @@ def generate_markdown_pages(

pages.append(
RenderedPage(
content=render_primitives_from_specs(extract_numerics(numeric_names)),
path=PRIMITIVES_PAGE,
content=render_numeric_from_specs(extract_numerics(numeric_names)),
path=NUMERIC_PAGE,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"render_feature",
"render_geometry_from_values",
"render_newtype",
"render_primitives_from_specs",
"render_numeric_from_specs",
"render_pydantic_type",
]

Expand Down Expand Up @@ -521,7 +521,7 @@ def render_pydantic_type(
)


# Matches the ge/le bounds of the int64 NewType in overture.schema.system.primitive.
# Matches the ge/le bounds of the int64 NewType in overture.schema.system.numeric.
_INT64_MIN = -(2**63)
_INT64_MAX = 2**63 - 1

Expand Down Expand Up @@ -586,9 +586,9 @@ def _bit_width_key(name: str) -> tuple[str, int]:
return (prefix, int(digits) if digits else 0)


def render_primitives_from_specs(specs: list[NumericSpec]) -> str:
"""Render the primitives.md page from pre-extracted NumericSpecs."""
template = _get_jinja_env().get_template("primitives.md.jinja2")
def render_numeric_from_specs(specs: list[NumericSpec]) -> str:
"""Render the numeric.md page from pre-extracted NumericSpecs."""
template = _get_jinja_env().get_template("numeric.md.jinja2")

signed_ints: list[dict[str, str | None]] = []
unsigned_ints: list[dict[str, str | None]] = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Primitive Types
# Numeric Types

Numeric types used for schema field definitions.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@
from overture.schema.system.discovery.tag import get_values_for_key
from overture.schema.system.doc import DocumentedEnum
from overture.schema.system.field_constraint import UniqueItemsConstraint
from overture.schema.system.model_constraint import require_any_of
from overture.schema.system.primitive import (
from overture.schema.system.geometric import (
Geometry,
GeometryType,
GeometryTypeConstraint,
float64,
int32,
)
from overture.schema.system.model_constraint import require_any_of
from overture.schema.system.numeric import float64, int32
from overture.schema.system.ref import Id, Identified, Reference, Relationship
from overture.schema.system.string import HexColor, LanguageTag, StrippedString
from pydantic import BaseModel, EmailStr, Field, HttpUrl
Expand Down
Loading
Loading