Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ jobs:
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand All @@ -22,7 +23,7 @@ jobs:
run: pytest
- name: Run mypy
run: mypy .
- name: Run flake8
run: flake8
- name: Run isort
run: isort --check --diff .
- name: Run ruff check
run: ruff check .
- name: Run ruff format
run: ruff format --check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ out_3d/
*.pdf
/librepcb_parts_generator.egg-info/
/build/
.venv
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
This is a collection of Python 3 based scripts to generate parts for the
[LibrePCB](https://librepcb.org) default library.


## Requirements

- Python 3.8+
- Python 3.9+
- Dependencies in `pyproject.toml`


## Introduction / Concepts

While it's easy to create a one-off script to generate LibrePCB library
Expand Down
6 changes: 4 additions & 2 deletions cadquery_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ class StepAssembly:
"""
A STEP assembly.
"""

def __init__(self, name: str):
self.assembly = cq.Assembly(name=name)

# Less verbose output
for printer in Message.DefaultMessenger_s().Printers():
printer.SetTraceLevel(Message_Gravity.Message_Fail)

def add_body(self, body: cq.Workplane, name: str, color: cq.Color,
location: Optional[cq.Location] = None) -> None:
def add_body(
self, body: cq.Workplane, name: str, color: cq.Color, location: Optional[cq.Location] = None
) -> None:
"""
Add a body to the assembly.

Expand Down
13 changes: 7 additions & 6 deletions common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Common functionality for generator scripts.
"""

import collections
import csv
import re
Expand All @@ -18,7 +19,7 @@
('\r', '\\r'),
('\t', '\\t'),
('\v', '\\v'),
('"', '\\"'),
('"', '\\"'),
)


Expand Down Expand Up @@ -113,10 +114,7 @@ def get_pad_uuids(base_lib_path: str, pkg_uuid: str) -> Dict[str, str]:
"""
with open(path.join(base_lib_path, 'pkg', pkg_uuid, 'package.lp'), 'r') as f:
lines = f.readlines()
opt_matches = [
re.match(r' \(pad ([^\s]*) \(name "([^"]*)"\)\)$', line)
for line in lines
]
opt_matches = [re.match(r' \(pad ([^\s]*) \(name "([^"]*)"\)\)$', line) for line in lines]
matches = list(filter(None, opt_matches))
mapping = {}
for match in matches:
Expand All @@ -132,13 +130,16 @@ def human_sort_key(key: str) -> List[Any]:
Function that can be used for natural sorting, where "PB2" comes before
"PB10" and after "PA3".
"""

def _convert(text: str) -> Union[int, str]:
return int(text) if text.isdigit() else text

return [_convert(x) for x in re.split(r'(\d+)', key) if x]


def serialize_common(serializable: Any, output_directory: str, uuid: str, long_type: str, short_type: str) -> None:
def serialize_common(
serializable: Any, output_directory: str, uuid: str, long_type: str, short_type: str
) -> None:
"""
Centralized serialize() implementation shared between Component, Symbol, Device, Package
"""
Expand Down
Loading