Skip to content

Interfaces and versions

interface

The semantic interface of a package version.

What dependents of a package rely on is more than the names its modules export. A PackageInterface lists one InterfaceSymbol per exported declaration, per constructor, per sample site of an exported program, and per data parameter of an exported program, each with:

  • a path, how dependents spell it (worlds.boolean.World, worlds.boolean.model.prior);
  • an identity that no spelling enters: the declaration's content hash (quivers.qiec.content_hash), a constructor's family hash and ordinal, a site's identity (quivers.dsl.modules.sites), or a data parameter's program hash and ordinal, so a renamed symbol keeps its identity;
  • facts dependents can observe, each a digest in which references to other declarations are their content hashes, so renaming a family does not change the type of a computation over it: the type (a computation's parameter and result types, a family's shape, a program's arguments), the effects row, a site's support (its family, plate, and axes), and a data parameter's index type;
  • the body, the declaration's whole content hash, which a change to a body alone moves.

qvr bump compares two interfaces symbol by symbol; the dependency lenses (quivers.packages.lenses) map one onto the other.

DATA_ROLES module-attribute

DATA_ROLES: frozenset[str] = frozenset({'data', 'observation', 'index_map'})

Program parameter roles a dependent binds to data rather than passes.

SIGNATURE_KINDS module-attribute

SIGNATURE_KINDS: frozenset[str] = frozenset({'computation', 'handler', 'program'})

Declaration kinds with a signature apart from their body: a change to the body alone keeps their interface. Any change to a declaration of another kind changes its shape, which dependents see.

InterfaceSymbol didactic-model

InterfaceSymbol(*, path: str, kind: str, module: str, identity: str, origin: str = '', type: str = '', effects: str = '', support: str = '', index: str = '', body: str = '', fitted: bool = False, display: str = '')

Bases: Model

One thing a dependent of a package can name or rely on.

ATTRIBUTE DESCRIPTION
path

How dependents spell it: the exposing module's path, then the name, then (for a site or data parameter) its label.

TYPE: str

kind

family, constructor, computation, program, ...; site:sample, site:observe, site:marginal for a site; data:<role> for a data parameter.

TYPE: str

module

The exposing module.

TYPE: str

origin

The declaring module's path and the name there, as name resolution reports it (empty for a site or data parameter).

TYPE: str

identity

The rename-stable identity.

TYPE: str

type

The digest of its type or shape.

TYPE: str

effects

The digest of its effect row (computations).

TYPE: str

support

What fixes a site's support: its family, plate, and axes.

TYPE: str

index

The digest of a data parameter's index type and axes.

TYPE: str

body

The declaration's whole content hash.

TYPE: str

fitted

For a program: whether it is fit to data (it observes, or takes data parameters).

TYPE: bool

display

How messages show it: the declaring line, or a site's family.

TYPE: str

PackageInterface didactic-model

PackageInterface(*, package: str, version: Version, symbols: tuple[InterfaceSymbol, ...] = ())

Bases: Model

The semantic interface of one package version.

ATTRIBUTE DESCRIPTION
package

The package.

TYPE: str

version

The version.

TYPE: Version

symbols

Every symbol, by path.

TYPE: tuple[InterfaceSymbol, ...]

symbol

symbol(path: str) -> InterfaceSymbol | None

The symbol at a path.

PARAMETER DESCRIPTION
path

A symbol path.

TYPE: str

RETURNS DESCRIPTION
InterfaceSymbol | None

The symbol, or None when the interface has none there.

Source code in src/quivers/packages/interface.py
def symbol(self, path: str) -> InterfaceSymbol | None:
    """The symbol at a path.

    Parameters
    ----------
    path : str
        A symbol path.

    Returns
    -------
    InterfaceSymbol | None
        The symbol, or ``None`` when the interface has none there.
    """
    for symbol in self.symbols:
        if symbol.path == path:
            return symbol
    return None

to_data

to_data() -> dict[str, object]

The interface as JSON-compatible data.

RETURNS DESCRIPTION
dict[str, object]

The package, version, and symbols.

Source code in src/quivers/packages/interface.py
def to_data(self) -> dict[str, object]:
    """The interface as JSON-compatible data.

    Returns
    -------
    dict[str, object]
        The package, version, and symbols.
    """
    return {
        "package": self.package,
        "version": self.version.render(),
        "symbols": [
            json.loads(symbol.model_dump_json()) for symbol in self.symbols
        ],
    }

package_interface

package_interface(package: str, version: Version, modules: Iterable[BuiltModule]) -> PackageInterface

The semantic interface of a package's exposed modules.

PARAMETER DESCRIPTION
package

The package's name.

TYPE: str

version

Its version.

TYPE: Version

modules

Its exposed modules, checked.

TYPE: Iterable[BuiltModule]

RETURNS DESCRIPTION
PackageInterface

Every symbol of every module, by path.

Source code in src/quivers/packages/interface.py
def package_interface(
    package: str, version: Version, modules: Iterable[BuiltModule]
) -> PackageInterface:
    """The semantic interface of a package's exposed modules.

    Parameters
    ----------
    package : str
        The package's name.
    version : Version
        Its version.
    modules : Iterable[BuiltModule]
        Its exposed modules, checked.

    Returns
    -------
    PackageInterface
        Every symbol of every module, by path.
    """
    symbols: list[InterfaceSymbol] = []
    for built in modules:
        if built.qiec is None:
            symbols.extend(_declared_only(built))
            continue
        symbols.extend(_ModuleSymbols(built, built.qiec).symbols())
    return PackageInterface(
        package=package,
        version=version,
        symbols=tuple(sorted(symbols, key=lambda symbol: symbol.path)),
    )

bump

Semantic versions computed from interface diffs.

A package's version says how a dependent is affected by moving to it, so it is computed rather than chosen [@lam2020putting]. diff_interfaces compares the interfaces of two versions (quivers.packages.interface) symbol by symbol and classifies every change:

change level
an export or sample site removed or renamed major
a type, a family's shape, a support, an effect row, or a data parameter's index type changed major
a symbol's kind changed major
a site added that must be observed, or a data parameter added major
an export added, or a sample site added (it has a default: its prior) minor
the body of an exported program fit to data changed minor
a body changed under an unchanged interface patch

The version a change needs is the old version bumped at the largest level (Version.bumped). InterfaceDiff.check refuses a proposed version that understates the change, naming every change it understates.

ChangeCategory

ChangeCategory = Literal['removed', 'renamed', 'added', 'added-site', 'kind', 'type', 'effects', 'support', 'index', 'fitted-body', 'body']

What kind of change one InterfaceChange is.

BumpError

Bases: ValueError

A proposed version that understates its interface change.

Its message says the proposed and required versions, and the changes that require more.

InterfaceChange didactic-model

InterfaceChange(*, level: ChangeLevel, category: ChangeCategory, symbol: str, renamed_to: str = '', detail: str)

Bases: Model

One change between two interfaces.

ATTRIBUTE DESCRIPTION
level

How much it moves the version.

TYPE: ChangeLevel

category

What changed.

TYPE: ChangeCategory

symbol

The symbol's old path (its new path for an addition).

TYPE: str

renamed_to

For a rename, the new path.

TYPE: str

detail

A sentence describing the change.

TYPE: str

render

render() -> str

The change as one line.

RETURNS DESCRIPTION
str

level symbol: detail.

Source code in src/quivers/packages/bump.py
def render(self) -> str:
    """The change as one line.

    Returns
    -------
    str
        ``level  symbol: detail``.
    """
    return f"{self.level:<5}  {self.symbol}: {self.detail}"

InterfaceDiff didactic-model

InterfaceDiff(*, package: str, old_version: Version, changes: tuple[InterfaceChange, ...] = (), lens: DependencyLens)

Bases: Model

The changes from one version of a package's interface to another.

ATTRIBUTE DESCRIPTION
package

The package.

TYPE: str

old_version

The version compared against.

TYPE: Version

changes

Every change, by symbol.

TYPE: tuple[InterfaceChange, ...]

lens

The lens dependents migrate along.

TYPE: DependencyLens

level property

level: ChangeLevel

The largest change.

RETURNS DESCRIPTION
ChangeLevel

none when nothing changed.

required

required() -> Version

The smallest version that publishes the change.

RETURNS DESCRIPTION
Version

The old version bumped at the largest change's level.

Source code in src/quivers/packages/bump.py
def required(self) -> Version:
    """The smallest version that publishes the change.

    Returns
    -------
    Version
        The old version bumped at the largest change's level.
    """
    return self.old_version.bumped(self.level)

check

check(proposed: Version) -> None

Refuse a version that understates the change.

PARAMETER DESCRIPTION
proposed

The version to publish.

TYPE: Version

RAISES DESCRIPTION
BumpError

If proposed is below the required version, or does not follow the old version although something changed.

Source code in src/quivers/packages/bump.py
def check(self, proposed: Version) -> None:
    """Refuse a version that understates the change.

    Parameters
    ----------
    proposed : Version
        The version to publish.

    Raises
    ------
    BumpError
        If ``proposed`` is below the required version, or does not
        follow the old version although something changed.
    """
    required = self.required()
    if self.level == "none":
        return
    if proposed.key() <= self.old_version.key():
        raise BumpError(
            f"{self.package} {proposed.render()} does not follow "
            f"{self.old_version.render()}, but the interface changed; publish "
            f"{required.render()} or later"
        )
    if proposed.key() < required.key():
        published = self.old_version.level_to(proposed)
        understated = [
            change
            for change in self.changes
            if CHANGE_LEVELS.index(change.level) > CHANGE_LEVELS.index(published)
        ]
        raise BumpError(
            f"{self.package} {proposed.render()} understates the change from "
            f"{self.old_version.render()}: it is a {self.level} change, so the "
            f"version must be at least {required.render()}:\n"
            + "\n".join(f"  {change.render()}" for change in understated)
        )

diff_interfaces

diff_interfaces(old: PackageInterface, new: PackageInterface) -> InterfaceDiff

Classify every change from one interface to another.

PARAMETER DESCRIPTION
old

The interface compared against.

TYPE: PackageInterface

new

The new interface.

TYPE: PackageInterface

RETURNS DESCRIPTION
InterfaceDiff

The changes and the lens dependents migrate along.

RAISES DESCRIPTION
LensError

If panproto cannot derive the lens.

Source code in src/quivers/packages/bump.py
def diff_interfaces(old: PackageInterface, new: PackageInterface) -> InterfaceDiff:
    """Classify every change from one interface to another.

    Parameters
    ----------
    old : PackageInterface
        The interface compared against.
    new : PackageInterface
        The new interface.

    Returns
    -------
    InterfaceDiff
        The changes and the lens dependents migrate along.

    Raises
    ------
    LensError
        If panproto cannot derive the lens.
    """
    lens = DependencyLens.between(old, new)
    changes: list[InterfaceChange] = []
    for rename in lens.renames:
        changes.append(
            InterfaceChange(
                level="major",
                category="renamed",
                symbol=rename.old,
                renamed_to=rename.new,
                detail=f"the {rename.kind} was renamed to {rename.new}; dependents "
                "migrate along the lens",
            )
        )
    for path in lens.removed:
        symbol = old.symbol(path)
        kind = symbol.kind if symbol is not None else "symbol"
        changes.append(
            InterfaceChange(
                level="major",
                category="removed",
                symbol=path,
                detail=f"the {kind} was removed with no replacement",
            )
        )
    for path in lens.added:
        symbol = new.symbol(path)
        assert symbol is not None
        changes.append(_added(symbol))
    for symbol in old.symbols:
        target = lens.image(symbol.path)
        if target is None:
            continue
        counterpart = new.symbol(target)
        if counterpart is None:
            continue
        facts = _facts(symbol, counterpart)
        for category, detail in facts:
            changes.append(
                InterfaceChange(
                    level="major", category=category, symbol=symbol.path, detail=detail
                )
            )
        if facts or symbol.body == counterpart.body:
            continue
        if symbol.kind.startswith(("site:", "data:")):
            # A site or data parameter follows its program, whose own body
            # change is reported once, on the program.
            continue
        if symbol.fitted or counterpart.fitted:
            changes.append(
                InterfaceChange(
                    level="minor",
                    category="fitted-body",
                    symbol=symbol.path,
                    detail="the body of a program fit to data changed, so fits of "
                    "it change meaning",
                )
            )
        else:
            changes.append(
                InterfaceChange(
                    level="patch",
                    category="body",
                    symbol=symbol.path,
                    detail="its body changed under the same interface",
                )
            )
    return InterfaceDiff(
        package=new.package,
        old_version=old.version,
        changes=tuple(
            sorted(changes, key=lambda change: (change.symbol, change.category))
        ),
        lens=lens,
    )

release

Releasing package versions: interfaces, version bumps, lenses, publishing.

package_version_interface checks a package's exposed modules and computes its semantic interface. previous_version finds the version to compare against: a directory, or a git revision of the repository holding the package (extracted into the project cache). bump diffs the two interfaces and, when the change is breaking, writes the dependency lens into the package's lenses/ directory, where qvr migrate --dependency finds it in the new version's source. publish adds a version to an index repository, refusing a version that understates its change from the newest version the index already lists.

LENS_DIRECTORY module-attribute

LENS_DIRECTORY = 'lenses'

Where a package keeps the lenses its breaking releases emit.

ReleaseError

Bases: ValueError

A release that cannot be made.

Its message says what prevents it.

VersionInterface didactic-model

VersionInterface(*, interface: PackageInterface, modules: tuple[BuiltModule, ...] = ())

Bases: Model

A package version's interface and the modules it was computed from.

ATTRIBUTE DESCRIPTION
interface

The interface.

TYPE: PackageInterface

modules

Its exposed modules, checked.

TYPE: tuple[BuiltModule, ...]

lens_file

lens_file(package: str, old: Version, new: Version) -> str

The file name a lens between two versions is emitted under.

PARAMETER DESCRIPTION
package

The package.

TYPE: str

old

The versions.

TYPE: Version

new

The versions.

TYPE: Version

RETURNS DESCRIPTION
str

<package>-<old>-to-<new>.json.

Source code in src/quivers/packages/release.py
def lens_file(package: str, old: Version, new: Version) -> str:
    """The file name a lens between two versions is emitted under.

    Parameters
    ----------
    package : str
        The package.
    old, new : Version
        The versions.

    Returns
    -------
    str
        ``<package>-<old>-to-<new>.json``.
    """
    return f"{package}-{old.render()}-to-{new.render()}.json"

package_version_interface

package_version_interface(directory: Path, cache: GitCache) -> VersionInterface

Check a package's exposed modules and compute its interface.

PARAMETER DESCRIPTION
directory

The package's directory.

TYPE: Path

cache

The cache its git and indexed dependencies are read through.

TYPE: GitCache

RETURNS DESCRIPTION
VersionInterface

The interface and the checked modules.

RAISES DESCRIPTION
ManifestError

If the manifest is malformed.

ResolutionError

If its dependencies do not resolve.

PackageError

If a module violates a package rule.

ModuleError

If a module does not load or resolve.

CompileError

If a module does not compile.

Source code in src/quivers/packages/release.py
def package_version_interface(directory: Path, cache: GitCache) -> VersionInterface:
    """Check a package's exposed modules and compute its interface.

    Parameters
    ----------
    directory : Path
        The package's directory.
    cache : GitCache
        The cache its git and indexed dependencies are read through.

    Returns
    -------
    VersionInterface
        The interface and the checked modules.

    Raises
    ------
    ManifestError
        If the manifest is malformed.
    ResolutionError
        If its dependencies do not resolve.
    PackageError
        If a module violates a package rule.
    ModuleError
        If a module does not load or resolve.
    CompileError
        If a module does not compile.
    """
    workspace = Workspace(directory, cache=cache)
    resolution = workspace.resolve()
    return _interface(workspace, resolution)

repository_of

repository_of(directory: Path) -> tuple[Path, str]

The git repository holding a directory, and the directory's place in it.

PARAMETER DESCRIPTION
directory

A directory inside a git working tree.

TYPE: Path

RETURNS DESCRIPTION
tuple[Path, str]

The working tree's top and the directory relative to it (POSIX).

RAISES DESCRIPTION
GitError

If the directory is in no git working tree.

Source code in src/quivers/packages/release.py
def repository_of(directory: Path) -> tuple[Path, str]:
    """The git repository holding a directory, and the directory's place in it.

    Parameters
    ----------
    directory : Path
        A directory inside a git working tree.

    Returns
    -------
    tuple[Path, str]
        The working tree's top and the directory relative to it (POSIX).

    Raises
    ------
    GitError
        If the directory is in no git working tree.
    """
    top = Path(
        run_git(["rev-parse", "--show-toplevel"], cwd=directory).decode("utf-8").strip()
    )
    relative = directory.resolve().relative_to(top.resolve()).as_posix()
    return top, relative

previous_version

previous_version(directory: Path, against: str, cache: GitCache) -> Path

The directory of the package version to compare against.

PARAMETER DESCRIPTION
directory

The package's current directory.

TYPE: Path

against

A directory holding the previous version, or a git revision (a tag such as v1.2.0, a branch, a commit) of the repository holding the package.

TYPE: str

cache

Where a revision is extracted.

TYPE: GitCache

RETURNS DESCRIPTION
Path

The previous version's package directory.

RAISES DESCRIPTION
GitError

If against is no directory and names no revision of the package's repository.

ReleaseError

If the revision has no manifest at the package's place.

Source code in src/quivers/packages/release.py
def previous_version(directory: Path, against: str, cache: GitCache) -> Path:
    """The directory of the package version to compare against.

    Parameters
    ----------
    directory : Path
        The package's current directory.
    against : str
        A directory holding the previous version, or a git revision (a tag
        such as ``v1.2.0``, a branch, a commit) of the repository holding
        the package.
    cache : GitCache
        Where a revision is extracted.

    Returns
    -------
    Path
        The previous version's package directory.

    Raises
    ------
    GitError
        If ``against`` is no directory and names no revision of the
        package's repository.
    ReleaseError
        If the revision has no manifest at the package's place.
    """
    candidate = Path(against)
    if candidate.is_dir():
        return candidate.resolve()
    top, relative = repository_of(directory)
    url = top.resolve().as_uri()
    commit = cache.resolve(url, against)
    tree = cache.checkout(url, commit)
    package = tree / relative
    if not (package / MANIFEST_NAME).is_file():
        raise ReleaseError(
            f"{against} ({commit[:12]}) of {top} has no {MANIFEST_NAME} at "
            f"{relative}: the package did not exist there"
        )
    return package

bump

bump(directory: Path, against: Path, cache: GitCache, *, proposed: Version | None = None, write: bool = False, emit_lens: bool = True) -> InterfaceDiff

Diff a package against a previous version and check its version.

PARAMETER DESCRIPTION
directory

The package's directory.

TYPE: Path

against

The previous version's directory.

TYPE: Path

cache

The project cache.

TYPE: GitCache

proposed

The version to publish; the manifest's version when it differs from the previous one.

TYPE: Version | None DEFAULT: None

write

Write the required version into the manifest when the manifest still has the previous version.

TYPE: bool DEFAULT: False

emit_lens

Write the dependency lens of a breaking change into lenses/.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
InterfaceDiff

The classified changes.

RAISES DESCRIPTION
BumpError

If the proposed version understates the change.

ReleaseError

If the previous version is another package.

Source code in src/quivers/packages/release.py
def bump(
    directory: Path,
    against: Path,
    cache: GitCache,
    *,
    proposed: Version | None = None,
    write: bool = False,
    emit_lens: bool = True,
) -> InterfaceDiff:
    """Diff a package against a previous version and check its version.

    Parameters
    ----------
    directory : Path
        The package's directory.
    against : Path
        The previous version's directory.
    cache : GitCache
        The project cache.
    proposed : Version | None
        The version to publish; the manifest's version when it differs
        from the previous one.
    write : bool
        Write the required version into the manifest when the manifest
        still has the previous version.
    emit_lens : bool
        Write the dependency lens of a breaking change into ``lenses/``.

    Returns
    -------
    InterfaceDiff
        The classified changes.

    Raises
    ------
    BumpError
        If the proposed version understates the change.
    ReleaseError
        If the previous version is another package.
    """
    old = package_version_interface(against, cache).interface
    new = package_version_interface(directory, cache).interface
    if old.package != new.package:
        raise ReleaseError(f"{against} holds package {old.package}, not {new.package}")
    diff = diff_interfaces(old, new)
    manifest_version = new.version
    candidate = proposed
    if candidate is None and manifest_version != old.version:
        candidate = manifest_version
    if candidate is not None:
        diff.check(candidate)
    elif write and diff.level != "none":
        set_manifest_version(directory, diff.required())
        candidate = diff.required()
    if emit_lens and diff.level == "major":
        target = candidate if candidate is not None else diff.required()
        lens = diff.lens.with_(new_version=target)
        folder = directory / LENS_DIRECTORY
        folder.mkdir(exist_ok=True)
        (folder / lens_file(new.package, old.version, target)).write_text(
            lens.to_json() + "\n", encoding="utf-8"
        )
    return diff

set_manifest_version

set_manifest_version(directory: Path, version: Version) -> None

Rewrite the version in a manifest, leaving the rest of it as written.

PARAMETER DESCRIPTION
directory

The package's directory.

TYPE: Path

version

The new version.

TYPE: Version

RAISES DESCRIPTION
ManifestError

If the manifest has no version line in its [package] table.

Source code in src/quivers/packages/release.py
def set_manifest_version(directory: Path, version: Version) -> None:
    """Rewrite the version in a manifest, leaving the rest of it as written.

    Parameters
    ----------
    directory : Path
        The package's directory.
    version : Version
        The new version.

    Raises
    ------
    ManifestError
        If the manifest has no version line in its [package] table.
    """
    path = directory / MANIFEST_NAME
    text = path.read_text(encoding="utf-8")
    package_start = text.find("[package]")
    following = text.find("\n[", package_start + 1)
    end = len(text) if following < 0 else following
    section = text[package_start:end]
    match = _VERSION_LINE.search(section)
    if package_start < 0 or match is None:
        raise ManifestError(f"{path}: [package] has no version line to rewrite")
    updated = section[: match.start(2)] + version.render() + section[match.end(2) :]
    path.write_text(text[:package_start] + updated + text[end:], encoding="utf-8")
    read_manifest(directory)

publish

publish(index_checkout: Path, url: str, revision: str, cache: GitCache) -> IndexEntry

Add a package version to an index.

The version is read from a commit of its repository, so what is published is exactly what dependents will fetch. Its modules are checked and pinned; its interface is compared with the newest version the index lists, and a version that understates the change, or that the index already lists, is refused. The entry is written into the index checkout and committed there; pushing it is left to the caller.

PARAMETER DESCRIPTION
index_checkout

A git working tree of the index repository.

TYPE: Path

url

The package's repository.

TYPE: str

revision

The commit, tag, or branch to publish.

TYPE: str

cache

The project cache.

TYPE: GitCache

RETURNS DESCRIPTION
IndexEntry

The published entry.

RAISES DESCRIPTION
ReleaseError

If the package depends on anything but packages of this index, or the version is already published.

BumpError

If the version understates its change.

GitError

If a repository cannot be read or the commit cannot be made.

Source code in src/quivers/packages/release.py
def publish(
    index_checkout: Path,
    url: str,
    revision: str,
    cache: GitCache,
) -> IndexEntry:
    """Add a package version to an index.

    The version is read from a commit of its repository, so what is
    published is exactly what dependents will fetch. Its modules are
    checked and pinned; its interface is compared with the newest version
    the index lists, and a version that understates the change, or that
    the index already lists, is refused. The entry is written into the
    index checkout and committed there; pushing it is left to the caller.

    Parameters
    ----------
    index_checkout : Path
        A git working tree of the index repository.
    url : str
        The package's repository.
    revision : str
        The commit, tag, or branch to publish.
    cache : GitCache
        The project cache.

    Returns
    -------
    IndexEntry
        The published entry.

    Raises
    ------
    ReleaseError
        If the package depends on anything but packages of this index, or
        the version is already published.
    BumpError
        If the version understates its change.
    GitError
        If a repository cannot be read or the commit cannot be made.
    """
    commit = cache.resolve(url, revision)
    directory = cache.checkout(url, commit)
    manifest = read_manifest(directory)
    index_url = (
        run_git(["config", "--get", "remote.origin.url"], cwd=index_checkout)
        .decode("utf-8")
        .strip()
    )
    for dependency in manifest.dependencies:
        source = dependency.source
        if not isinstance(source, IndexSource):
            raise ReleaseError(
                f"{manifest.name} depends on {dependency.name} through "
                f"{source.kind}; a published package depends only on packages of "
                "its index, so every dependent can resolve it"
            )
        if not same_repository(manifest.index_url(source.index), index_url):
            raise ReleaseError(
                f"{manifest.name} depends on {dependency.name} from "
                f"{manifest.index_url(source.index)}, not from this index "
                f"({index_url})"
            )
    current = Workspace(directory, cache=cache)
    resolution = current.resolve()
    built = _interface(current, resolution)
    local = (
        PackageIndex(
            "publishing",
            index_checkout.resolve().as_uri(),
            run_git(["rev-parse", "HEAD"], cwd=index_checkout).decode("ascii").strip(),
            GitCache(cache.directory),
        )
        if _has_commits(index_checkout)
        else None
    )
    versions = local.versions(manifest.name) if local is not None else ()
    if manifest.version in versions:
        raise ReleaseError(
            f"the index already lists {manifest.name} {manifest.version.render()}; "
            "a published version never changes"
        )
    earlier = [
        version for version in versions if version.key() < manifest.version.key()
    ]
    if earlier and local is not None:
        previous = local.entry(manifest.name, earlier[-1])
        old_directory = cache.checkout(previous.url, previous.commit)
        old = package_version_interface(old_directory, cache).interface
        diff_interfaces(old, built.interface).check(manifest.version)
    entry = IndexEntry(
        name=manifest.name,
        version=manifest.version,
        url=url,
        commit=commit,
        dependencies=tuple(
            IndexRequirement(name=dependency.name, minimum=dependency.source.minimum)
            for dependency in manifest.dependencies
            if isinstance(dependency.source, IndexSource)
        ),
        modules=tuple(module.pin() for module in built.modules),
    )
    target = index_checkout / entry_path(entry.name, entry.version)
    target.parent.mkdir(parents=True, exist_ok=True)
    target.write_text(render_entry(entry), encoding="utf-8")
    relative = target.relative_to(index_checkout).as_posix()
    run_git(["add", "--", relative], cwd=index_checkout)
    run_git(
        [
            "commit",
            "--quiet",
            "-m",
            f"publish {entry.name} {entry.version.render()}",
            "--",
            relative,
        ],
        cwd=index_checkout,
    )
    return entry

read_emitted_lens

read_emitted_lens(directory: Path, package: str, old: Version, new: Version) -> DependencyLens | None

The lens a package version emitted for its move from an older one.

PARAMETER DESCRIPTION
directory

The new version's package directory.

TYPE: Path

package

The package.

TYPE: str

old

The versions.

TYPE: Version

new

The versions.

TYPE: Version

RETURNS DESCRIPTION
DependencyLens | None

The emitted lens, or None when the version emitted none.

Source code in src/quivers/packages/release.py
def read_emitted_lens(
    directory: Path, package: str, old: Version, new: Version
) -> DependencyLens | None:
    """The lens a package version emitted for its move from an older one.

    Parameters
    ----------
    directory : Path
        The new version's package directory.
    package : str
        The package.
    old, new : Version
        The versions.

    Returns
    -------
    DependencyLens | None
        The emitted lens, or ``None`` when the version emitted none.
    """
    path = directory / LENS_DIRECTORY / lens_file(package, old, new)
    if not path.is_file():
        return None
    return DependencyLens.from_json(path.read_text(encoding="utf-8"))