Repository navigation
Build each load into a Corpus that load() returns, handed explicitly everywhere - #145
Merged
Merged
Conversation
…everywhere The loader kept its records in class-level registries (`Author._authors`, `Source._sources`, `Taxon._taxa`, `Section._sections` and the rest), an index every `Tree` root wrote (`_new_index`), a repository registry in `material.py` and a rank-hub cache in `claims.py` that went stale when a taxon was added. `load()` filled them as a side effect and returned `(data, roots)`; a second load in one process overwrote and leaked; the extractor and the claims script read the private dicts; and the tests snapshotted and restored all of them by hand before every test. `phylohist/loader/corpus.py` holds the `Corpus`: the five record dicts in insertion order, the repositories, the raw data and the roots, with `add_*` methods that build a record against the corpus and then store it (a constructor that ends the load stores nothing), `copy()` for a test's own view, and `protologue_sources()` walked from the roots in place of the index. Every constructor takes the corpus it resolves records in; a root `Tree` takes it beside its metadata and its nodes share it; no record keeps a reference to its corpus, and `Source.publication` is resolved where the record is built. `load()` builds a fresh corpus per call and returns it; the loader's own checks, the extractor (`extract`, `manifest`, `names_index`, `rank_variants`, `holotype_conflicts`) and the claims script take it as their first argument, and `claims.py` imports no record class and keeps nothing between calls. The tests take `records`, a per-test copy of the session corpus, in place of the restored registries; `support.with_documents` gives a loader check its synthetic documents, and an autouse guard fails a test that changes the session corpus. The three autouse registry fixtures and the snapshot machinery are gone. The claims, the names index, the manifest and the repositories file are byte-identical, as is the loader's log over the data and drafts. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The loader kept its records in class-level registries (
Author._authors,Source._sources,Taxon._taxa,Section._sectionsand the rest), an index everyTreeroot wrote (_new_index), a repository registry inmaterial.pyand a rank-hub cache inclaims.pythat went stale when a taxon was added.load()filled them as a side effect and returned(data, roots); a second load in one process overwrote and leaked; the extractor and the claims script read the private dicts; and the tests snapshotted and restored all of them by hand before every test.phylohist/loader/corpus.pyholds theCorpus: the five record dicts in insertion order, the repositories, the raw data and the roots, withadd_*methods that build a record against the corpus and then store it (a constructor that ends the load stores nothing),copy()for a test's own view, andprotologue_sources()walked from the roots in place of the index. Every constructor takes the corpus it resolves records in; a rootTreetakes it beside its metadata and its nodes share it; no record keeps a reference to its corpus, andSource.publicationis resolved where the record is built.load()builds a fresh corpus per call and returns it; the loader's own checks, the extractor (extract,manifest,names_index,rank_variants,holotype_conflicts) and the claims script take it as their first argument, andclaims.pyimports no record class and keeps nothing between calls.The tests take
records, a per-test copy of the session corpus, in place of the restored registries;support.with_documentsgives a loader check its synthetic documents, and an autouse guard fails a test that changes the session corpus. The three autouse registry fixtures and the snapshot machinery are gone.The claims, the names index, the manifest and the repositories file are byte-identical, as is the loader's log over the data and drafts.