lock module#
The lcsc.lock.json record of per-part metadata, keyed by C-number.
A design’s catalogue parts need facts that are neither in the design nor derivable from it, starting with the rotation JLCPCB expects and the catalogue footprint an LCSCLandpattern is built from. Measuring or fetching those reaches the network, which a build should not do every time, and the answer should be reviewable in a diff rather than hidden in a cache. So they are recorded in a file in the project, read on every build and extended when a new part appears.
The file is data the user owns: an entry a human writes or edits is authoritative, and anything this module does not understand is preserved untouched.
- VERSION = 1#
Format version, so a later change can migrate rather than guess.
- class Lock(path, parts, extra)[source]#
Bases:
objectPer-part metadata, keyed by LCSC C-number.
- Parameters:
path (
Path) – where the file lives, whether or not it exists yet.parts (
dict[str,dict[str,Any]]) – the parts mapping, C-number to a record. Records may hold keys this version does not know about.extra (
dict[str,Any]) – top-level keys other than version and parts, kept so that writing the file back does not discard them.
- record(orientations)[source]#
Add measured orientations, leaving every other field in place.
Existing orientations are not overwritten: the file is the authority, and a caller that has measured one already knew it was missing.
- record_footprint(partnumber, footprint)[source]#
Add a fetched catalogue footprint, leaving every other field alone.
The orientation is recorded as zero at the same time. A landpattern built from the catalogue footprint is already in the catalogue’s own frame, which is the frame JLCPCB places the part in, so there is nothing to correct and nothing for the exporter to measure. As everywhere else here, an existing value wins: a part whose orientation a human has stated keeps it.
- project()[source]#
The JITX project directory, where the lock file lives.
Falls back to the working directory when nothing is run from inside a project, so neither a build nor an export fails over where to keep its record.
- Return type:
- path(project_root=None)[source]#
Where the lock file lives, for a project root or the discovered one.
- WIDTH = 120#
Where render stops keeping a value on one line.
Wider than code would be, because this is a data file: one pad of a recorded footprint on one line is what makes a diff of it readable.
- render(value, indent=0)[source]#
value as indented JSON, keeping a short list on one line.
json.dumps(indent=2) puts every number of every coordinate on a line of its own, which turns a recorded footprint into thousands of lines and a diff into something no one reads. Anything that fits stays on one line instead, so a footprint reads as a list of pads and a path as a list of points.