Dependency lenses¶
lenses
¶
Dependency lenses: how a package's interface change maps its dependents.
When a package moves from one version to another, every dependent module and
every stored run record that names one of its symbols must follow. A
DependencyLens describes the move in panproto's terms [@foster2007combinators;
@litt2020cambria]:
- each interface is an inventory, a panproto schema (in the
json-schemaprotocol) with one vertex per symbol, and a dependent's usage is an instance of it: each symbol the dependent names, with the places it names it; - a rename is a symbol whose identity (
quivers.packages.interface) the new interface keeps under a new path; the renames form a theory morphismphifrom the old inventory's theory to the new one's; - the residual chain is
diff_to_protolensof the old inventory and the new inventory spelled in old names, so it holds exactly the symbols that were removed (with no image underphi) and the ones that were added; - the chain is lifted along
phi(lift_protolens) and applied to the usages of every dependent at once (apply_to_fleet). Getting a usage through the lens drops exactly the places that name a removed symbol: the lens's complement lists every place no lens reaches, so nothing is dropped silently.
A place the lens keeps is renamed to the image of its symbol under phi.
INVENTORY_PROTOCOL
module-attribute
¶
The panproto protocol inventories and usages are written in.
LensError
¶
Bases: ValueError
A lens that cannot be built or applied.
Its message says what failed.
Rename
didactic-model
¶
Bases: Model
A symbol the new interface keeps under another path.
| ATTRIBUTE | DESCRIPTION |
|---|---|
old |
Its old path.
TYPE:
|
new |
Its new path.
TYPE:
|
kind |
Its kind.
TYPE:
|
Use
didactic-model
¶
Bases: Model
One place a dependent names a symbol.
| ATTRIBUTE | DESCRIPTION |
|---|---|
symbol |
The symbol's old path.
TYPE:
|
place |
Where (a key the dependent understands: a byte span of a module, or a site key of a run record).
TYPE:
|
Unmigratable
didactic-model
¶
Unmigratable(*, use: Use, reason: str)
Bases: Model
A place no lens reaches.
| ATTRIBUTE | DESCRIPTION |
|---|---|
use |
The place.
TYPE:
|
reason |
Why: the symbol was removed with no replacement, or the dependent's usage did not satisfy the lens.
TYPE:
|
RenamedUse
didactic-model
¶
RenamedUse(*, use: Use, new: str)
Bases: Model
A kept place and its symbol's new path.
| ATTRIBUTE | DESCRIPTION |
|---|---|
use |
The place.
TYPE:
|
new |
The symbol's path in the new interface.
TYPE:
|
MemberOutcome
didactic-model
¶
MemberOutcome(*, member: str, renames: tuple[RenamedUse, ...] = (), unmigratable: tuple[Unmigratable, ...] = ())
Bases: Model
What a lens does to one dependent.
| ATTRIBUTE | DESCRIPTION |
|---|---|
member |
The dependent.
TYPE:
|
renames |
Each kept place with its symbol's new path.
TYPE:
|
unmigratable |
Each place no lens reaches.
TYPE:
|
DependencyLens
didactic-model
¶
DependencyLens(*, package: str, old_version: Version, new_version: Version, renames: tuple[Rename, ...] = (), removed: tuple[str, ...] = (), added: tuple[str, ...] = (), old_paths: tuple[str, ...] = (), chain: str = '', morphism: str = '')
Bases: Model
The lens from one version of a package's interface to another.
| ATTRIBUTE | DESCRIPTION |
|---|---|
package |
The package.
TYPE:
|
old_version, new_version |
The versions.
TYPE:
|
renames |
The symbols kept under new paths, by old path.
TYPE:
|
removed |
The old paths with no image.
TYPE:
|
added |
The new paths no old symbol maps to.
TYPE:
|
old_paths |
Every old path.
TYPE:
|
chain |
The residual protolens chain, as panproto's JSON.
TYPE:
|
morphism |
The renaming theory morphism, as panproto's JSON.
TYPE:
|
between
classmethod
¶
between(old: PackageInterface, new: PackageInterface) -> DependencyLens
The lens from an old interface to a new one.
| PARAMETER | DESCRIPTION |
|---|---|
old
|
The interfaces.
TYPE:
|
new
|
The interfaces.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DependencyLens
|
The renames, the residual chain, and the renaming morphism. |
| RAISES | DESCRIPTION |
|---|---|
LensError
|
If panproto cannot derive the residual chain. |
Source code in src/quivers/packages/lenses.py
image
¶
Where an old symbol is in the new interface.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
An old symbol path.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
Its new path, or |
Source code in src/quivers/packages/lenses.py
is_identity
¶
Whether the lens renames, removes, and adds nothing.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether dependents need no change. |
apply
¶
apply(fleet: Mapping[str, tuple[Use, ...]]) -> tuple[MemberOutcome, ...]
Apply the lens to the usages of every dependent at once.
The residual chain is fused, lifted along the renaming morphism, and applied to each dependent's usage schema; each usage is read through the lens it instantiates, and the places its complement holds are the ones no lens reaches. With no residual change, the morphism alone maps every place.
| PARAMETER | DESCRIPTION |
|---|---|
fleet
|
Each dependent's places, by name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[MemberOutcome, ...]
|
Each dependent's renamed and unmigratable places, by name. |
| RAISES | DESCRIPTION |
|---|---|
LensError
|
If a use names a symbol the old interface does not have. |
Source code in src/quivers/packages/lenses.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
to_json
¶
The lens as the JSON document qvr bump emits.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Canonical JSON. |
from_json
classmethod
¶
from_json(text: str) -> DependencyLens
Read an emitted lens.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
What
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DependencyLens
|
The lens. |
Source code in src/quivers/packages/lenses.py
inventory_schema
¶
inventory_schema(interface: PackageInterface) -> Schema
The inventory of an interface: one vertex per symbol.
| PARAMETER | DESCRIPTION |
|---|---|
interface
|
The interface.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Schema
|
A |
Source code in src/quivers/packages/lenses.py
migration
¶
Migrating dependents and stored runs across a dependency's interface change.
qvr migrate --dependency pkg@old..new moves a package's own modules and
its stored run records from one version of a dependency to another:
- the locked build supplies the old version and the manifest the new one;
- the dependency lens (
quivers.packages.lenses.DependencyLens) is the one the new version emitted (lenses/in its source), or is computed from the two versions' interfaces; - every module of the package is a member of the fleet: its usage is each place it names a symbol of the dependency, found by name resolution against the old build. The lens maps each place to the symbol's new path, or reports it as unmigratable, with its location, when the symbol was removed;
- a module whose places all map is rewritten by the grammar migration
chain's own machinery (
quivers.cli.migrations._features.migrate_with): token-local edits of each name's own segment, checked for overlaps, trailing whitespace, and a clean parse of the result. The result is then resolved against the new build, and a module in which a new name would resolve to anything but the renamed symbol is refused; - a run record is migrated by the same lens construction over the sites of its program: the old site table is the record's, the new one is the migrated program's, sites correspond by their rename-stable identities, and a stored site whose identity the new program lacks is reported unmigratable.
A dependency lens renames; it never changes what a declaration means, so a migrated module has the same content hashes against the new dependency as the original against the old one.
DependencyMigrationError
¶
Bases: ValueError
A dependency migration that cannot start.
Its message says why.
SiteReport
didactic-model
¶
Bases: Model
A place a dependency migration could not migrate.
| ATTRIBUTE | DESCRIPTION |
|---|---|
file |
The module file or run record.
TYPE:
|
line, column |
Where (0 for a run record's site).
TYPE:
|
symbol |
The dependency's symbol the place names.
TYPE:
|
reason |
Why no lens reaches it.
TYPE:
|
render
¶
The report as one diagnostic line.
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/packages/migration.py
MigratedFile
didactic-model
¶
Bases: Model
One file a dependency migration rewrites.
| ATTRIBUTE | DESCRIPTION |
|---|---|
path |
The file.
TYPE:
|
text |
Its migrated text.
TYPE:
|
changed |
Whether the text differs from the file's.
TYPE:
|
DependencyMigration
didactic-model
¶
DependencyMigration(*, lens: DependencyLens, files: tuple[MigratedFile, ...] = (), unmigratable: tuple[SiteReport, ...] = ())
Bases: Model
The outcome of migrating a package's dependents of one dependency.
| ATTRIBUTE | DESCRIPTION |
|---|---|
lens |
The lens applied.
TYPE:
|
files |
Every module and run record that migrated, by path.
TYPE:
|
unmigratable |
Every place no lens reaches, by file and position; a file with such a place is not rewritten.
TYPE:
|
write
¶
Write every migrated file that changed.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The paths written. |
Source code in src/quivers/packages/migration.py
DependencyMigrator
¶
Migrate one package's modules and run records across a dependency change.
| PARAMETER | DESCRIPTION |
|---|---|
workspace
|
The dependent package.
TYPE:
|
dependency
|
The dependency's name.
TYPE:
|
old
|
The version the package is locked to.
TYPE:
|
new
|
The version its manifest now resolves to.
TYPE:
|
Source code in src/quivers/packages/migration.py
modules
¶
The package's own modules, which the migration covers.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
Their paths. |
migrate
¶
migrate(records: Iterable[Path] = ()) -> DependencyMigration
Migrate every module of the package and the given run records.
| PARAMETER | DESCRIPTION |
|---|---|
records
|
Run records (
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DependencyMigration
|
The migrated texts and every unmigratable place. |
| RAISES | DESCRIPTION |
|---|---|
DependencyMigrationError
|
If the migration cannot start. |
MigrationError
|
If a rewritten module does not parse. |
Source code in src/quivers/packages/migration.py
migrate_record
¶
migrate_record(record: Path, migrated: Mapping[str, str]) -> tuple[MigratedFile | None, tuple[SiteReport, ...]]
Migrate one run record of one of the package's programs.
| PARAMETER | DESCRIPTION |
|---|---|
record
|
The record, as
TYPE:
|
migrated
|
The package's migrated module texts, by path.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[MigratedFile | None, tuple[SiteReport, ...]]
|
The migrated record ( |
| RAISES | DESCRIPTION |
|---|---|
DependencyMigrationError
|
If the record is not a run record of one of the package's programs. |
Source code in src/quivers/packages/migration.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
file_resolutions
¶
file_resolutions(graph: ModuleGraph) -> tuple[Resolution, ...]
Every name resolution of a graph's root file, module bodies included.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
A graph rooted at a file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Resolution, ...]
|
The root module's resolutions, then those of the modules, signatures, and templates declared in it. |