Workspaces¶
workspace
¶
Building a package and its dependencies.
A Workspace is a root package (the directory holding qvr.toml) and the
build its manifest resolves to. It provides:
PackageLoader, which finds a module path in the package whose name is its first segment, so every module of the build is found without search roots;- the visibility rule: a module imports the modules of its own package, and the exposed modules of the packages its package depends on; any other import is refused, naming the import;
- the link set: every package's default links, overridden by the root
manifest's
[links]; Workspace.lock, which resolves the manifest afresh, checks every module of every package, and writesqvr.lockwith each module's content hashes;Workspace.build, which resolves against the lockfile (offline once the pinned commits are cached), refuses a lockfile the manifest has moved away from, refuses any module whose hashes differ from their pins, and checks every module of the root package.
PackageErrorCode
¶
PackageErrorCode = Literal['package-module-private', 'package-not-a-dependency', 'package-module-outside', 'package-hole-unlisted', 'package-hole-unknown', 'package-link-conflict', 'package-pin-mismatch', 'package-lock-stale', 'package-module-missing']
The codes a package diagnostic carries.
PackageError
¶
PackageError(code: PackageErrorCode, message: str, location: SourceLocation | None = None)
Bases: ValueError
A build that violates a package rule or disagrees with its pins.
| PARAMETER | DESCRIPTION |
|---|---|
code
|
The stable code.
TYPE:
|
message
|
What is wrong.
TYPE:
|
location
|
Where, when the refusal points at source.
TYPE:
|
Source code in src/quivers/packages/workspace.py
PackageLoader
¶
PackageLoader(packages: Iterable[Package])
Find a module in the package its path's first segment names.
| PARAMETER | DESCRIPTION |
|---|---|
packages
|
Every package of the build.
TYPE:
|
Source code in src/quivers/packages/workspace.py
find
¶
find(path: tuple[str, ...]) -> tuple[ModuleSource, ...]
The source of a module path, from its package.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The module path's segments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ModuleSource, ...]
|
The module's source, or nothing when no package of the build provides it. |
Source code in src/quivers/packages/workspace.py
available
¶
Every module the build's packages provide.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The dotted paths, sorted. |
Source code in src/quivers/packages/workspace.py
package_of
¶
package_of(path: tuple[str, ...]) -> Package | None
The package providing a module path.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The module path's segments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Package | None
|
The package named by its first segment, if the build has one. |
Source code in src/quivers/packages/workspace.py
BuiltModule
didactic-model
¶
BuiltModule(*, path: str, package: str, interface: ModuleInterface, core: str, holes: tuple[str, ...] = (), qiec: QiecModule | None = field(opaque=True, extras=OPAQUE_BY_VALUE), flat: FlatProgram = field(opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
One module of a package, checked.
| ATTRIBUTE | DESCRIPTION |
|---|---|
path |
The module's path.
TYPE:
|
package |
Its package's name.
TYPE:
|
interface |
Its public interface.
TYPE:
|
core |
The hash of its checked declarations.
TYPE:
|
qiec |
The checked core of its flat program (or, for a module that needs
unfilled holes, of its checking program);
TYPE:
|
flat |
Its flat program.
TYPE:
|
holes |
The holes its graph has that modules of its own package declare.
TYPE:
|
Workspace
¶
Workspace(root: Path, *, cache: GitCache | None = None, standard_library_root: Path = STANDARD_LIBRARY_ROOT)
A root package and its build.
| PARAMETER | DESCRIPTION |
|---|---|
root
|
The root package's directory.
TYPE:
|
cache
|
The git cache; the project's own (
TYPE:
|
standard_library_root
|
Where the standard library's modules are.
TYPE:
|
Source code in src/quivers/packages/workspace.py
discover
classmethod
¶
discover(start: Path, *, cache: GitCache | None = None, standard_library_root: Path = STANDARD_LIBRARY_ROOT) -> Workspace
The workspace of the package containing a path.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
A file or directory inside the package.
TYPE:
|
cache
|
The git cache, as for the constructor.
TYPE:
|
standard_library_root
|
Where the standard library's modules are.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Workspace
|
The workspace. |
| RAISES | DESCRIPTION |
|---|---|
ManifestError
|
If no directory at or above |
Source code in src/quivers/packages/workspace.py
resolve
¶
resolve(*, locked: Lockfile | None = None) -> Resolution
Resolve the root manifest.
| PARAMETER | DESCRIPTION |
|---|---|
locked
|
A lockfile whose index and git commits to read; the newest ones when omitted.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Resolution
|
The build. |
| RAISES | DESCRIPTION |
|---|---|
ResolutionError
|
If no build satisfies the requirements. |
Source code in src/quivers/packages/workspace.py
locked_build
¶
locked_build(locked: Lockfile) -> Resolution
The build a lockfile records, read from the lockfile alone.
The manifest is not consulted beyond the root package itself: each package is materialized from its pinned source (a directory, a git commit, the index entry at the locked index commit, or the standard library), so the build migrated from stays reachable after the manifest has moved on.
| PARAMETER | DESCRIPTION |
|---|---|
locked
|
The lockfile.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Resolution
|
The locked build. |
| RAISES | DESCRIPTION |
|---|---|
PackageError
|
If a locked package no longer has the version the lockfile records. |
GitError
|
If a pinned commit cannot be read. |
Source code in src/quivers/packages/workspace.py
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 415 416 417 418 419 420 | |
loader
¶
loader(resolution: Resolution) -> PackageLoader
The loader of a resolved build.
| PARAMETER | DESCRIPTION |
|---|---|
resolution
|
The build.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PackageLoader
|
Finds every module of every package. |
Source code in src/quivers/packages/workspace.py
links
¶
links(resolution: Resolution) -> dict[str, str]
The links of a build: default links, then the root's own.
| PARAMETER | DESCRIPTION |
|---|---|
resolution
|
The build.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str]
|
Hole path to filling module. |
| RAISES | DESCRIPTION |
|---|---|
PackageError
|
If two packages give one hole different defaults and the root does not link it. |
Source code in src/quivers/packages/workspace.py
load
¶
load(module: str, resolution: Resolution, *, extra_links: Mapping[str, str] | None = None, overlay: Mapping[str, str] | None = None) -> ModuleGraph
Load the module graph rooted at one module of the build.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The root module's path.
TYPE:
|
resolution
|
The build.
TYPE:
|
extra_links
|
Links beyond the build's (an experiment's), which win.
TYPE:
|
overlay
|
Module texts, by path, read instead of the packages' files (an editor's buffers, a migration's output).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModuleGraph
|
The checked graph, linked with the build's links for the holes it has. |
| RAISES | DESCRIPTION |
|---|---|
PackageError
|
If no package provides the module, or an import or link crosses a package boundary the rules forbid. |
ModuleError
|
If the graph does not load or resolve. |
Source code in src/quivers/packages/workspace.py
build_module
¶
build_module(module: str, resolution: Resolution, *, extra_links: Mapping[str, str] | None = None, overlay: Mapping[str, str] | None = None) -> BuiltModule
Check one module of the build as a root.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module's path.
TYPE:
|
resolution
|
The build.
TYPE:
|
extra_links
|
Links beyond the build's.
TYPE:
|
overlay
|
Module texts read instead of the packages' files.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BuiltModule
|
The checked module and its hashes. A module that needs holes no link fills is hashed by its checking program, which checks it against the holes' signatures. |
| RAISES | DESCRIPTION |
|---|---|
PackageError
|
If an import crosses a package boundary the rules forbid. |
ModuleError
|
If the graph does not load or resolve. |
CompileError
|
If the module does not compile. |
Source code in src/quivers/packages/workspace.py
build_package
¶
build_package(package: Package, resolution: Resolution) -> tuple[BuiltModule, ...]
Check the modules of one package that the build pins.
The root package's every module is checked; a dependency's exposed modules are (its private modules are checked through them).
| PARAMETER | DESCRIPTION |
|---|---|
package
|
A package of the build.
TYPE:
|
resolution
|
The build.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[BuiltModule, ...]
|
The checked modules, by path. |
| RAISES | DESCRIPTION |
|---|---|
PackageError
|
If an exposed module does not exist or a hole is unlisted. |
ModuleError
|
If a module does not load or resolve. |
CompileError
|
If a module does not compile. |
Source code in src/quivers/packages/workspace.py
pinned_modules
¶
pinned_modules(package: Package, resolution: Resolution) -> tuple[BuiltModule, ...]
The checked modules a lockfile pins for one dependency.
The standard library ships with quivers, so its version (the release it ships with) identifies its content: it is not checked or pinned module by module. Every other dependency's exposed modules are.
| PARAMETER | DESCRIPTION |
|---|---|
package
|
A dependency of the build.
TYPE:
|
resolution
|
The build.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[BuiltModule, ...]
|
Its pinned modules, by path. |
| RAISES | DESCRIPTION |
|---|---|
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/workspace.py
lock
¶
lock() -> Lockfile
Resolve the manifest afresh, check every package, and pin it.
| RETURNS | DESCRIPTION |
|---|---|
Lockfile
|
The lockfile, also written beside the manifest. |
| RAISES | DESCRIPTION |
|---|---|
ResolutionError
|
If no build satisfies the requirements. |
PackageError
|
If a module violates a package rule, or an indexed version's modules differ from the hashes its index entry publishes. |
ModuleError
|
If a module does not load or resolve. |
CompileError
|
If a module does not compile. |
Source code in src/quivers/packages/workspace.py
build
¶
build() -> tuple[Lockfile, tuple[BuiltModule, ...]]
Build the root package against its lockfile.
| RETURNS | DESCRIPTION |
|---|---|
tuple[Lockfile, tuple[BuiltModule, ...]]
|
The lockfile and the root package's checked modules. |
| RAISES | DESCRIPTION |
|---|---|
PackageError
|
If the package has no lockfile, the manifest has moved away
from it ( |
ResolutionError
|
If no build satisfies the requirements. |
ModuleError
|
If a module does not load or resolve. |
CompileError
|
If a module does not compile. |
Source code in src/quivers/packages/workspace.py
module_core_hash
¶
module_core_hash(module: QiecModule | None) -> str
The hash of a root module's own checked declarations.
The root's declarations are the ones with bare names in its flat program; each enters by its declaration kind and content hash, so renaming, reformatting, and comments leave the hash unchanged.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked core of a flat program;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The digest. |
Source code in src/quivers/packages/workspace.py
package_module_of
¶
package_module_of(file: str | Path) -> tuple[Workspace, str] | None
The package a module file belongs to, and the file's module path.
A .qvr file is a module of a package when the nearest qvr.toml
at or above it declares a package whose namespace holds the file below
the package's module root: coins/model.qvr below a package named
coins whose source is . is the module coins.model.
| PARAMETER | DESCRIPTION |
|---|---|
file
|
The file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Workspace, str] | None
|
The package's workspace and the module path, or |
| RAISES | DESCRIPTION |
|---|---|
ManifestError
|
If the nearest manifest is malformed. |
Source code in src/quivers/packages/workspace.py
package_build
¶
package_build(workspace: Workspace) -> Resolution
The build a package's modules are read in.
| PARAMETER | DESCRIPTION |
|---|---|
workspace
|
The package's workspace.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Resolution
|
The build its |
| RAISES | DESCRIPTION |
|---|---|
LockfileError
|
If the lockfile is malformed. |
PackageError
|
If a locked package no longer has the version the lockfile records. |
ResolutionError
|
If no build satisfies the manifest's requirements. |
Source code in src/quivers/packages/workspace.py
load_package_file
¶
load_package_file(file: str | Path, *, links: Mapping[str, str] | None = None) -> ModuleGraph | None
The module graph rooted at a file, read in its package's build.
| PARAMETER | DESCRIPTION |
|---|---|
file
|
The root module's file.
TYPE:
|
links
|
Links beyond the build's (an experiment's), which win.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModuleGraph | None
|
The checked graph, or |
| RAISES | DESCRIPTION |
|---|---|
ManifestError
|
If the package's manifest is malformed. |
PackageError
|
If an import or link crosses a package boundary the rules forbid, or the lockfile does not match the packages. |
ModuleError
|
If the graph does not load or resolve. |