From 3e006c6c3c11055e4a2d8fe5da7ee0ea2ac316df Mon Sep 17 00:00:00 2001 From: Titus Date: Fri, 27 Nov 2026 10:15:01 +0100 Subject: [PATCH 1/2] Add a check that a public name stays within a major and leaves only after six months marked scripts/verify_promise.py reads src/onlyworlds/ with ast (never importing it) against scripts/public-names.json, which lists each public module's names, their deprecation marks (since, leaves) and the version they were read at. It fails when a deprecation mark does not say "Deprecated since X.Y.Z" and "onlyworlds 1.0" (a DeprecationWarning's text must also name its replacement), when a listed name is gone while the major is unchanged, when a public name is not listed, and, once the major has moved, when a removed name was not marked at least six months before. --write adds names and updates marks, and removes a name only when the major moved. Exit 2 when a file cannot be read, never a pass. The two existing marks now say so: resolve_calendar_lens (since 0.69.0) and the version key of KindLayout and AroundLayout (since 0.133.0) leave in onlyworlds 1.0. The check runs in the gates job and is listed in AGENTS.md. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 2 + AGENTS.md | 3 + CHANGELOG.md | 2 + scripts/public-names.json | 725 ++++++++++++++++++++++++++++++++++ scripts/verify_promise.py | 542 +++++++++++++++++++++++++ src/onlyworlds/calendar.py | 4 +- src/onlyworlds/layout_kind.py | 10 +- 7 files changed, 1280 insertions(+), 8 deletions(-) create mode 100644 scripts/public-names.json create mode 100644 scripts/verify_promise.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9699b7e..04ea6a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,8 @@ jobs: - run: uv run python codegen/generate_nfc.py --check # Published text names no one inside the team and points at no internal room or tracker. - run: uv run python scripts/public_words.py + # A public name stays within a major, and a deprecation mark says since when and that it leaves in 1.0. + - run: uv run python scripts/verify_promise.py okf-reference: # OKF's own parser and viewer, at the commit onlyworlds.okf pins, read this package's export. diff --git a/AGENTS.md b/AGENTS.md index 820ecc1..cbb9616 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -21,8 +21,11 @@ uv run python codegen/generate_directions.py --check uv run python codegen/generate_casefold.py --check uv run python codegen/generate_nfc.py --check uv run python scripts/public_words.py +uv run python scripts/verify_promise.py ``` +`scripts/verify_promise.py` holds the package's promise: a patch fixes and a minor adds, and neither removes or renames a public name. It reads the source (never importing it) against `scripts/public-names.json`, the public names of each public module and their deprecation marks. A change that adds public names runs `uv run python scripts/verify_promise.py --write`, which adds them and never removes one within a major. A name that will go is marked first: its docstring says `Deprecated since X.Y.Z` and `onlyworlds 1.0`, and a function also warns with `DeprecationWarning`, whose text names its replacement and `onlyworlds 1.0`. It goes only in 1.0, six months or more after the release that marked it. + `main` requires two checks: `gates (ubuntu-latest, 3.13)` and `wheel`. The `gates` job also runs on Windows and on Python 3.12 and 3.14. A pull request runs four more jobs that are not required: `commits` (the commit-message check below), `okf-reference`, `folder-conformance` and `wire`. The `wheel` job builds the wheel, checks it holds exactly the tracked files under `src/onlyworlds/`, installs it in place of the source tree and runs the suite against it. Read its steps in `ci.yml`; its import check asserts a `/site-packages/` path and fails on Windows. If you change packaging (`pyproject.toml`, files added or removed under `src/`), let CI run it. diff --git a/CHANGELOG.md b/CHANGELOG.md index 92a0906..70397ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ The package version runs on its own semver; the schema it is generated from is ` ## Unreleased +- **A check holds the package's promise: a patch fixes, a minor adds, and neither removes or renames a public name** (`scripts/verify_promise.py`, in CI). It reads each public module's names from the source against `scripts/public-names.json`, and fails on a listed name gone within a major, a public name the file does not list, and a deprecation mark that does not say since which release and that the name leaves in onlyworlds 1.0; when the major moves, a name may go only if it was marked at least six months before. The two marks now say so: `resolve_calendar_lens` is deprecated since 0.69.0 and its `DeprecationWarning` says it leaves in onlyworlds 1.0 (use `resolve_calendar`), and the `version` key of `KindLayout` and `AroundLayout` is deprecated since 0.133.0 and leaves in onlyworlds 1.0 (read `method`), where it said it would leave with the npm SDK's 5.0. Only those texts change. + ## 0.156.4 (2026-11-27) - **Fixed: `calendar.validate_calendar_config` names the profile's size bounds.** Since 0.156.0 the reader refuses a calendar past a bound (more than 256 eras, 64 months, a week of more than 64 steps or names, 16 festival days, an `except` longer than 8, a name or template longer than 256 characters, a year longer than 2^53 - 1 steps), but the validator said nothing about it. It now gives the npm SDK's words for each, such as `A calendar holds at most 256 eras`; a calendar with no months whose `year.steps` is past 2^53 - 1 included, which the npm SDK names from 4.212.2. Held to the npm SDK's validator on 3,000 randomized calendars near each bound, none differing. diff --git a/scripts/public-names.json b/scripts/public-names.json new file mode 100644 index 0000000..465a386 --- /dev/null +++ b/scripts/public-names.json @@ -0,0 +1,725 @@ +{ + "about": "The public names of the onlyworlds package, read by scripts/verify_promise.py: each public module's names, the deprecated ones with the release that marked them and the major they leave in, and the version they were read at. Run the script with --write after adding names; it never removes one within a major.", + "version": "0.156.4", + "major": 0, + "modules": { + "onlyworlds": [ + "API_BASE", + "AddressAt", + "AddressError", + "AddressForm", + "AddressFound", + "AddressReading", + "AddressReason", + "ApiError", + "AroundLayout", + "AroundPoint", + "BY_LINKS_3D_REST", + "BY_LINKS_3D_VERSION", + "BulkResult", + "CHECKS_FIELD", + "CREATE_FIELDS", + "CarryLint", + "CarryOf", + "CarryPoint", + "CarryStop", + "ChangeWalk", + "CharterHub", + "CharterPacket", + "CharterRead", + "CheckRow", + "Client", + "DATE_FIELD", + "DesignPart", + "DesignState", + "DomainRead", + "Door", + "ELEMENT_TYPES", + "EditRead", + "FIELD_KINDS", + "FORMAT_VERSION", + "Folder", + "FolderElement", + "GraphEdge", + "GraphNode", + "GuideRead", + "KNOWN_OF_KEEPS", + "KindLayout", + "KindPoint", + "Landing", + "LandingCluster", + "LandingGap", + "LandingMember", + "LayoutByLinks3d", + "LensMail", + "LensReading", + "Linked", + "MESSAGE_PAIR", + "MapLayout", + "MapSpace", + "MapSpaceMap", + "MapSpaceOutline", + "MapSpacePin", + "MostLinked", + "NOTE_PAIR", + "NameFinder", + "NameFound", + "NameShared", + "Opener", + "PROPOSED_MARK", + "PUBLIC_FIELDS", + "Patch", + "PinKnown", + "PinsKnownTo", + "PreconditionFailed", + "ProposedError", + "ProposedMark", + "PushPlan", + "PushResult", + "READING_AID_MARK", + "READING_AID_PAIRS", + "READ_MARK_PAIR", + "READ_ONLY_FIELDS", + "RECORD_FIELD", + "ROOM_PAIRS", + "Record", + "RecordMark", + "RecordStory", + "ReportGroup", + "ReportLine", + "ReportLint", + "ReportParent", + "ReportThreads", + "Response", + "RetryPolicy", + "SCHEMA_DIST_TAG", + "SCHEMA_MANIFEST_SHA256", + "SCHEMA_VERSION", + "SKILL_MAX", + "SPINE_KINDS", + "STRAND_FIELD", + "SenderRead", + "SenderStatus", + "SkippedFile", + "SpineRead", + "StaleProposal", + "Strand", + "StrandSlot", + "TOOLS", + "TRAIL_TIERS", + "Talk", + "Tool", + "ToolOpen", + "TrailHanger", + "TrailLayout", + "TrailPin", + "TrailPlace", + "TrailRecipe", + "TrailSettings", + "TrailSpiral", + "TrailTier", + "Transport", + "UrllibTransport", + "WORLD_FILE_MEDIA_TYPE", + "WorldFile", + "WorldFileError", + "WorldGraph", + "WriteReport", + "__version__", + "apply_checks", + "carry_of", + "charter_of", + "check_kinds", + "date_of", + "degree_of", + "design_parts_of", + "domains_of", + "door_where", + "doors_of", + "draught_text", + "edited_by", + "element_address", + "element_filename", + "export_world", + "find_ow_links", + "hands_on_as_proposed", + "has_unseen_recipients", + "is_addressed_to", + "is_charter_element", + "is_hidden", + "is_known_of", + "is_lens", + "is_message", + "is_note", + "is_room_element", + "is_sent_by", + "is_template", + "is_to_everyone", + "landing_of", + "layout_around", + "layout_by_kind", + "layout_by_links_3d", + "layout_of", + "lenses_in_use", + "map_space", + "most_linked_of", + "name_finder", + "note_of", + "openers_for", + "out_degree_of", + "parse_ow_link", + "parse_retry_after", + "pins_known_to", + "plan_push", + "proposed_mark_of", + "push", + "read_folder", + "read_mark_of", + "read_ow_link_at", + "read_report_line", + "read_report_lines", + "read_spine_element", + "read_world_file", + "reading_aid_of", + "recipients_of", + "record_mark_of", + "records_of", + "report_talks_of", + "report_threads_of", + "resolve_filenames", + "resolve_lens", + "sanitize_payload", + "sender_status", + "slugify", + "strand_of", + "talks_of", + "thread_of", + "trail_by_place", + "type_word", + "unplaced_around", + "unplaced_by_kind", + "unplaced_by_links_3d", + "unread_for", + "uuid7", + "verify_level", + "world_file_bytes", + "world_graph", + "write_folder", + "write_world_file" + ], + "onlyworlds.address": [ + "AddressAt", + "AddressError", + "AddressForm", + "AddressFound", + "AddressReading", + "AddressReason", + "element_address", + "find_ow_links", + "parse_ow_link", + "read_ow_link_at" + ], + "onlyworlds.calendar": [ + "CALENDAR_FIELD", + "CALENDAR_SUPERTYPE", + "CalendarBundles", + "CalendarConfig", + "CalendarEra", + "CalendarIntercalary", + "CalendarMonths", + "CalendarWeek", + "CalendarYear", + "EraDomain", + "MonthStart", + "ParseError", + "ParseResult", + "StepBreakdown", + "WORLD_CALENDAR_KEY", + "WorldCalendar", + "abs_year_for_era_year", + "absolute_year", + "approx_year_length", + "breakdown_step", + "display_year", + "era_for_step", + "floor_div", + "floor_mod", + "format_duration", + "format_mid_label", + "format_step", + "format_steps", + "format_year_label", + "intercalary_in_year", + "is_leap_year", + "is_parse_error", + "month_start_steps", + "parse_date", + "read_calendar_config", + "read_calendar_value", + "resolve_calendar", + "resolve_calendar_lens", + "resolve_era_domains", + "speaking_calendar", + "validate_calendar_config", + "weekday_for_step", + "world_calendars", + "year_length", + "year_start_step" + ], + "onlyworlds.campfire": [ + "CAMPFIRE_NAMESPACE", + "EXT_PREFIX", + "ElementPlan", + "Folded", + "ImportReport", + "MADE_NAMES", + "MODULE_TYPES", + "MadeName", + "ModuleEvidence", + "PRODUCER_INPUT", + "SEEN_MODULES", + "TEMPLATE_MODULES", + "UNTYPED_SUPERTYPE", + "import_campfire", + "main" + ], + "onlyworlds.carry": [ + "CarryLint", + "CarryOf", + "CarryPoint", + "CarryStop", + "carry_of" + ], + "onlyworlds.charter": [ + "CharterHub", + "CharterPacket", + "CharterRead", + "DesignPart", + "DesignState", + "DomainRead", + "GuideRead", + "SKILL_MAX", + "charter_of", + "design_parts_of", + "domains_of" + ], + "onlyworlds.checks": [ + "CHECKS_FIELD", + "CheckRow", + "PATTERN_CAP", + "PREDICATES", + "apply_checks" + ], + "onlyworlds.doctor": [ + "AIDS_FLAG", + "CHECKS_FLAG", + "FLAGS", + "ListReader", + "MESSAGE_SUPERTYPES", + "PACKET_CAP", + "PACKET_TOOL", + "PROPOSALS_FLAG", + "Reader", + "Report", + "SPINE_FLAG", + "doctor_api", + "doctor_folder", + "fold_name", + "main", + "packets", + "render_prose" + ], + "onlyworlds.doors": [ + "Door", + "DoorTool", + "door_where", + "doors_of" + ], + "onlyworlds.draught_text": [ + "draught_text" + ], + "onlyworlds.errors": [ + "ApiError", + "error_code", + "parse_retry_after" + ], + "onlyworlds.export": [ + "EXPORT_PRODUCER", + "MEMBER_ROLES", + "export_world", + "exported_as" + ], + "onlyworlds.folder": [ + "DuplicateId", + "ELEMENTS_DIR", + "FORMAT_VERSION", + "Folder", + "FolderElement", + "FolderNameCaseError", + "HIDDEN", + "ID_TAIL_LEN", + "KNOWN_OF", + "KNOWN_OF_KEEPS", + "LEGACY_SPATIAL_DIR", + "LEGACY_SPATIAL_TYPES", + "SLUG_ID_SEP", + "SLUG_MAX_LEN", + "SkippedFile", + "WIRE_TO_DISK_WORLD_KEYS", + "WORLD_FILE", + "WORLD_FOLDER_KEYS", + "WriteReport", + "element_filename", + "element_filename_full_id", + "id_tail", + "is_hidden", + "is_known_of", + "known_of_for_disk", + "misnamed_fixed_name", + "read_folder", + "resolve_filenames", + "slugify", + "world_for_disk", + "write_folder" + ], + "onlyworlds.graph": [ + "GraphEdge", + "GraphNode", + "WorldGraph", + "degree_of", + "world_graph" + ], + "onlyworlds.http": [ + "API_BASE", + "ApiError", + "BulkResult", + "CREATE_FIELDS", + "ChangeWalk", + "Client", + "READ_ONLY_FIELDS", + "Response", + "RetryPolicy", + "Transport", + "UrllibTransport", + "check_kinds", + "sanitize_payload" + ], + "onlyworlds.kanka": [ + "EXT_PREFIX", + "Folded", + "Hidden", + "ImportReport", + "KANKA_NAMESPACE", + "MADE_NAMES", + "MODULE_TYPES", + "MadeName", + "ModulePlan", + "PRODUCER_INPUT", + "PROVEN_MODULES", + "Picture", + "STARTER_WINDOW", + "Unplaced", + "Unresolved", + "Untagged", + "html_to_markdown", + "import_kanka", + "main" + ], + "onlyworlds.landing": [ + "Landing", + "LandingCluster", + "LandingGap", + "LandingGapKind", + "LandingMember", + "LandingMode", + "LandingUnclustered", + "Linked", + "MostLinked", + "landing_of", + "most_linked_of" + ], + "onlyworlds.layout_kind": [ + "AroundLayout", + "AroundPoint", + "KindLayout", + "KindPoint", + "layout_around", + "layout_by_kind" + ], + "onlyworlds.layout_links_3d": [ + "BY_LINKS_3D_REST", + "BY_LINKS_3D_VERSION", + "HeldRangeError", + "HeldTypeError", + "LayoutByLinks3d", + "layout_by_links_3d", + "unplaced_by_links_3d" + ], + "onlyworlds.layout_trail": [ + "TRAIL_TIERS", + "TrailHanger", + "TrailLayout", + "TrailPin", + "TrailPlace", + "TrailRecipe", + "TrailSettings", + "TrailSpiral", + "TrailTier", + "trail_by_place" + ], + "onlyworlds.legendkeeper": [ + "API_BASE", + "ApiSource", + "BoardMade", + "EXT_PREFIX", + "FileSource", + "Hidden", + "IMPORT_MAP_SOURCE", + "ImportMap", + "ImportMapOffer", + "ImportReport", + "KEY_ENV", + "LEGENDKEEPER_NAMESPACE", + "MADE_NAMES", + "MadeName", + "MapMade", + "NotImported", + "PRODUCER_INPUT", + "PRODUCER_INPUT_FILE", + "RecordedSource", + "Snapshot", + "Source", + "SourceError", + "Typed", + "Unplaced", + "Unresolved", + "import_legendkeeper", + "main", + "read_project" + ], + "onlyworlds.lens": [ + "DATE_FIELD", + "LensMail", + "LensReading", + "date_of", + "is_lens", + "is_template", + "lenses_in_use", + "resolve_lens" + ], + "onlyworlds.lint": [ + "format_version", + "lint", + "main", + "schema" + ], + "onlyworlds.map_space": [ + "MapLayout", + "MapSpace", + "MapSpaceMap", + "MapSpaceOutline", + "MapSpacePin", + "MapSpaceShape", + "PinKnown", + "PinKnownHow", + "PinsKnownTo", + "layout_of", + "map_space", + "pins_known_to" + ], + "onlyworlds.message": [ + "EditRead", + "MESSAGE_PAIR", + "NOTE_PAIR", + "READ_MARK_PAIR", + "SenderRead", + "SenderStatus", + "edited_by", + "has_unseen_recipients", + "is_addressed_to", + "is_message", + "is_note", + "is_sent_by", + "is_to_everyone", + "note_of", + "read_mark_of", + "recipients_of", + "sender_status", + "thread_of", + "unread_for" + ], + "onlyworlds.name_finder": [ + "NameFinder", + "NameFound", + "NameShared", + "name_finder" + ], + "onlyworlds.names": [ + "type_word" + ], + "onlyworlds.notion": [ + "CATEGORY_WORDS", + "DatabasePlan", + "EXT_PREFIX", + "IdFromPath", + "ImportReport", + "MADE_NAMES", + "MadeName", + "NOTION_NAMESPACE", + "PRODUCER_INPUT", + "Unplaced", + "Unresolved", + "category_of", + "import_notion", + "main", + "parse_name" + ], + "onlyworlds.okf": [ + "EXPORTER", + "FolderError", + "OKF_COMMIT", + "OKF_VERSION", + "OkfReport", + "build_bundle", + "export_okf", + "main" + ], + "onlyworlds.openers": [ + "Opener", + "Tool", + "ToolOpen", + "openers_for" + ], + "onlyworlds.pack": [ + "DEFAULT_BYTES", + "DEFAULT_FILES", + "DEFAULT_WORDS", + "PackError", + "PackReport", + "build_pack", + "is_proposed", + "main", + "pack_api", + "pack_folder", + "pack_world" + ], + "onlyworlds.push": [ + "NOT_SENT", + "Patch", + "PushPlan", + "PushResult", + "plan_push", + "push", + "stops_run", + "verify_level", + "wire_view" + ], + "onlyworlds.record": [ + "RECORD_FIELD", + "Record", + "RecordEvent", + "RecordMark", + "RecordStory", + "record_mark_of", + "records_of" + ], + "onlyworlds.report": [ + "ReportGroup", + "ReportLine", + "ReportLint", + "ReportParent", + "ReportThreads", + "read_report_line", + "read_report_lines", + "report_talks_of", + "report_threads_of" + ], + "onlyworlds.review": [ + "PROPOSED_MARK", + "ProposedMark", + "hands_on_as_proposed", + "proposed_mark_of" + ], + "onlyworlds.room": [ + "ROOM_PAIRS", + "Talk", + "is_charter_element", + "is_room_element", + "reading_aid_of", + "talks_of" + ], + "onlyworlds.spine": [ + "SPINE_ACCESS", + "SPINE_AUDIENCE", + "SPINE_FREE", + "SPINE_FREE_TYPES", + "SPINE_KEYS", + "SPINE_KINDS", + "SPINE_LAYERS", + "SPINE_OFF_LIST", + "SPINE_PREFIX", + "SPINE_PROBE_VERBS", + "SPINE_STATUSES", + "SpineRead", + "read_spine_element" + ], + "onlyworlds.strand": [ + "STRAND_FIELD", + "Strand", + "StrandSlot", + "strand_of" + ], + "onlyworlds.worldanvil": [ + "DATE_KEYS", + "EXT_PREFIX", + "Folded", + "HiddenArticle", + "ImportReport", + "MADE_NAMES", + "MadeName", + "PRODUCER_INPUT", + "PROVEN_TEMPLATES", + "TEMPLATE_TYPES", + "TemplatePlan", + "Unplaced", + "Unresolved", + "WORLDANVIL_NAMESPACE", + "import_worldanvil", + "main" + ], + "onlyworlds.worldfile": [ + "MARKER_NAME", + "REASONS", + "WORLD_FILE_MAX_BYTES", + "WORLD_FILE_MAX_ENTRIES", + "WORLD_FILE_MEDIA_TYPE", + "WORLD_FILE_PARTS", + "WorldFile", + "WorldFileError", + "WorldFileReason", + "nfc", + "read_world_file", + "simple_case_fold", + "world_file_bytes", + "write_world_file" + ] + }, + "deprecated": { + "onlyworlds.calendar": { + "resolve_calendar_lens": { + "since": "0.69.0", + "leaves": "1.0" + } + }, + "onlyworlds.layout_kind": { + "AroundLayout.version": { + "since": "0.133.0", + "leaves": "1.0" + }, + "KindLayout.version": { + "since": "0.133.0", + "leaves": "1.0" + } + } + } +} diff --git a/scripts/verify_promise.py b/scripts/verify_promise.py new file mode 100644 index 0000000..6b47865 --- /dev/null +++ b/scripts/verify_promise.py @@ -0,0 +1,542 @@ +"""Hold the package to its promise: a patch fixes, a minor adds, and neither removes or renames a public name. + +A name that will go is marked deprecated first, says since which release and that it leaves in onlyworlds 1.0 +(the next major), stays at least six months, and goes only in a major. Three rules, read from the source with +`ast` (the package is never imported) against the names file `scripts/public-names.json`: + +1. Marks. Every deprecation mark in a public module (one whose dotted name has no part with a leading + underscore) says since when and where it leaves. A mark is a docstring or a `#:` comment that says + "deprecated", or a function that calls `warnings.warn(..., DeprecationWarning)`. The owner's docstring + (the function's or class's own; for a `#:` comment, the class or module that holds the name) says + `Deprecated since X.Y.Z` and `onlyworlds N.0` with N above the current major. A warning's text also + names `onlyworlds N.0` and its replacement, a public name of the package. A class docstring that says + "deprecated" while a `#:` comment in its body marks one of its keys is read as that key's mark. +2. Names. Each public module's names are its `__all__` when it has one, else its top-level public `def`, + `class` and assigned names. Within the major the file was read at, a listed name gone from the source + fails, and so does a public name, or a mark, the file does not hold. +3. Six months. When the major has moved, a listed name gone from the source must have been marked, and the + release its mark names (a CHANGELOG.md heading `## x.y.z (YYYY-MM-DD)`) must be at least six months + before today. + +Not held: whether a mark's words are true, and a change of behaviour under an unchanged name. + +Usage: + python scripts/verify_promise.py check the source against the names file + python scripts/verify_promise.py --write add new names and update the marks; a name is removed only + when the major moved and its removal keeps rule 3 +Exit 0 when the promise holds, 1 and one line per failure (module, name, rule), 2 when a file could not be +read (a module that does not parse, an `__all__` that is not a literal list, no version): never a pass. +""" + +from __future__ import annotations + +import argparse +import ast +import calendar +import datetime +import json +import re +import sys +from dataclasses import dataclass, field +from pathlib import Path +from typing import Any + +ROOT = Path(__file__).resolve().parent.parent +PACKAGE = "onlyworlds" +SOURCE = ROOT / "src" / PACKAGE +VERSION_FILE = SOURCE / "_version.py" +CHANGELOG = ROOT / "CHANGELOG.md" +NAMES_FILE = ROOT / "scripts" / "public-names.json" + +SAYS_DEPRECATED = re.compile(r"\bdeprecated\b", re.IGNORECASE) +SINCE = re.compile(r"\b[Dd]eprecated since (\d+\.\d+\.\d+)\b") +LEAVES = re.compile(r"\bonlyworlds (\d+)\.0\b") +HEADING = re.compile(r"^## (\d+\.\d+\.\d+) \((\d{4}-\d{2}-\d{2})\)$", re.MULTILINE) +IDENTIFIER = re.compile(r"[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*") +MODULE_SELF = "(module)" # the key a module's own deprecation is recorded under +ABOUT = ( + "The public names of the onlyworlds package, read by scripts/verify_promise.py: each public module's names, " + "the deprecated ones with the release that marked them and the major they leave in, and the version they " + "were read at. Run the script with --write after adding names; it never removes one within a major." +) + + +class Unseen(Exception): + """A file the check needs could not be read: exit 2, never a pass.""" + + +@dataclass +class Mark: + """One deprecated name: where its words are, and what they say.""" + + texts: list[str] = field(default_factory=list) # the mark's own words (docstring or `#:` comment) + owner_doc: str = "" # the docstring that must say since when and where it leaves + warnings: list[str] = field(default_factory=list) # each DeprecationWarning's text + line: int = 0 + + +@dataclass +class Module: + name: str + path: Path + names: set[str] + quals: set[str] # every class, def and class-level assignment, dotted from the module + marks: dict[str, Mark] + + +@dataclass(frozen=True) +class Failure: + module: str + name: str + rule: str + text: str + kind: str # "mark", "gone", "unlisted", "record", "early" + + def line(self) -> str: + return f"{self.module}: {self.name}: {self.rule}: {self.text}" + + +def read_text(path: Path) -> str: + try: + return path.read_text(encoding="utf-8") + except (OSError, UnicodeDecodeError) as exc: + raise Unseen(f"{path.relative_to(ROOT).as_posix()}: {exc}") from exc + + +def parse(path: Path) -> tuple[ast.Module, list[str]]: + text = read_text(path) + try: + return ast.parse(text, filename=str(path)), text.splitlines() + except SyntaxError as exc: + raise Unseen(f"{path.relative_to(ROOT).as_posix()}: does not parse: {exc.msg} (line {exc.lineno})") from exc + + +def read_version() -> str: + tree, _ = parse(VERSION_FILE) + for node in tree.body: + if ( + isinstance(node, ast.Assign) + and any(isinstance(t, ast.Name) and t.id == "__version__" for t in node.targets) + and isinstance(node.value, ast.Constant) + and isinstance(node.value.value, str) + and re.fullmatch(r"\d+\.\d+\.\d+", node.value.value) + ): + return node.value.value + raise Unseen(f'{VERSION_FILE.relative_to(ROOT).as_posix()}: no __version__ = "X.Y.Z"') + + +def major_of(version: str) -> int: + return int(version.split(".", 1)[0]) + + +def public_modules() -> dict[str, Path]: + if not SOURCE.is_dir(): + raise Unseen(f"{SOURCE.relative_to(ROOT).as_posix()}: not a folder") + found: dict[str, Path] = {} + for path in sorted(SOURCE.rglob("*.py")): + parts = path.relative_to(SOURCE).with_suffix("").parts + if parts[-1] == "__init__": + parts = parts[:-1] + if any(part.startswith("_") for part in parts): + continue + found[".".join((PACKAGE, *parts))] = path + if PACKAGE not in found: + raise Unseen(f"{SOURCE.relative_to(ROOT).as_posix()}/__init__.py: missing") + return found + + +def is_public(name: str) -> bool: + return not name.startswith("_") + + +def string_of(node: ast.expr) -> str | None: + """The literal text of a message: a string, an f-string's fixed parts, or a sum of those.""" + if isinstance(node, ast.Constant) and isinstance(node.value, str): + return node.value + if isinstance(node, ast.JoinedStr): + return "".join(v.value for v in node.values if isinstance(v, ast.Constant) and isinstance(v.value, str)) + if isinstance(node, ast.BinOp) and isinstance(node.op, ast.Add): + left, right = string_of(node.left), string_of(node.right) + if left is not None and right is not None: + return left + right + return None + + +def is_deprecation_warn(call: ast.Call) -> bool: + func = call.func + named_warn = (isinstance(func, ast.Attribute) and func.attr == "warn") or ( + isinstance(func, ast.Name) and func.id == "warn" + ) + if not named_warn: + return False + category = call.args[1] if len(call.args) > 1 else None + for keyword in call.keywords: + if keyword.arg == "category": + category = keyword.value + return (isinstance(category, ast.Name) and category.id == "DeprecationWarning") or ( + isinstance(category, ast.Attribute) and category.attr == "DeprecationWarning" + ) + + +def warn_texts(nodes: list[ast.stmt], where: str) -> list[str]: + texts: list[str] = [] + for stmt in nodes: + for node in ast.walk(stmt): + if isinstance(node, ast.Call) and is_deprecation_warn(node): + message = node.args[0] if node.args else None + for keyword in node.keywords: + if keyword.arg == "message": + message = keyword.value + text = string_of(message) if message is not None else None + if text is None: + raise Unseen(f"{where} (line {node.lineno}): a DeprecationWarning whose text is not a literal") + texts.append(text) + return texts + + +def comment_above(lines: list[str], node: ast.stmt) -> str: + """The `#:` comment that documents an assignment: the lines just above it, or the end of its own line.""" + found: list[str] = [] + index = node.lineno - 2 + while index >= 0 and lines[index].strip().startswith("#:"): + found.insert(0, lines[index].strip()[2:].strip()) + index -= 1 + own = lines[node.lineno - 1] + if "#:" in own: + found.append(own.split("#:", 1)[1].strip()) + return " ".join(found) + + +def assigned_names(node: ast.stmt) -> list[str]: + targets: list[ast.expr] = [] + if isinstance(node, ast.Assign): + targets = list(node.targets) + elif isinstance(node, ast.AnnAssign): + targets = [node.target] + elif isinstance(node, ast.TypeAlias): + targets = [node.name] + names: list[str] = [] + while targets: + target = targets.pop(0) + if isinstance(target, ast.Name): + names.append(target.id) + elif isinstance(target, (ast.Tuple, ast.List)): + targets.extend(target.elts) + elif isinstance(target, ast.Starred): + targets.append(target.value) + return names + + +def flat_body(body: list[ast.stmt]) -> list[ast.stmt]: + """A body's statements, with the bodies of top-level `if`, `try` and `with` blocks taken in.""" + out: list[ast.stmt] = [] + for node in body: + if isinstance(node, ast.If): + out.extend(flat_body(node.body + node.orelse)) + elif isinstance(node, (ast.Try, ast.TryStar)): + inner = node.body + node.orelse + node.finalbody + for handler in node.handlers: + inner += handler.body + out.extend(flat_body(inner)) + elif isinstance(node, (ast.With, ast.AsyncWith)): + out.extend(flat_body(node.body)) + else: + out.append(node) + return out + + +def read_module(name: str, path: Path) -> Module: + tree, lines = parse(path) + where = path.relative_to(ROOT).as_posix() + body = flat_body(tree.body) + module = Module(name, path, set(), set(), {}) + + declared = [n for n in body if isinstance(n, (ast.Assign, ast.AnnAssign)) and "__all__" in assigned_names(n)] + if declared: + value = declared[-1].value + if not ( + isinstance(value, (ast.List, ast.Tuple)) + and all(isinstance(e, ast.Constant) and isinstance(e.value, str) for e in value.elts) + ): + raise Unseen(f"{where} (line {declared[-1].lineno}): __all__ is not a literal list of strings") + module.names = {e.value for e in value.elts if isinstance(e, ast.Constant) and isinstance(e.value, str)} + if any(isinstance(n, ast.AugAssign) and isinstance(n.target, ast.Name) and n.target.id == "__all__" for n in body): + raise Unseen(f"{where}: __all__ is extended in place, not one literal list") + + tied: set[int] = set() # the lines of `#:` comments tied to a name + + def tie(node: ast.stmt) -> None: + index = node.lineno - 2 + while index >= 0 and lines[index].strip().startswith("#:"): + tied.add(index + 1) + index -= 1 + tied.add(node.lineno) + + def walk(statements: list[ast.stmt], prefix: str, owner: ast.Module | ast.ClassDef) -> None: + owner_doc = ast.get_docstring(owner, clean=False) or "" + for node in statements: + if isinstance(node, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)): + qual = prefix + node.name + module.quals.add(qual) + doc = ast.get_docstring(node, clean=False) or "" + warned = warn_texts(node.body, f"{where}: {qual}") if not isinstance(node, ast.ClassDef) else [] + if SAYS_DEPRECATED.search(doc) or warned: + module.marks[qual] = Mark([doc] if doc else [], doc, warned, node.lineno) + if isinstance(node, ast.ClassDef): + walk(flat_body(node.body), qual + ".", node) + elif isinstance(node, (ast.Assign, ast.AnnAssign, ast.TypeAlias)): + comment = comment_above(lines, node) + tie(node) + for target in assigned_names(node): + qual = prefix + target + module.quals.add(qual) + if comment and SAYS_DEPRECATED.search(comment): + module.marks[qual] = Mark([comment], owner_doc, [], node.lineno) + # A class whose keys carry the deprecation: its docstring's "deprecated" is theirs, not its own. + if isinstance(owner, ast.ClassDef): + own = prefix[:-1] + keys = [q for q in module.marks if q.startswith(prefix) and "." not in q[len(prefix) :]] + keyed = [q for q in keys if module.marks[q].owner_doc == owner_doc and q != own] + if own in module.marks and keyed and not module.marks[own].warnings: + del module.marks[own] + + walk(body, "", tree) + module_doc = ast.get_docstring(tree, clean=False) or "" + top_warned = warn_texts( + [n for n in body if not isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef))], where + ) + if SAYS_DEPRECATED.search(module_doc) or top_warned: + module.marks[MODULE_SELF] = Mark([module_doc], module_doc, top_warned, 1) + + for number, text in enumerate(lines, start=1): + if text.strip().startswith("#:") and SAYS_DEPRECATED.search(text) and number not in tied: + module.marks[f"(line {number})"] = Mark([text.strip()], "", [], number) + + if not declared: + for node in body: + if isinstance(node, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)): + module.names.add(node.name) + elif isinstance(node, (ast.Assign, ast.AnnAssign, ast.TypeAlias)): + module.names.update(assigned_names(node)) + module.names = {n for n in module.names if is_public(n)} + return module + + +def leaves_above(text: str, major: int) -> int | None: + above = sorted(int(m) for m in LEAVES.findall(text) if int(m) > major) + return above[0] if above else None + + +def judge_marks( + module: Module, major: int, every_name: set[str] +) -> tuple[dict[str, dict[str, str | None]], list[Failure]]: + """Rule 1: each mark says since when and where it leaves; a warning names its replacement and that major.""" + recorded: dict[str, dict[str, str | None]] = {} + failures: list[Failure] = [] + for qual, mark in sorted(module.marks.items()): + if any(not is_public(part) for part in qual.split(".")) and qual != MODULE_SELF: + continue + + def fail(text: str, qual: str = qual) -> None: + failures.append(Failure(module.name, qual, "marks", text, "mark")) + + if not mark.owner_doc and qual.startswith("(line"): + fail("a #: comment says deprecated but documents no assignment") + continue + own = " ".join(mark.texts) + sinces = sorted(set(SINCE.findall(own))) or sorted(set(SINCE.findall(mark.owner_doc))) + whose = "its docstring" if mark.texts and mark.texts[0] == mark.owner_doc else "its owner's docstring" + since: str | None = None + if not sinces: + fail(f'{whose} says no "Deprecated since X.Y.Z"') + elif len(sinces) > 1: + fail(f"{whose} names more than one release ({', '.join(sinces)}): say which in the mark") + else: + since = sinces[0] + leaves = leaves_above(own, major) or leaves_above(mark.owner_doc, major) + if leaves is None: + fail(f'{whose} says no "onlyworlds {major + 1}.0", the major it leaves in') + for text in mark.warnings: + if leaves_above(text, major) is None: + fail(f'its DeprecationWarning text says no "onlyworlds {major + 1}.0": {text!r}') + own_name = qual.rsplit(".", 1)[-1] + named = [t for t in IDENTIFIER.findall(text) if t != own_name and t != PACKAGE and t in every_name] + if not named: + fail(f"its DeprecationWarning text names no replacement (a public name of the package): {text!r}") + recorded[qual] = {"since": since, "leaves": f"{leaves}.0" if leaves is not None else None} + return recorded, failures + + +def said(mark: dict[str, str | None] | None) -> str: + """A recorded mark in words, for a line that says the source and the names file differ.""" + if mark is None: + return "no mark" + return f"deprecated since {mark.get('since') or '(none)'}, leaving in onlyworlds {mark.get('leaves') or '(none)'}" + + +def changelog_dates() -> dict[str, datetime.date]: + return {v: datetime.date.fromisoformat(d) for v, d in HEADING.findall(read_text(CHANGELOG))} + + +def six_months_after(day: datetime.date) -> datetime.date: + month = day.month + 6 + year, month = day.year + (month - 1) // 12, (month - 1) % 12 + 1 + return datetime.date(year, month, min(day.day, calendar.monthrange(year, month)[1])) + + +def load_names_file(writing: bool) -> dict[str, Any] | None: + if not NAMES_FILE.exists(): + if writing: + return None + raise Unseen(f"{NAMES_FILE.relative_to(ROOT).as_posix()}: missing (run with --write to make it)") + try: + data = json.loads(read_text(NAMES_FILE)) + except json.JSONDecodeError as exc: + raise Unseen(f"{NAMES_FILE.relative_to(ROOT).as_posix()}: not JSON: {exc}") from exc + if not ( + isinstance(data, dict) + and isinstance(data.get("version"), str) + and re.fullmatch(r"\d+\.\d+\.\d+", data["version"]) + and isinstance(data.get("modules"), dict) + and all(isinstance(v, list) and all(isinstance(n, str) for n in v) for v in data["modules"].values()) + and isinstance(data.get("deprecated"), dict) + and all(isinstance(v, dict) for v in data["deprecated"].values()) + ): + raise Unseen(f"{NAMES_FILE.relative_to(ROOT).as_posix()}: not the names file's shape") + return data + + +def run(writing: bool, today: datetime.date) -> int: + version = read_version() + major = major_of(version) + modules = {name: read_module(name, path) for name, path in public_modules().items()} + every_name: set[str] = set() + for module in modules.values(): + short = module.name.removeprefix(PACKAGE + ".") + every_name |= module.names | module.quals | {f"{short}.{n}" for n in module.names} + every_name = {n for n in every_name if all(is_public(p) for p in n.split("."))} + + failures: list[Failure] = [] + marks: dict[str, dict[str, dict[str, str | None]]] = {} + for module in modules.values(): + recorded, bad = judge_marks(module, major, every_name) + failures += bad + if recorded: + marks[module.name] = recorded + + data = load_names_file(writing) + listed: dict[str, list[str]] = data["modules"] if data else {} + was_marked: dict[str, dict[str, dict[str, str | None]]] = data["deprecated"] if data else {} + read_at = str(data["version"]) if data else version + moved = major_of(read_at) != major + if major_of(read_at) > major: + raise Unseen(f"the names file was read at {read_at}, a later major than the source's {version}") + + dates = changelog_dates() if moved else {} + removed: dict[str, set[str]] = {} # names a moved major may drop from the file + + def present(module_name: str, name: str) -> bool: + module = modules.get(module_name) + if module is None: + return False + if name == MODULE_SELF: + return True + return name in module.names if "." not in name else name in module.quals + + def gone(module_name: str, name: str) -> None: + if not moved: + text = f"listed at {read_at}, gone from the source within major {major} (a name stays within a major)" + failures.append(Failure(module_name, name, "names", text, "gone")) + return + mark = was_marked.get(module_name, {}).get(name) or was_marked.get(module_name, {}).get(MODULE_SELF) + since = mark.get("since") if mark else None + if mark is None: + text = f"gone in major {major} with no deprecation mark at {read_at} (a name is marked before it leaves)" + elif not since: + text = f"gone in major {major}, marked at {read_at} with no release it was deprecated in" + elif since not in dates: + text = f"gone in major {major}, deprecated since {since}, a release CHANGELOG.md does not date" + elif six_months_after(dates[since]) > today: + text = ( + f"gone in major {major}, deprecated since {since} ({dates[since].isoformat()}): under six months " + f"before {today.isoformat()} (a name stays six months marked)" + ) + else: + removed.setdefault(module_name, set()).add(name) + return + failures.append(Failure(module_name, name, "six months", text, "early")) + + for module_name, names in sorted(listed.items()): + for name in sorted(names): + if not present(module_name, name): + gone(module_name, name) + for module_name, keys in sorted(was_marked.items()): + for name in sorted(keys): + if "." in name and not present(module_name, name): + gone(module_name, name) + + for module_name, module in sorted(modules.items()): + for name in sorted(module.names - set(listed.get(module_name, []))): + failures.append( + Failure( + module_name, name, "names", "public, not in scripts/public-names.json (run --write)", "unlisted" + ) + ) + for module_name in sorted(set(marks) | set(was_marked)): + now, then = marks.get(module_name, {}), was_marked.get(module_name, {}) + for name in sorted(set(now) | set(then)): + if name.startswith("(line") or not present(module_name, name): + continue + if now.get(name) != then.get(name): + text = f"the source has {said(now.get(name))}, the names file {said(then.get(name))} (run --write)" + failures.append(Failure(module_name, name, "names", text, "record")) + + if writing: + held_back = any(f.kind in ("gone", "early") for f in failures) + new_modules: dict[str, list[str]] = {} + for module_name in sorted(set(listed) | set(modules)): + keep = {n for n in listed.get(module_name, []) if n not in removed.get(module_name, set())} + names = keep | (modules[module_name].names if module_name in modules else set()) + if names: + new_modules[module_name] = sorted(names) + new_marks: dict[str, dict[str, dict[str, str | None]]] = {} + for module_name in sorted(set(marks) | set(was_marked)): + entries = {k: v for k, v in marks.get(module_name, {}).items() if not k.startswith("(line")} + for name, mark in was_marked.get(module_name, {}).items(): + if not present(module_name, name) and name not in removed.get(module_name, set()): + entries[name] = mark # a name still listed keeps the mark it left with + if entries: + new_marks[module_name] = dict(sorted(entries.items())) + out = { + "about": ABOUT, + "version": read_at if held_back and moved else version, + "major": major_of(read_at) if held_back and moved else major, + "modules": new_modules, + "deprecated": new_marks, + } + with NAMES_FILE.open("w", encoding="utf-8", newline="\n") as handle: + handle.write(json.dumps(out, indent=2, ensure_ascii=True) + "\n") + failures = [f for f in failures if f.kind not in ("unlisted", "record")] + + for failure in failures: + print(failure.line()) + count = sum(len(m.names) for m in modules.values()) + marked = sum(len(v) for v in marks.values()) + verdict = f"{len(failures)} failure{'s' if len(failures) != 1 else ''}" if failures else "the promise holds" + print(f"verify_promise: {len(modules)} public modules, {count} names, {marked} marks, at {version}: {verdict}") + return 1 if failures else 0 + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0] if __doc__ else None) + parser.add_argument("--write", action="store_true", help="add new names and update marks in the names file") + args = parser.parse_args(argv) + try: + return run(args.write, datetime.date.today()) + except Unseen as exc: + print(f"verify_promise: could not see: {exc}", file=sys.stderr) + return 2 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/src/onlyworlds/calendar.py b/src/onlyworlds/calendar.py index d86a805..9bfd324 100644 --- a/src/onlyworlds/calendar.py +++ b/src/onlyworlds/calendar.py @@ -2050,12 +2050,12 @@ def resolve_calendar_lens( *, fallback_to_only: bool = False, ) -> WorldCalendar | None: - """Deprecated since 0.69.0: the old name of ``resolve_calendar``, with the same answers. + """Deprecated since 0.69.0, and leaves in onlyworlds 1.0: use ``resolve_calendar``, which answers the same. "Lens" now names a cut of a world, not a chosen calendar. Warns with ``DeprecationWarning``. """ warnings.warn( - "resolve_calendar_lens is renamed resolve_calendar; the old name will be removed", + "resolve_calendar_lens is renamed resolve_calendar; the old name leaves in onlyworlds 1.0", DeprecationWarning, stacklevel=2, ) diff --git a/src/onlyworlds/layout_kind.py b/src/onlyworlds/layout_kind.py index 3b385e7..bf747b6 100644 --- a/src/onlyworlds/layout_kind.py +++ b/src/onlyworlds/layout_kind.py @@ -42,9 +42,8 @@ class KindPoint(TypedDict): class KindLayout(TypedDict): """What ``layout_by_kind`` answers: one point per node, in the graph's node order, and the method that made them. - ``version`` is deprecated. It is always 1: a method's word is its version, so read ``method``, never this - number. The layout profile's mark carries no version key, and this one leaves when the npm SDK's does, at - its 5.0.""" + The ``version`` key is deprecated since 0.133.0 and leaves in onlyworlds 1.0: read ``method`` instead. It is + always 1, since a method's word is its version, and the layout profile's mark carries no version key.""" method: Literal["by-kind"] #: Deprecated: always 1 (the class docstring says when it leaves). @@ -65,9 +64,8 @@ class AroundPoint(TypedDict): class AroundLayout(TypedDict): """What ``layout_around`` answers: the focus and every element within the steps, in the graph's node order. - ``version`` is deprecated. It is always 1: a method's word is its version, so read ``method``, never this - number. The layout profile's mark carries no version key, and this one leaves when the npm SDK's does, at - its 5.0.""" + The ``version`` key is deprecated since 0.133.0 and leaves in onlyworlds 1.0: read ``method`` instead. It is + always 1, since a method's word is its version, and the layout profile's mark carries no version key.""" method: Literal["around"] #: Deprecated: always 1 (the class docstring says when it leaves). From f40850114a08bcc90bd9c8c69f0fe723a9b28772 Mon Sep 17 00:00:00 2001 From: Titus Date: Fri, 27 Nov 2026 10:17:03 +0100 Subject: [PATCH 2/2] 0.156.5: the two deprecations say since which release and that they leave in onlyworlds 1.0 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 +++ src/onlyworlds/_version.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70397ec..3f097c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ The package version runs on its own semver; the schema it is generated from is ` ## Unreleased +## 0.156.5 (2026-11-27) + +- **The two deprecations say since which release and that they leave in onlyworlds 1.0**: `calendar.resolve_calendar_lens` (since 0.69.0; its warning now names the release) and the `version` key of `KindLayout` and `AroundLayout` (since 0.133.0), which said it would leave with the npm SDK. - **A check holds the package's promise: a patch fixes, a minor adds, and neither removes or renames a public name** (`scripts/verify_promise.py`, in CI). It reads each public module's names from the source against `scripts/public-names.json`, and fails on a listed name gone within a major, a public name the file does not list, and a deprecation mark that does not say since which release and that the name leaves in onlyworlds 1.0; when the major moves, a name may go only if it was marked at least six months before. The two marks now say so: `resolve_calendar_lens` is deprecated since 0.69.0 and its `DeprecationWarning` says it leaves in onlyworlds 1.0 (use `resolve_calendar`), and the `version` key of `KindLayout` and `AroundLayout` is deprecated since 0.133.0 and leaves in onlyworlds 1.0 (read `method`), where it said it would leave with the npm SDK's 5.0. Only those texts change. ## 0.156.4 (2026-11-27) diff --git a/src/onlyworlds/_version.py b/src/onlyworlds/_version.py index 984e859..e676b0c 100644 --- a/src/onlyworlds/_version.py +++ b/src/onlyworlds/_version.py @@ -1 +1 @@ -__version__ = "0.156.4" +__version__ = "0.156.5"