Everything in this repository is ready. This file is the lifelib-side half: the steps that cannot be done here because they touch lifelib's own files.
The design decisions behind each step are in USLIB-MERGE-PLAN.md;
this is the checklist, not the argument. The plan was written for uslib and executed
there first; uklib was then put through the same phases, and §9
records where the second run contradicted the first. jplib is the third, and
§10 records what the third run changed — less than the second,
which is the point of having parameterized the tooling.
Status of the prep: the documentation builds to 235 pages with 0 warnings under
-n -W --keep-going -E, 25,075 internal anchor links resolve with 0 broken, and the three
libraries' 2,453 tests pass (37 skipped). All three are reproducible here:
python tools/doccheck.pypython -m pytest lifelib/libraries/uslib/tests lifelib/libraries/uklib/tests lifelib/libraries/jplib/tests -qpython tools/doccheck.py --keep && python tools/check_anchors.py doc/build/checkcp -r lifelib/libraries/uslib lifelib/libraries/uklib lifelib/libraries/jplib <lifelib>/lifelib/libraries/That is the whole step, and it is a copy with no path rewriting because the libraries
already sit at lifelib/libraries/<lib>/ in this repository too. That is deliberate: it
is what lets the page tree in §4 be copied verbatim rather than regenerated on this side.
Each library is self-contained: the models sit beside the documents that specify them, the
test suite is inside at <lib>/tests/, and every internal path reference is either
relative or library-root-relative, so nothing inside names its own location. Each directory
is already called by its library name — the anchors, the automodule paths and the package
names all say uslib, uklib and jplib today.
That takes the compiler with them. uslib and uklib each carry build_sec_cy.py at their
root, the tool that compiles their _SEC models with modelx-cython, one file in both and
held so by uklib's suite. Each run_sec.py --cython builds with it, each model-sec.md
gives python build_sec_cy.py <product> as the build, and the compile tests load it, so a
build works in lifelib and in a lifelib.create() copy as it does here. Until 2026-11-27
the tool lived in this repository's tools/, which this step does not copy, and lifelib
was left with runners and pages naming a script it did not have (lifelib-dev/lifelib issue
195). This repository's tools/build_sec_cy.py is now a command line over the libraries'
copies, and stays here with the rest of tools/.
Take them together. uklib/index.md links to ../uslib/index.md and to two explicit
targets on it — #uslib-one-shape and #uslib-shared-vocabulary — because D8 makes the
enforced model shape and the settled cells vocabulary rulings for all the libraries, stated
once. jplib/index.md links to both siblings and to the same two targets. The relative paths
hold inside libraries/, but only once all three are there. Merging any one of them alone
breaks cross-references and fails the -n build.
get_package_data lists the extensions that reach an installed copy:
extensions = ['py', 'ipynb', 'xlsx', 'csv', 'json', 'pickle']Add 'md'. Without it the documents are not installed, so lifelib.create("uslib", …)
hands the user a library with no documentation — and for these libraries the documentation
is the point. .py and .csv are already covered, so the models, their inputs and the
tests travel as they are.
Then keep _research/ out. With 'md' in the list — upstream already has it — the walk
also ships every library's research notes, and those notes quote third-party documents
(insurers' producer-only guides, the NAIC AP&P Manual) that the libraries may cite but not
redistribute. Prune the directory in get_package_data, and in MANIFEST.in so the sdist
matches:
for root, dirs, files in os.walk(topd):
# Each library's _research/ notes stay in the repository and out of the
# distributions: they quote third-party documents verbatim.
dirs[:] = [d for d in dirs if d != '_research']prune lifelib/libraries/*/_research
Built from the 0.17.2 sources, this drops exactly the 69 _research/ files from the wheel,
and the same files from the sdist, and changes nothing else; lifelib.create("uslib", …)
still copies the models, the documents and the tests. It does not reach releases already on
PyPI: 0.14.0 to 0.17.2 carry the notes.
install_requires=['modelx>=0.31.0'] # -> 'modelx>=0.32'The twenty-eight models are serialized with modelx serializer v8. modelx 0.31.1 cannot read
them; read_model fails outright rather than degrading. This is a hard requirement of the
merge, not a preference.
No configuration change is needed at all, but one existing workaround becomes load-
bearing — see the end of this section. lifelib already loads myst_parser,
sphinx.ext.autodoc, autosummary and napoleon, already sets
autodoc_member_order = 'bysource', and already puts lifelib/libraries on sys.path —
which is why the models are importable as <lib>.products.<slug>.<Model> and why the
product slugs were underscored.
The documents reach the build through the page tree, not through configuration. Each
page under doc/source/libraries/<lib>/ is a one-line {include} of the corresponding
library document, and the page tree mirrors the library tree so the authored relative links
keep resolving. Nothing is copied and nothing is generated at build time.
Copy doc/source/libraries/uslib/ (146 files), doc/source/libraries/uklib/ (86 files) and
doc/source/libraries/jplib/ (74 files) from this repository into lifelib's
doc/source/libraries/ as they stand. All of them come
from python tools/gen_scaffolding.py lifelib/libraries/<lib>, and every include path they
carry is already the one lifelib needs — ../../../../../../lifelib/libraries/uslib/…,
counted from the stub by os.path.relpath rather than written by hand — because the
libraries sit at that same path in this repository. Nothing here needs regenerating.
Those trees also carry the autodoc pages — <Model>/<Model>.rst and one
<Model>/<Space>.rst per Space, following annuallife/TradLife_A.rst — which deliberately
do not live in the libraries: they are Sphinx plumbing, and a lifelib.create() copy is
better without them. Each model has a folder of its own, in every library, because a uslib
or uklib product can hold two models whose Spaces share their names: its <Name>_US_S and
the <Name>_US_SEC beside it (USLIB-SEC-PLAN.md D9), or its <Name>_UK_S and the
<Name>_UK_SEC beside it (UKLIB-SEC-PLAN.md U1). A model page's URL is therefore
libraries/<lib>/products/<slug>/<Model>/<Model>.html.
_research/ is excluded by simply having no pages, so there is no exclude_patterns entry
to add either. It stays in the repository rather than shipping with each library (§2),
because it quotes third-party documents, and it carries its own deliberately independent
[S#] numbering: a second, conflicting S1 in front of a reader is worse than not
publishing it.
Do not enable myst_enable_extensions = ["dollarmath"]. These documents are full of
currency: $100,000, £100,000, ¥10,000,000 — and jplib's foreign-currency whole life
adds seventy more dollar signs of its own, as US$100,000, in a library where every other
figure is yen. lifelib's MyST extension set is empty today and must stay
that way for these libraries to render.
_scope_nbsphinx_link_rewriting_to_notebooks() is now mandatory. lifelib's conf.py
already carries it (it is defined around line 289 and called from setup), and it must
stay. nbsphinx registers RewriteLocalLinks with app.add_transform, so the transform
runs over every document rather than only notebooks: given a link that is nothing but a
fragment, it substitutes the current document's own filename and emits a std:ref to
/<docname>.md#fragment, which no explicit MyST target matches. The node is replaced during
the read phase, so myst-parser's own resolver never sees it.
Every [R#], [REG-R#], [std] and [unverified] citation is exactly such a bare
#fragment link: 8,572 of them as authored across the three libraries — 4,789
regulatory, 3,451 convention markers and 332 inline pinpoint links, recounted on the current
corpus. (Do not read the 25,075 from the status block as
this number: that counts every internal anchor link in the built site, most of which are
heading permalinks and autodoc cross-references, which this transform cannot touch. Nor
does the built HTML show the exposure, because Sphinx has by then rewritten every
cross-page citation to a full relative URL — the transform runs during the read phase,
while they are all still bare fragments.)
They are produced by link reference definitions, for which there is no {ref}-role
equivalent, because a shortcut reference is Markdown link syntax by construction. There is
no version of these documents that avoids the problem.
This repository cannot reproduce the failure: it does not load nbsphinx, so its build is clean either way. That is exactly the trap — the check that passes here is not the check that matters there.
Two rows in the table:
:doc:`uslib/index` U.S. life and annuity reference products and models
:doc:`uklib/index` UK life and pension annuity reference products and models
:doc:`jplib/index` Japan life, third-sector and annuity reference products and models
and three entries in the toctree:
uslib/index.md
uklib/index.md
jplib/index.md
The page trees are committed source, not build output, so they need nothing. A compiled
build does: run_sec.py --cython, and python build_sec_cy.py <product> without --out,
build beside the model, in the product directory (§1). lifelib already ignores build/
and *.so; add the rest of what a build leaves there, as this repository's .gitignore
has it:
*_nomx/
*_nomx_cy/
*.pyd
lifelib/libraries/*/products/*/setup.py
The setup.py rule is anchored to the product directories, because a setup.py anywhere
else can be source: lifelib's own is, at its root.
python -m pytest lifelib/libraries/uslib/tests lifelib/libraries/uklib/tests lifelib/libraries/jplib/tests -qCI needs no change: .github/workflows/tests.yml and tox.ini both run bare pytest from
the repository root, which already collects ifrs17a's in-library tests and will collect
these the same way. That is precisely why §9's first item matters — a bare pytest at
the lifelib root collects all three suites in one process, and the registry split is what
keeps them apart.
Then build the docs and confirm the pages are clean, with
sphinx-build -n -W --keep-going -E; the -n matters.
Sphinx does not warn about an unresolved :func:/:mod: role by default — it drops the
role and renders plain text — so a build without nitpicky mode cannot tell you whether the
cross-references survived. During the uslib prep it was the only thing that revealed 38
silently dead references; during the uklib prep, 63 problems of which one warned; during the jplib prep, two, both
inside model docstrings and neither visible without it.
Finally, confirm the links arrive rather than merely exist:
python tools/check_anchors.py <build tree>Sphinx normalises label underscores to hyphens when it emits ids —
uklib-term_assurance-s1 becomes id="uklib-term-assurance-s1" — so a check written
against the label text passes while every link goes nowhere. check_anchors.py reads the
ids out of the built pages instead.
requirements.txtin lifelib-products pins the runtime for the models. After the merge,modelxcomes from lifelib'sinstall_requires(step 3) andpandas/numpyare already assumed by the other libraries.pyteststays a development dependency and is deliberately not added toinstall_requires, even though the tests now ship.- The models' autodoc pages are already written and building, at
doc/source/libraries/<lib>/products/<slug>/<Model>/<Model>.rstand one<Space>.rstbeside each, in the model's own folder. Nothing further is required to publish them.
The plan's D8 fixed the conventions as house conventions and required the tooling to be parameterized, so the uklib run was meant to be a re-invocation rather than a redesign. It mostly was: the counts P3 predicted came out exactly, and P4 and P5 needed no new decisions. What follows is everything that did not go to plan, because that is the part worth reading.
conftest.py is a name pytest fixes. With two in-library suites, pytest lifelib/libraries/uslib/tests lifelib/libraries/uklib/tests puts two files called conftest on sys.path; one wins sys.modules, and
every from conftest import LIB in either suite resolves to the other library. It
surfaced as a FileNotFoundError naming a uslib product under uklib/. The quiet version
of the same fault is a suite that locates the wrong library's models and passes.
MODELS, LIB and model_path now live in us_registry.py / uk_registry.py;
conftest.py re-exports them for its fixtures. This is a merge-blocking item, not a
tidy-up: CI runs bare pytest from the lifelib root, which collects both.
separate_citations.py and gen_citation_links.py excluded fenced code and nothing else.
CommonMark also has indented code — a four-space run after a blank line — which is how these
technical notes lay out their recursions, and 47 such blocks carry citation tags.
In uslib all but one of them is a bare [S1], inert whether it is processed or not, so the
gap all but never showed. The exception found it: P5 had already written a literal
(#uslib-immediate_annuity-s5) into an indented block in
immediate_annuity/technical-notes.md, and that page printed the raw markup at the reader
until the S-citation reversal took it back out. In uklib they carry pinpoint cites
throughout, and the pinpoint pass is the one that rewrites text, so the same fault would
have landed in a rendered formula block on every product. This is the D5 asymmetry the plan
predicted — uk has roughly twice the pinpoint cites of us despite being half the size —
arriving in a form the inventory could not show.
New tools/mdspans.py answers where-is-the-code with markdown-it, MyST's own parser, rather
than a heuristic. Verified byte-neutral on uslib.
It collected model names from the library it was fixing, so uklib's five chassis pointers at
uslib models — PA_UK_S → SPIA_US_S, Term_UK_S → Term_US_S, WOL_UK_S →
WholeLife_US_S — were invisible to it and it reported 0. These are the same sibling
pointers the plan describes inside uslib, one level out. It now collects from every
sibling library. The leading dot is refspecific, so a UK model's chassis pointer lands on the
US model's page without either library naming the other's location — and that is the second
reason the two libraries want to be in one build.
:data:roles on modelx References, 32 of them. A Reference is a module-level assignment, not a cells, so autodoc documents no target and the role is always dead. uslib has no:data:roles at all — it spells References as inline literals — so these were made to match.- Aligned two-column blocks, 19 of them across seven
Projectiondocstrings."BEF_DECR"the start of the monthhas no RST construct behind it: docutils reads it as a paragraph plus an over-indented block. Newtools/fix_docstring_lists.pyconverts them to the definition lists the rest of the corpus uses.
python tools/fix_docstring_lists.py lifelib/libraries/uslib --dry-run reports 5 blocks, in five
Projection docstrings. None of them warns, which is why a build at zero warnings did
not find them: they are all the silent kind, one term with a wrapped description, which
docutils parses as a definition list whose term is the whole first line — description
included. They render wrongly and always have. Left alone here rather than changing a
finished library on the way past; the tool is in the repository and the fix is one command.
That inventory counted the whole uk/ tree. _research/ is out of the build under D6 and
receives no definitions, so the numbers for rendered documents are lower and the shortfall
is not a miss:
| §6 predicted for uk | rendered | in _research/ |
|
|---|---|---|---|
| pinpoint cites | 768 | 518 | 321 |
| comma lists | 1 | 0 | 1 ([S1,S2]) |
| bracket adjacencies | 1,947 | 1,515 | 472 |
The 1,515 is 1,505 separated by the tool, 8 inside indented code blocks where an adjacency
is displayed and never resolved, and 2 by hand. The §6 column was measured on the uk/ tree
as it stood before the models landed; measuring the same way today gives 1,987 rather than
1,947, so it is a moving figure and only the split matters.
The tools reported two adjacencies they declined to guess at, and the P5 output showed two
more of the same shape that nothing had flagged. All four are a bare citation nested inside
another citation's brackets — [R10, …; verified via [REG-R33][REG-R34]] — where, once the
outer bracket becomes a link, CommonMark will not put a link inside link text. Fixed by
unnesting: the annotation becomes a parenthetical and all three citations are siblings.
uslib has 19 more of that shape and uklib five, but every one of those swallows a [std] or
[unverified] marker rather than a citation, which is the accepted D5a behaviour for
qualified forms. Only these four lost a cross-reference.
Its generated definition block was missing: P5 ran before P6 rewrote that page, and it was
never regenerated, so the eight [std] and two [unverified] markers on the page that
states every citation tag is a link were the only ones that were not. Regenerated here.
The same thing happened to uklib/index.md during its own P6 and was caught by
check_anchors.py, which is the check that exists to catch it.
- uk has models now. The plan assumed the UK section had none and that a product directory carrying documents but no model had to be legal. PR #14 landed all seven, so D2 colocation and D9 autodoc apply to uklib exactly as to uslib.
- No generated "Verifying this copy" block in uklib's
model.md. uslib carries one per product from an earlier version ofgen_scaffolding.py, which no longer emits it. uklib's hand-written## Testssections already name the test module, say what it asserts and give the command, so D7's requirement is met without a near-duplicate beside it. gen_scaffolding.py'sTITLESgains the seven UK slugs. One map serves both libraries, since slugs are unique across them.- 28 document H1s retitled to
Product Specification/Technical Notes/Implementation Notes/Sources, matching uslib: the toctree shows the H1, and repeating the product name under a page already titled for the product reads badly. - Cross-document target links need no path.
[text](../uslib/index.md#uslib-one-shape)makes MyST look for a local id in that document rather than a label, and an explicit(target)=does not match. Bare#targetresolves project-wide.
The uklib run tested whether the plan's conventions were conventions; the jplib run tests
whether the tooling is. Mostly it is: every citation tool ran unmodified and every count came
out of them without an argument. What follows is the part that did not.
gen_scaffolding.py's TITLES was keyed by slug, under a comment recording the assumption:
"Slugs are unique across libraries, so one map serves both." Japan ends that. It sells a 定期保険
and a 終身保険, the honest slugs for them are term_life and whole_life, and uslib already
uses both for different products. TITLES is now keyed by (library, slug) — main had the
library name all along, derived from its argument. Verified byte-neutral: --dry-run reports
0 files on both existing libraries.
This is the first place the two-library design leaked an assumption that only a third library could falsify, and it is worth expecting others of the same shape.
§9's first item was written for two in-library suites. Three is the same fault with more ways to
land, and the fix needed no change: jp_registry.py beside us_registry.py and
uk_registry.py, with conftest.py re-exporting for its fixtures. Worth stating because the
hazard grows with each library, not with each product, and CI runs a bare pytest from the
lifelib root.
docutils lays an RST simple table out by display column, where an East Asian wide or
fullwidth character occupies two. tools/fix_docstring_tables.py measured in characters. On two
ASCII libraries the measures coincide and the tool was correct; on jplib it read a correctly
laid out table as broken, and re-laying it would have produced one that really was — a clean
build turned into Malformed table, which is the wrong direction for a repair tool to fail in.
It now measures display width throughout (width, at_column, between_columns) and reports
0 tables to re-lay on all three libraries. This is the only tool change the jplib run
required.
The build found the converse independently: two Projection docstrings really did have a cell
wider than its rule, both caught by -n -W and fixed by splitting the row across two. Only the
build is the authority here — a character-counting checker flags the wrong ones in both
directions.
Japanese in a document is fine; the pages are UTF-8 and the docstrings render. Japanese on a
Windows console is not portable across code pages, so every jplib run.py prints JPY and
USD rather than currency signs, and romanizes or glosses what it labels. Asserted by running
all nine and decoding each one's output as ASCII.
uslib takes MYGA, RILA, SPIA and ULSG from the trade's own usage, and uklib takes
CI, IP, WOL, ULB, WP and PA the same way. Japanese products have no Latin short form
in circulation, so there was nothing to borrow: jplib's names are short English descriptors —
Term_JP_S, IncomeTerm_JP_S, WholeLife_JP_S, Endowment_JP_S, Medical_JP_S,
Cancer_JP_S, LTC_JP_S, Annuity_JP_S, FXWholeLife_JP_S. jp_registry.py records that they
are chosen and why, so the next library does not re-litigate it, and it names the two that could
be misread: IncomeTerm_JP_S is 収入保障保険, a death benefit paid as an income and not
uklib's disability cover, and LTC_JP_S is private cover written on top of the public
公的介護保険 scheme rather than that scheme.
separate_citations.py reported 0 adjacencies — the drafting pass wrote [S1] [S6]
throughout rather than needing the repair afterwards; add_citation_anchors.py placed 230
product entries and 47 reference-library entries; gen_citation_links.py wrote 944
definitions across 38 documents and checked 365 source tags with none unresolved;
fix_doc_roles.py, fix_docstring_lists.py, unlink_spec_citations.py and md_lint.py each
reported 0. That is what D8's parameterization was for.
uklib's decrement bases are all [std] proxies because the CMI tables cannot be read without
a subscription. Japan's statutory tables can be read by anyone, free, at a stable public URL —
but the publisher's terms forbid redistribution. So jplib cites them, quotes the individual
rates its worked examples use, and ships [std] constructions anchored to them. The distinction
matters at merge time because it is the one claim in jplib/index.md that a reader is most
likely to over-read, and every product document, model.md and Data docstring is written to
state it the same way.