feat: Add JLCPCB component import for LCSC part numbers - #616
Open
paycheckpacheck wants to merge 1 commit into
Open
feat: Add JLCPCB component import for LCSC part numbers#616paycheckpacheck wants to merge 1 commit into
paycheckpacheck wants to merge 1 commit into
Conversation
Adds circuit_synth.manufacturing.jlcpcb.component_import, which turns a JLCPCB/LCSC catalog entry into a ready-to-use circuit-synth Component. Public API: - import_jlc_component(lcsc_part, ...) -> Component: look up an LCSC part number and build the component - component_from_search_result(result, ...) -> Component: build a component from an existing FastSearchResult without another lookup - lookup_lcsc_part(lcsc_part) -> Optional[JlcPartSpec]: non raising lookup for callers that need to fall back to a locally specified component - JlcComponentImporter / JlcPartSpec for injection and reuse - normalize_lcsc_part() plus a JlcImportError hierarchy (JlcPartNotFoundError, JlcLookupError, SymbolResolutionError) The importer resolves the KiCad symbol, footprint, value and reference prefix through the existing SmartComponentFinder mappings and attaches the sourcing metadata as component properties: LCSC, MPN, Manufacturer, JLCPCB_Package, JLCPCB_Price, JLCPCB_Stock and JLCPCB_Part_Type (Basic or Extended). Symbol, footprint, value, reference and extra properties can be overridden by the caller. A missing footprint mapping logs a warning and still produces a component; a missing symbol mapping raises SymbolResolutionError unless a symbol is supplied. Search backend failures are wrapped in JlcLookupError so an unavailable or rate limited JLCPCB endpoint does not surface as an arbitrary exception. Also adds the `jlc-fast import <LCSC>` CLI command, which prints the resolved part data and the generated Component definition, with a --json mode for scripting, and promotes the SmartComponentFinder symbol/footprint mapping helpers to public methods so they can be reused. Tests: 33 unit tests for the importer and 5 for the CLI command, all with the JLCPCB search layer mocked so no network access is required.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for importing JLCPCB/LCSC parts as circuit-synth components. Until now the JLCPCB integration could search for parts and print a code snippet, but there was no supported way to go from an LCSC part number to a
Componentobject with the sourcing data attached.New module:
src/circuit_synth/manufacturing/jlcpcb/component_import.py.Public API
import_jlc_component(lcsc_part, ref=None, symbol=None, footprint=None, value=None, **properties) -> Component- look up an LCSC part number and build the component.component_from_search_result(result, ...) -> Component- build a component from an existingFastSearchResultwithout performing another lookup (works with cached results).lookup_lcsc_part(lcsc_part) -> Optional[JlcPartSpec]- non raising lookup for callers that want to fall back to a locally specified component.JlcComponentImporter- injectable class holding the search backend and the KiCad mapping provider;resolve_part(),spec_from_search_result(),spec_from_catalog_entry(),build_component(),import_component().JlcPartSpec- resolved part data withto_properties()andto_circuit_synth_code().normalize_lcsc_part()and the error hierarchyJlcImportError->JlcPartNotFoundError,JlcLookupError,SymbolResolutionError.Symbol, footprint, value and reference prefix are resolved through the existing
SmartComponentFindermappings, whose lookup helpers are now public methods (find_kicad_symbol,find_kicad_footprint,reference_designator_for,is_passive_component,extract_component_value) instead of being duplicated.Component properties attached:
LCSC,MPN,Manufacturer,JLCPCB_Package,JLCPCB_Price,JLCPCB_Stock,JLCPCB_Part_Type(Basic or Extended). Properties without data are omitted.CLI
Degradation behavior
JlcLookupError, so an unavailable or rate limited JLCPCB endpoint does not surface as an arbitrary exception;lookup_lcsc_part()returnsNoneand logs a warning.JlcPartNotFoundError(the CLI reports it and exits with status 1).SymbolResolutionErrorunlesssymbol=is supplied.Testing
38 new tests, all with the JLCPCB search layer mocked, so no network access is required:
tests/unit/jlc_integration/test_jlc_component_import.py(33 tests) - part number normalization, symbol/footprint/value resolution for passives and ICs, property mapping, code generation, lookup success and failure paths, component construction, overrides and fallbacks.tests/unit/tools/test_jlc_fast_search_cli.py(5 tests) - the new CLI command including the unknown part and unmapped symbol paths.The 3 skips are the pre-existing network dependent JLCPCB integration tests.
blackandisortreport no changes on the touched files.