Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Add KiCad global footprint paths for non-linux platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-mellor committed Oct 22, 2024
1 parent ca06d40 commit 20241b8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/faebryk/exporters/pcb/kicad/pcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from faebryk.libs.kicad.fileformats_common import C_effects, C_wh
from faebryk.libs.kicad.fileformats_version import kicad_footprint_file
from faebryk.libs.kicad.paths import GLOBAL_FP_DIR_PATH, GLOBAL_FP_LIB_PATH
from faebryk.libs.sexp.dataclass_sexp import get_parent
from faebryk.libs.util import (
KeyErrorNotFound,
Expand Down Expand Up @@ -50,9 +51,6 @@ def _get_footprint(identifier: str, fp_lib_path: Path) -> C_footprint:
dir_path = Path(lib.uri.replace("${KIPRJMOD}", str(fp_lib_path.parent)))
except KeyErrorNotFound:
# non-local lib, search in kicad global lib
# TODO don't hardcode path
GLOBAL_FP_LIB_PATH = Path("~/.config/kicad/8.0/fp-lib-table").expanduser()
GLOBAL_FP_DIR_PATH = Path("/usr/share/kicad/footprints")
global_fp_lib_table = C_kicad_fp_lib_table_file.loads(GLOBAL_FP_LIB_PATH)
lib = find(global_fp_lib_table.fp_lib_table.libs, lambda x: x.name == lib_id)
dir_path = Path(
Expand Down
6 changes: 1 addition & 5 deletions src/faebryk/exporters/schematic/kicad/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
C_rect,
C_stroke,
)
from faebryk.libs.kicad.paths import GLOBAL_FP_DIR_PATH, GLOBAL_FP_LIB_PATH
from faebryk.libs.sexp.dataclass_sexp import dataclass_dfs
from faebryk.libs.util import (
cast_assert,
Expand Down Expand Up @@ -201,11 +202,6 @@ def index_symbol_files(
fp_lib_table_paths = [Path(p) for p in fp_lib_tables]

# non-local lib, search in kicad global lib
# TODO don't hardcode path
# TODO: doesn't work on OSx. Make them at least search paths
# /Applications/KiCad/KiCad.app/Contents/SharedSupport/symbols/
GLOBAL_FP_LIB_PATH = Path("~/.config/kicad/8.0/fp-lib-table").expanduser()
GLOBAL_FP_DIR_PATH = Path("/usr/share/kicad/footprints")
if load_globals:
fp_lib_table_paths += [GLOBAL_FP_LIB_PATH]

Expand Down
40 changes: 40 additions & 0 deletions src/faebryk/libs/kicad/paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import sys
from pathlib import Path

KICAD_VERSION = "8.0"

# footprint library paths
# ref: https://docs.kicad.org/8.0/en/kicad/kicad.html#config-file-location
match sys.platform:
case "win32":
appdata = os.getenv("APPDATA")
if appdata is not None:
GLOBAL_FP_LIB_PATH = (
Path(appdata) / "kicad" / KICAD_VERSION / "fp-lib-table"
)
else:
raise EnvironmentError("APPDATA environment variable not set")
# TODO: verify on a windows machine
GLOBAL_FP_DIR_PATH = Path(appdata) / "kicad" / KICAD_VERSION / "footprints"
case "linux":
GLOBAL_FP_LIB_PATH = (
Path("~/.config/kicad").expanduser() / KICAD_VERSION / "fp-lib-table"
)
GLOBAL_FP_DIR_PATH = Path("/usr/share/kicad/footprints")
case "darwin":
GLOBAL_FP_LIB_PATH = (
Path("~/Library/Preferences/kicad").expanduser()
/ KICAD_VERSION
/ "fp-lib-table"
)
GLOBAL_FP_DIR_PATH = Path(
"/Applications/KiCad/KiCad.app/Contents/SharedSupport/symbols"
)
case _:
raise EnvironmentError(f"Unsupported platform: {sys.platform}")

if not GLOBAL_FP_LIB_PATH.exists():
raise FileNotFoundError(f"Footprint library path not found: {GLOBAL_FP_LIB_PATH}")
if not GLOBAL_FP_DIR_PATH.exists():
raise FileNotFoundError(f"Footprint directory path not found: {GLOBAL_FP_DIR_PATH}")

0 comments on commit 20241b8

Please sign in to comment.