jitxlib.parts.providers package#

The providers that ship with jitxlib-parts#

CsvParts resolves passives from a CSV of approved parts. IdealPassives synthesizes one at whatever value was asked for. Put them in a chain, as registry strings in project config or as instances in code:

[tool.jitx.parts] chain = [“csv:parts/approved-parts.csv”, “ideal”]

PartSource([CsvParts(“parts/approved-parts.csv”), IdealPassives()])

They are here for two reasons.

They are the worked examples to read before writing a provider of your own, and between them they cover the two shapes a provider can have. CsvParts is a catalogue with rows to search, so it shows filtering, ranking, distinct and a versioned payload. IdealPassives is a generator with nothing to search, so it shows declining a query whose value it cannot pin, and marking a synthesized part as not orderable. Both are short enough to read end to end, and neither needs a service to talk to, so the protocol is the only thing left in them.

And they carry early exploration and prototyping. Someone new to JITX can describe a passive by what it has to do and get a board out of it without first choosing a catalogue, installing anything, or knowing that the provider protocol exists: a CSV you can write by hand, and a generator that answers at any value, are enough to see the whole describe-resolve-pin cycle work.

class CsvPart(identity, payload)[source]#

Bases: object

A resolved part from a CSV row. Implements ResolvedPart.

Parameters:
identity: PartIdentity#
payload: dict[str, JSON]#
materialize(component)[source]#

Attach a landpattern and symbol from the standard generators.

Return type:

None

Parameters:

component (Any)

class CsvParts(path, root=None, package=None)[source]#

Bases: CategoryProvider

Resolve passives from a CSV of approved parts.

category, mpn and manufacturer are consumed as identity and datasheet as payload; every other column becomes an attribute under its own name, so the file’s header is the vocabulary. Dimensioned columns are parsed into quantities.

A row is a candidate when match says so, and candidates are ordered by the query’s rank. Filtering and ordering cover every column the file has, which is the provider invariant: whatever it exposes, it serves.

Parameters:
  • path (str)

  • root (str | None)

  • package (str | None)

path: str#

The file, as written. Relative paths are resolved against root.

root: str | None = None#

Directory path is relative to, when it came from project config.

Deliberately absent from config(), and so from the chain digest: where a project happens to be checked out is not a design decision, and baking an absolute path into the digest would give two developers different chains for the same project and never let the lock match.

package: str | None = None#

Installed package path is a resource of, for a catalogue shipped by a company-wide pip package. Read through importlib.resources, so it works from a wheel, an editable install or a zip import alike.

Unlike root, this one is in config(): which package a catalogue comes from is a design decision, where its files happen to land on disk is not.

name: str#

` and the file’s basename, or the package and basename for a resource.

Two catalogues with the same basename in different directories collide, which is legal; PartSource.names() suffixes duplicates positionally.

Type:

`csv

classmethod from_package(package, resource)[source]#

A catalogue shipped inside an installed package.

The spelling for a company-wide approved-parts list: publish a chain from the package that carries the CSV, and name the file as a resource rather than as a path.

PartSource([CsvParts.from_package(“acme_parts”, “approved.csv”)])

The package name and resource reach the chain digest; the filesystem location does not, so every developer and every CI box computes the same chain for the same installed version.

Parameters:
  • package (str)

  • resource (str)

config()[source]#

What identifies this catalogue, and nothing that does not.

The path or resource name, and the package when there is one: changing either is a decision. root is excluded, and so is wherever a package resolves to on disk, so the digest is the same on every machine.

The package’s version is excluded too, deliberately. A chain published by a package is pinned by dependency version, not by the lockfile; asking the lock to defend against an upgrade as well would pin the same thing twice, in two files, with no way to tell which is authoritative.

Return type:

dict[str, JSON]

property file: Any#

a package resource, or a filesystem path.

A Traversable in the package case rather than a Path, since the file need not be on the filesystem at all.

Type:

Where to read from

resolve_one(query)[source]#

Answer one query. config and rehydrate are still yours to write.

Return type:

Resolved | NoMatch | Unsupported | Deny

Parameters:

query (CanonicalQuery)

distinct(query, key)[source]#

Values of key among matching rows, in sorted order.

Return type:

Sequence[object]

Parameters:
rehydrate(identity, payload)[source]#

Rebuild a part from a lockfile entry.

The payload carries its own version, so this provider can disown a payload it no longer understands rather than the core guessing.

Return type:

ResolvedPart

Parameters:
class IdealPart(identity, payload)[source]#

Bases: object

A synthesized part. Implements ResolvedPart.

Parameters:
identity: PartIdentity#
payload: dict[str, JSON]#
materialize(component)[source]#
Return type:

None

Parameters:

component (Any)

class IdealPassives(series='auto')[source]#

Bases: CategoryProvider

Synthesize an ideal passive at the requested value.

Only serves a query whose value constraint pins one value: Exactly, or a Tolerance/Range whose typical is unambiguous. A query asking for “anything between 1k and 10k” has no single answer to synthesize, so it is declined rather than guessed at.

series is “auto” (the default) to pick values by the synthesized part’s tolerance, or names the E-series values snap to, several joined with + (“E24+E96”). An unknown name raises ValueError.

Parameters:

series (str)

series: str = 'auto'#
name: str = 'ideal'#

How this provider is named in diagnostics and lockfile entries.

Supply it as a dataclass field, a plain class attribute, or an assignment in __init__. A property or a ClassVar is an incompatible override; for a derived name, use field(init=False) and set it in __post_init__.

discovery_priority: int = -100#

Rank used ONLY when no chain is declared anywhere and one is discovered from entry points; higher is asked first. An explicit PartSource ignores it, because a written chain is already ordered.

Declare it the same way as name.

config()[source]#

This provider’s configuration as a canonical JSON object.

An object rather than a bare value, so a config is always something with named keys, which is what makes two of them comparable and what keeps a chain digest readable in the file it lands in.

Must cover everything that could change which part gets selected (a file path, a base URL, a series name) and nothing that could not, such as an open connection or a warmed cache.

Return type:

dict[str, JSON]

resolve_one(query)[source]#

Answer one query. config and rehydrate are still yours to write.

Return type:

Resolved | NoMatch | Unsupported | Deny

Parameters:

query (CanonicalQuery)

rehydrate(identity, payload)[source]#

Reconstruct a part from a lockfile entry this provider wrote.

Required of any provider used with a lockfile: only the provider knows what payload means. May raise StalePayload if the payload predates a change it cannot honor.

Return type:

ResolvedPart

Parameters:

Submodules#