Skip to content

Commit 7a57b65

Browse files
committed
Reformat
1 parent 6d48160 commit 7a57b65

File tree

16 files changed

+135
-68
lines changed

16 files changed

+135
-68
lines changed

kicad_lib_manager/commands/add_hook/command.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def add_hook(directory, force):
7777
else:
7878
# Merge with existing content to preserve user logic
7979
click.echo("Merging KiLM content with existing hook...")
80-
new_content = merge_hook_content(existing_content, create_kilm_hook_content())
80+
new_content = merge_hook_content(
81+
existing_content, create_kilm_hook_content()
82+
)
8183

8284
except (OSError, UnicodeDecodeError):
8385
click.echo("Warning: Could not read existing hook content, overwriting...")

kicad_lib_manager/commands/config/command.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ def set_default(library_name, library_type):
292292

293293
# Set as current library
294294
if library_path is None:
295-
click.echo(f"Error: Could not find path for library '{library_name}'", err=True)
295+
click.echo(
296+
f"Error: Could not find path for library '{library_name}'", err=True
297+
)
296298
sys.exit(1)
297299
config.set_current_library(library_path)
298300
click.echo(f"Set {library_type} library '{library_name}' as default.")
@@ -350,7 +352,9 @@ def remove(library_name, library_type, force):
350352
# Find libraries matching the name and type
351353
matching_libraries = []
352354
for lib in all_libraries:
353-
if lib.get("name") == library_name and (library_type == "all" or lib.get("type") == library_type):
355+
if lib.get("name") == library_name and (
356+
library_type == "all" or lib.get("type") == library_type
357+
):
354358
matching_libraries.append(lib)
355359

356360
if not matching_libraries:

kicad_lib_manager/commands/setup/command.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ def setup(
478478

479479
# Also list existing libraries to pin them all
480480
try:
481-
482481
existing_symbols, existing_footprints = list_libraries(kicad_lib_dir)
483482
symbol_libs = existing_symbols
484483
footprint_libs = existing_footprints

kicad_lib_manager/commands/status/command.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ def status():
2626
config_data = yaml.safe_load(f)
2727

2828
# Show libraries
29-
if config_data and "libraries" in config_data and config_data["libraries"]:
29+
if (
30+
config_data
31+
and "libraries" in config_data
32+
and config_data["libraries"]
33+
):
3034
click.echo(" Configured Libraries:")
3135

3236
# Group by type
@@ -48,7 +52,8 @@ def status():
4852
path = lib.get("path", "unknown")
4953
current = (
5054
" (current)"
51-
if config_data and config_data.get("current_library") == path
55+
if config_data
56+
and config_data.get("current_library") == path
5257
else ""
5358
)
5459
click.echo(f" - {name}: {path}{current}")
@@ -67,7 +72,8 @@ def status():
6772
path = lib.get("path", "unknown")
6873
current = (
6974
" (current)"
70-
if config_data and config_data.get("current_library") == path
75+
if config_data
76+
and config_data.get("current_library") == path
7177
else ""
7278
)
7379
click.echo(f" - {name}: {path}{current}")
@@ -83,7 +89,8 @@ def status():
8389

8490
# Show current library
8591
if (
86-
config_data and "current_library" in config_data
92+
config_data
93+
and "current_library" in config_data
8794
and config_data["current_library"]
8895
):
8996
click.echo(

kicad_lib_manager/commands/template/command.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,12 @@ def make(
817817
if not git_path.endswith("/"):
818818
git_path += "/"
819819

820-
if gitignore_spec and gitignore_spec.match_file(git_path) or additional_spec and additional_spec.match_file(git_path):
820+
if (
821+
gitignore_spec
822+
and gitignore_spec.match_file(git_path)
823+
or additional_spec
824+
and additional_spec.match_file(git_path)
825+
):
821826
dirs_to_remove.append(d)
822827
excluded_files.append(f"{rel_path}/")
823828

kicad_lib_manager/commands/unpin/command.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def unpin(symbols, footprints, all, dry_run, max_backups, verbose):
5050
"""Unpin libraries in KiCad"""
5151
# Enforce mutual exclusivity of --all with --symbols/--footprints
5252
if all and (symbols or footprints):
53-
raise click.UsageError("'--all' cannot be used with '--symbols' or '--footprints'")
53+
raise click.UsageError(
54+
"'--all' cannot be used with '--symbols' or '--footprints'"
55+
)
5456

5557
# Find KiCad configuration
5658
try:

kicad_lib_manager/commands/update/command.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def update(dry_run, verbose, auto_setup):
175175
)
176176
click.echo("Use 'kilm status' to check your current configuration.")
177177

178+
178179
# TODO: Should be in services or utils
179180
def check_for_library_changes(git_output, lib_path):
180181
"""
@@ -202,23 +203,35 @@ def check_for_library_changes(git_output, lib_path):
202203
templates_path = lib_path / "templates"
203204

204205
# Look for symbol libraries (.kicad_sym files)
205-
if symbols_path.exists() and symbols_path.is_dir() and any(
206-
f.name.endswith(".kicad_sym") for f in symbols_path.glob("**/*.kicad_sym")
206+
if (
207+
symbols_path.exists()
208+
and symbols_path.is_dir()
209+
and any(
210+
f.name.endswith(".kicad_sym") for f in symbols_path.glob("**/*.kicad_sym")
211+
)
207212
):
208213
changes.append("symbols")
209214

210215
# Look for footprint libraries (.pretty directories)
211-
if footprints_path.exists() and footprints_path.is_dir() and any(
212-
f.is_dir() and f.name.endswith(".pretty")
213-
for f in footprints_path.glob("**/*.pretty")
216+
if (
217+
footprints_path.exists()
218+
and footprints_path.is_dir()
219+
and any(
220+
f.is_dir() and f.name.endswith(".pretty")
221+
for f in footprints_path.glob("**/*.pretty")
222+
)
214223
):
215224
changes.append("footprints")
216225

217226
# Look for project templates (directories with metadata.yaml)
218-
if templates_path.exists() and templates_path.is_dir() and any(
219-
(f / "metadata.yaml").exists()
220-
for f in templates_path.glob("*")
221-
if f.is_dir()
227+
if (
228+
templates_path.exists()
229+
and templates_path.is_dir()
230+
and any(
231+
(f / "metadata.yaml").exists()
232+
for f in templates_path.glob("*")
233+
if f.is_dir()
234+
)
222235
):
223236
changes.append("templates")
224237

kicad_lib_manager/config.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
class LibraryDict(TypedDict):
2020
"""Type definition for library configuration."""
21+
2122
name: str
2223
path: str
2324
type: str
@@ -62,7 +63,9 @@ def _get_config_file(self) -> Path:
6263
config_dir.mkdir(parents=True, exist_ok=True)
6364
return config_dir / CONFIG_FILE_NAME
6465

65-
def get(self, key: str, default: Optional[ConfigValue] = None) -> Optional[ConfigValue]:
66+
def get(
67+
self, key: str, default: Optional[ConfigValue] = None
68+
) -> Optional[ConfigValue]:
6669
"""Get a configuration value"""
6770
return self._config.get(key, default)
6871

@@ -122,9 +125,7 @@ def remove_library(self, name: str, library_type: Optional[str] = None) -> bool:
122125
if not (lib["name"] == name and lib["type"] == library_type)
123126
]
124127
else:
125-
filtered_libraries = [
126-
lib for lib in libraries if lib["name"] != name
127-
]
128+
filtered_libraries = [lib for lib in libraries if lib["name"] != name]
128129

129130
self._config["libraries"] = filtered_libraries
130131
removed = len(filtered_libraries) < original_count
@@ -263,14 +264,19 @@ def _normalize_libraries_field(self) -> None:
263264

264265
# If libraries is not a list, reset to empty list
265266
if not isinstance(libraries, list):
266-
click.echo(f"Warning: libraries field in config was {type(libraries).__name__}, resetting to empty list", err=True)
267+
click.echo(
268+
f"Warning: libraries field in config was {type(libraries).__name__}, resetting to empty list",
269+
err=True,
270+
)
267271
self._config["libraries"] = []
268272
return
269273

270274
# Validate and clean up each library entry
271275
normalized_libraries: List[LibraryDict] = []
272276
for lib in libraries:
273-
if isinstance(lib, dict) and all(key in lib for key in ["name", "path", "type"]):
277+
if isinstance(lib, dict) and all(
278+
key in lib for key in ["name", "path", "type"]
279+
):
274280
# Ensure all values are strings
275281
normalized_lib = _make_library_dict(
276282
name=str(lib["name"]),
@@ -294,7 +300,10 @@ def _get_normalized_libraries(self) -> List[LibraryDict]:
294300

295301
# If libraries is not a list, reset to empty list
296302
if not isinstance(libraries_raw, list):
297-
click.echo(f"Warning: libraries field was {type(libraries_raw).__name__}, resetting to empty list", err=True)
303+
click.echo(
304+
f"Warning: libraries field was {type(libraries_raw).__name__}, resetting to empty list",
305+
err=True,
306+
)
298307
self._config["libraries"] = []
299308
return []
300309

@@ -303,7 +312,9 @@ def _get_normalized_libraries(self) -> List[LibraryDict]:
303312
needs_save = False
304313

305314
for lib in libraries_raw:
306-
if isinstance(lib, dict) and all(key in lib for key in ["name", "path", "type"]):
315+
if isinstance(lib, dict) and all(
316+
key in lib for key in ["name", "path", "type"]
317+
):
307318
# Ensure all values are strings
308319
normalized_lib = _make_library_dict(
309320
name=str(lib["name"]),

kicad_lib_manager/utils/file_ops.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from typing import List, Optional, Tuple
88

99

10-
def read_file_with_encoding(file_path: Path, encodings: Optional[List[str]] = None) -> str:
10+
def read_file_with_encoding(
11+
file_path: Path, encodings: Optional[List[str]] = None
12+
) -> str:
1113
"""
1214
Read a file trying multiple encodings until successful
1315

kicad_lib_manager/utils/git_utils.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def get_git_hooks_directory(repo_path: Path) -> Path:
3232
try:
3333
rp = subprocess.run(
3434
["git", "-C", str(repo_path), "rev-parse", "--git-path", "hooks"],
35-
capture_output=True, text=True, check=True
35+
capture_output=True,
36+
text=True,
37+
check=True,
3638
)
3739
hooks_dir = Path(rp.stdout.strip())
3840
if not hooks_dir.is_absolute():
@@ -44,7 +46,9 @@ def get_git_hooks_directory(repo_path: Path) -> Path:
4446
try:
4547
cd = subprocess.run(
4648
["git", "-C", str(repo_path), "rev-parse", "--git-common-dir"],
47-
capture_output=True, text=True, check=True
49+
capture_output=True,
50+
text=True,
51+
check=True,
4852
)
4953
common_dir = Path(cd.stdout.strip())
5054
if not common_dir.is_absolute():
@@ -93,7 +97,7 @@ def merge_hook_content(existing_content: str, kilm_content: str) -> str:
9397
# Check if KiLM content is already present
9498
if "KiLM-managed section" in existing_content:
9599
# Already has KiLM content, replace the section
96-
lines = existing_content.split('\n')
100+
lines = existing_content.split("\n")
97101
start_marker = "# BEGIN KiLM-managed section"
98102
end_marker = "# END KiLM-managed section"
99103

@@ -109,8 +113,8 @@ def merge_hook_content(existing_content: str, kilm_content: str) -> str:
109113

110114
if start_idx is not None and end_idx is not None:
111115
# Replace existing KiLM section
112-
new_lines = lines[:start_idx] + [kilm_content] + lines[end_idx + 1:]
113-
return '\n'.join(new_lines)
116+
new_lines = lines[:start_idx] + [kilm_content] + lines[end_idx + 1 :]
117+
return "\n".join(new_lines)
114118

115119
# Add KiLM content at the end with clear markers
116120
return f"{existing_content.rstrip()}\n\n{kilm_content}"

0 commit comments

Comments
 (0)