brepy 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- brepy-0.1.2/.containerignore +5 -0
- brepy-0.1.2/.github/dependabot.yml +25 -0
- brepy-0.1.2/.github/workflows/ci.yml +164 -0
- brepy-0.1.2/.gitignore +4 -0
- brepy-0.1.2/.python-version +1 -0
- brepy-0.1.2/Containerfile +8 -0
- brepy-0.1.2/LICENSE +21 -0
- brepy-0.1.2/PKG-INFO +156 -0
- brepy-0.1.2/README.md +140 -0
- brepy-0.1.2/pyproject.toml +53 -0
- brepy-0.1.2/src/brepy/__init__.py +0 -0
- brepy-0.1.2/src/brepy/__main__.py +5 -0
- brepy-0.1.2/src/brepy/build.py +149 -0
- brepy-0.1.2/src/brepy/cli.py +96 -0
- brepy-0.1.2/src/brepy/export.py +58 -0
- brepy-0.1.2/src/brepy/printability.py +95 -0
- brepy-0.1.2/src/brepy/sheets.py +631 -0
- brepy-0.1.2/src/brepy/viewer.py +121 -0
- brepy-0.1.2/tests/fixtures/peg/peg.py +7 -0
- brepy-0.1.2/tests/fixtures/stand/stand.py +34 -0
- brepy-0.1.2/tests/test_build.py +64 -0
- brepy-0.1.2/tests/test_cli.py +35 -0
- brepy-0.1.2/tests/test_printability.py +40 -0
- brepy-0.1.2/uv.lock +1859 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: docker
|
|
4
|
+
directory: /
|
|
5
|
+
schedule:
|
|
6
|
+
interval: weekly
|
|
7
|
+
groups:
|
|
8
|
+
docker:
|
|
9
|
+
patterns: ["*"]
|
|
10
|
+
|
|
11
|
+
- package-ecosystem: github-actions
|
|
12
|
+
directory: /
|
|
13
|
+
schedule:
|
|
14
|
+
interval: weekly
|
|
15
|
+
groups:
|
|
16
|
+
github-actions:
|
|
17
|
+
patterns: ["*"]
|
|
18
|
+
|
|
19
|
+
- package-ecosystem: uv
|
|
20
|
+
directory: /
|
|
21
|
+
schedule:
|
|
22
|
+
interval: weekly
|
|
23
|
+
groups:
|
|
24
|
+
python:
|
|
25
|
+
patterns: ["*"]
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
schedule:
|
|
9
|
+
- cron: "23 10 * * *"
|
|
10
|
+
workflow_dispatch: {}
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
check:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- name: Clone
|
|
20
|
+
env:
|
|
21
|
+
TOKEN: ${{ github.token }}
|
|
22
|
+
run: |
|
|
23
|
+
git init -q .
|
|
24
|
+
git -c http.extraHeader="Authorization: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" \
|
|
25
|
+
fetch -q --depth 1 "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" "$GITHUB_REF"
|
|
26
|
+
git checkout -q FETCH_HEAD
|
|
27
|
+
|
|
28
|
+
- name: Install OCP's system libraries
|
|
29
|
+
run: |
|
|
30
|
+
sudo apt-get update -q
|
|
31
|
+
sudo apt-get install -y -q --no-install-recommends libgl1 libglib2.0-0
|
|
32
|
+
|
|
33
|
+
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
|
|
34
|
+
|
|
35
|
+
- name: Check
|
|
36
|
+
run: |
|
|
37
|
+
uv sync --locked --all-extras
|
|
38
|
+
uv run ruff check
|
|
39
|
+
uv run ruff format --check
|
|
40
|
+
uv run ty check
|
|
41
|
+
uv run pytest -q
|
|
42
|
+
|
|
43
|
+
dist:
|
|
44
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
45
|
+
needs: check
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
steps:
|
|
48
|
+
- name: Clone
|
|
49
|
+
env:
|
|
50
|
+
TOKEN: ${{ github.token }}
|
|
51
|
+
run: |
|
|
52
|
+
git init -q .
|
|
53
|
+
git -c http.extraHeader="Authorization: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" \
|
|
54
|
+
fetch -q --depth 1 "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" "$GITHUB_REF"
|
|
55
|
+
git checkout -q FETCH_HEAD
|
|
56
|
+
|
|
57
|
+
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
|
|
58
|
+
|
|
59
|
+
- name: Build
|
|
60
|
+
run: |
|
|
61
|
+
version="$(uv version --short)"
|
|
62
|
+
if [ "$version" != "${GITHUB_REF_NAME#v}" ]; then
|
|
63
|
+
echo "::error::tag $GITHUB_REF_NAME does not match version $version in pyproject.toml"
|
|
64
|
+
exit 1
|
|
65
|
+
fi
|
|
66
|
+
uv build --no-sources
|
|
67
|
+
|
|
68
|
+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
|
69
|
+
with:
|
|
70
|
+
name: dist
|
|
71
|
+
path: dist/*
|
|
72
|
+
if-no-files-found: error
|
|
73
|
+
retention-days: 1
|
|
74
|
+
|
|
75
|
+
pypi:
|
|
76
|
+
needs: dist
|
|
77
|
+
runs-on: ubuntu-latest
|
|
78
|
+
environment:
|
|
79
|
+
name: pypi
|
|
80
|
+
url: https://pypi.org/project/brepy/
|
|
81
|
+
permissions:
|
|
82
|
+
id-token: write
|
|
83
|
+
steps:
|
|
84
|
+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
85
|
+
with:
|
|
86
|
+
name: dist
|
|
87
|
+
path: dist
|
|
88
|
+
|
|
89
|
+
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
|
|
90
|
+
|
|
91
|
+
- name: Publish with trusted publishing
|
|
92
|
+
run: uv publish --trusted-publishing always
|
|
93
|
+
|
|
94
|
+
image:
|
|
95
|
+
if: github.event_name != 'pull_request'
|
|
96
|
+
needs: check
|
|
97
|
+
strategy:
|
|
98
|
+
fail-fast: false
|
|
99
|
+
matrix:
|
|
100
|
+
include:
|
|
101
|
+
- arch: amd64
|
|
102
|
+
runner: ubuntu-24.04
|
|
103
|
+
- arch: arm64
|
|
104
|
+
runner: ubuntu-24.04-arm
|
|
105
|
+
runs-on: ${{ matrix.runner }}
|
|
106
|
+
permissions:
|
|
107
|
+
contents: read
|
|
108
|
+
packages: write
|
|
109
|
+
steps:
|
|
110
|
+
- name: Clone
|
|
111
|
+
env:
|
|
112
|
+
TOKEN: ${{ github.token }}
|
|
113
|
+
run: |
|
|
114
|
+
git init -q .
|
|
115
|
+
git -c http.extraHeader="Authorization: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" \
|
|
116
|
+
fetch -q --depth 1 "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" "$GITHUB_REF"
|
|
117
|
+
git checkout -q FETCH_HEAD
|
|
118
|
+
|
|
119
|
+
- name: Build and push by digest
|
|
120
|
+
env:
|
|
121
|
+
TOKEN: ${{ github.token }}
|
|
122
|
+
ARCH: ${{ matrix.arch }}
|
|
123
|
+
run: |
|
|
124
|
+
echo "$TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin
|
|
125
|
+
docker buildx create --use
|
|
126
|
+
docker buildx build --platform "linux/$ARCH" --pull --no-cache \
|
|
127
|
+
--label "org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
|
|
128
|
+
--output "type=image,name=ghcr.io/${GITHUB_REPOSITORY,,},push-by-digest=true,name-canonical=true,push=true" \
|
|
129
|
+
--metadata-file metadata.json -f Containerfile .
|
|
130
|
+
mkdir digests
|
|
131
|
+
digest="$(jq -r '."containerimage.digest"' metadata.json)"
|
|
132
|
+
touch "digests/${digest#sha256:}"
|
|
133
|
+
|
|
134
|
+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
|
135
|
+
with:
|
|
136
|
+
name: digest-${{ matrix.arch }}
|
|
137
|
+
path: digests/*
|
|
138
|
+
if-no-files-found: error
|
|
139
|
+
retention-days: 1
|
|
140
|
+
|
|
141
|
+
manifest:
|
|
142
|
+
needs: image
|
|
143
|
+
runs-on: ubuntu-latest
|
|
144
|
+
permissions:
|
|
145
|
+
contents: read
|
|
146
|
+
packages: write
|
|
147
|
+
steps:
|
|
148
|
+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
149
|
+
with:
|
|
150
|
+
pattern: digest-*
|
|
151
|
+
merge-multiple: true
|
|
152
|
+
path: digests
|
|
153
|
+
|
|
154
|
+
- name: Push the multi-platform tag
|
|
155
|
+
env:
|
|
156
|
+
TOKEN: ${{ github.token }}
|
|
157
|
+
run: |
|
|
158
|
+
case "$GITHUB_REF" in
|
|
159
|
+
refs/tags/v*) tag="${GITHUB_REF_NAME#v}" ;;
|
|
160
|
+
*) tag=latest ;;
|
|
161
|
+
esac
|
|
162
|
+
repo="ghcr.io/${GITHUB_REPOSITORY,,}"
|
|
163
|
+
echo "$TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin
|
|
164
|
+
docker buildx imagetools create -t "$repo:$tag" $(printf "$repo@sha256:%s " $(ls digests))
|
brepy-0.1.2/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.14
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
FROM ghcr.io/astral-sh/uv:0.13.0-python3.14-trixie-slim@sha256:8e70ac2e85d09a5bb7ef09753b80671a60a71c8d24f195e4890d71e03865e36d
|
|
2
|
+
RUN apt-get update \
|
|
3
|
+
&& apt-get install -y --no-install-recommends ca-certificates curl git libgl1 libglib2.0-0 \
|
|
4
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
5
|
+
COPY . /src
|
|
6
|
+
RUN uv export --project /src --locked --no-hashes --no-emit-project --format requirements-txt > /tmp/requirements.txt \
|
|
7
|
+
&& uv pip install --system --no-cache -r /tmp/requirements.txt /src \
|
|
8
|
+
&& rm -rf /src /tmp/requirements.txt
|
brepy-0.1.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Brandon Helwig
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
brepy-0.1.2/PKG-INFO
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: brepy
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Build, export and preview build123d model scripts
|
|
5
|
+
Author: Brandon Helwig
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Requires-Dist: build123d>=0.13
|
|
10
|
+
Requires-Dist: numpy>=2
|
|
11
|
+
Requires-Dist: pillow>=11
|
|
12
|
+
Provides-Extra: viewer
|
|
13
|
+
Requires-Dist: ocp-viewer>=1.1; extra == 'viewer'
|
|
14
|
+
Requires-Dist: pywebview>=6; extra == 'viewer'
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# brepy
|
|
18
|
+
|
|
19
|
+
Build, export and preview [build123d](https://build123d.readthedocs.io) model
|
|
20
|
+
scripts from the command line.
|
|
21
|
+
|
|
22
|
+
A model is a Python script with a `build()` function. `brepy` runs it, writes
|
|
23
|
+
the parts to STEP, STL, 3MF or BREP, draws dimensioned preview sheets without a
|
|
24
|
+
GPU or display, and can show the model in a live viewer that rebuilds on save.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
uv tool install "brepy[viewer]"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The `viewer` extra adds `--view` and `--watch`. Leave it out on headless
|
|
33
|
+
machines. OCP needs the system library `libGL.so.1` (Debian: `libgl1`).
|
|
34
|
+
Releases are published to [PyPI](https://pypi.org/project/brepy/).
|
|
35
|
+
|
|
36
|
+
A container image with `brepy`, pytest, ruff and ty preinstalled is published
|
|
37
|
+
as `ghcr.io/brhelwig-dev/brepy:<version>` for each release, and as `:latest`,
|
|
38
|
+
rebuilt from `main` on every push and nightly:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
docker run --rm -v "$PWD:/work" -w /work ghcr.io/brhelwig-dev/brepy:0.1.2 \
|
|
42
|
+
brepy -f step models/bracket/bracket.py
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
brepy models/bracket/bracket.py # STEP beside the script
|
|
49
|
+
brepy -f stl -f 3mf -o out/ models/bracket/bracket.py
|
|
50
|
+
brepy -f png models/bracket/bracket.py # preview sheets
|
|
51
|
+
brepy --part lid models/box/box.py # one part
|
|
52
|
+
brepy -p width=30 models/bracket/bracket.py # a build() argument
|
|
53
|
+
brepy --watch models/bracket/bracket.py # live preview
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The script is imported by its path relative to `--root`, the current directory
|
|
57
|
+
by default. `models/bracket/bracket.py` imports as `models.bracket.bracket`, so
|
|
58
|
+
scripts can share code by importing each other or helper modules under the
|
|
59
|
+
root.
|
|
60
|
+
|
|
61
|
+
## Model scripts
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from build123d import Box, Cylinder, Pos
|
|
65
|
+
|
|
66
|
+
SEPARATE_PRINTS = False
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def build(width: float = 40.0) -> dict:
|
|
70
|
+
base = Box(width, 20, 5)
|
|
71
|
+
pin = Pos(0, 0, 5) * Cylinder(3, 10)
|
|
72
|
+
return {"base": base, "pin": pin}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def preview_spec() -> dict:
|
|
76
|
+
return {"parts": {"bracket_base": {"build_up": [0, 0, 1]}}}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`build()` returns parts by name. A part may itself be a mapping of shells,
|
|
80
|
+
`{"red": shape, "white": shape}`, for one print in several colours. Its
|
|
81
|
+
arguments can be set with `-p NAME=VALUE`, converted to the annotated type.
|
|
82
|
+
|
|
83
|
+
Output files are named after the script:
|
|
84
|
+
|
|
85
|
+
- one plain part: `<name>`
|
|
86
|
+
- several parts: `<name>_<part>` each, plus a combined `<name>` holding all of
|
|
87
|
+
them, unless the script sets `SEPARATE_PRINTS = True`
|
|
88
|
+
- shells: `<name>_<part>_<shell>` each, plus `<name>_<part>` holding the shells
|
|
89
|
+
|
|
90
|
+
## Preview sheets
|
|
91
|
+
|
|
92
|
+
`-f png` writes one sheet per output file to `previews/`, with six orthographic
|
|
93
|
+
views (isometric, underside, front, right, top, bottom) at one shared scale.
|
|
94
|
+
`preview_spec()` adds to them:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
{
|
|
98
|
+
"parts": {
|
|
99
|
+
"<stem>": {
|
|
100
|
+
"build_up": [0, 0, 1],
|
|
101
|
+
"dimensions": [
|
|
102
|
+
{"label": "pin dia", "view": "top", "a": [-3, 0, 15], "b": [3, 0, 15]},
|
|
103
|
+
{"label": "slot", "view": "front", "a": [...], "b": [...], "detail": "slot"},
|
|
104
|
+
],
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"assemblies": {
|
|
108
|
+
"<name>": {
|
|
109
|
+
"seat": [
|
|
110
|
+
{"stem": "<stem>", "at": [0, 0, 0], "build_up": [0, 0, 1]},
|
|
111
|
+
{"stem": "../<other model>/<stem>"},
|
|
112
|
+
],
|
|
113
|
+
"dimensions": [],
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
- `build_up` is the direction away from the build plate. With it, faces that
|
|
120
|
+
would print without support are shaded orange.
|
|
121
|
+
- A dimension is drawn in the view it names, between points `a` and `b`. One
|
|
122
|
+
with a `detail` name gets its own zoomed, sectioned tile.
|
|
123
|
+
- An assembly places output files, or files from a sibling script
|
|
124
|
+
(`../<other model>/<other model>.py`), on one sheet.
|
|
125
|
+
|
|
126
|
+
When the spec is present, `-f step` also writes it to `preview.json`.
|
|
127
|
+
|
|
128
|
+
## Printability
|
|
129
|
+
|
|
130
|
+
`brepy.printability` measures a solid the same way the sheets shade it, for
|
|
131
|
+
use in a model's tests:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from brepy import printability
|
|
135
|
+
|
|
136
|
+
assert printability.unsupported_area(part, build_up=(0, 0, 1)) < 0.01
|
|
137
|
+
assert printability.island_area(part, layer_height=0.2, build_up=(0, 0, 1)) < 0.01
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
A face is unsupported where it faces down more than 42 degrees from vertical
|
|
141
|
+
and does not rest on the plate. An island is an area printed in some layer with
|
|
142
|
+
nothing below it. `printability.section(part, z)` returns the plan section at
|
|
143
|
+
height `z`.
|
|
144
|
+
|
|
145
|
+
## Development
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
uv sync --extra viewer
|
|
149
|
+
uv run pytest
|
|
150
|
+
uv run ruff check && uv run ruff format --check
|
|
151
|
+
uv run ty check
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
MIT
|
brepy-0.1.2/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# brepy
|
|
2
|
+
|
|
3
|
+
Build, export and preview [build123d](https://build123d.readthedocs.io) model
|
|
4
|
+
scripts from the command line.
|
|
5
|
+
|
|
6
|
+
A model is a Python script with a `build()` function. `brepy` runs it, writes
|
|
7
|
+
the parts to STEP, STL, 3MF or BREP, draws dimensioned preview sheets without a
|
|
8
|
+
GPU or display, and can show the model in a live viewer that rebuilds on save.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
uv tool install "brepy[viewer]"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The `viewer` extra adds `--view` and `--watch`. Leave it out on headless
|
|
17
|
+
machines. OCP needs the system library `libGL.so.1` (Debian: `libgl1`).
|
|
18
|
+
Releases are published to [PyPI](https://pypi.org/project/brepy/).
|
|
19
|
+
|
|
20
|
+
A container image with `brepy`, pytest, ruff and ty preinstalled is published
|
|
21
|
+
as `ghcr.io/brhelwig-dev/brepy:<version>` for each release, and as `:latest`,
|
|
22
|
+
rebuilt from `main` on every push and nightly:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
docker run --rm -v "$PWD:/work" -w /work ghcr.io/brhelwig-dev/brepy:0.1.2 \
|
|
26
|
+
brepy -f step models/bracket/bracket.py
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
brepy models/bracket/bracket.py # STEP beside the script
|
|
33
|
+
brepy -f stl -f 3mf -o out/ models/bracket/bracket.py
|
|
34
|
+
brepy -f png models/bracket/bracket.py # preview sheets
|
|
35
|
+
brepy --part lid models/box/box.py # one part
|
|
36
|
+
brepy -p width=30 models/bracket/bracket.py # a build() argument
|
|
37
|
+
brepy --watch models/bracket/bracket.py # live preview
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The script is imported by its path relative to `--root`, the current directory
|
|
41
|
+
by default. `models/bracket/bracket.py` imports as `models.bracket.bracket`, so
|
|
42
|
+
scripts can share code by importing each other or helper modules under the
|
|
43
|
+
root.
|
|
44
|
+
|
|
45
|
+
## Model scripts
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from build123d import Box, Cylinder, Pos
|
|
49
|
+
|
|
50
|
+
SEPARATE_PRINTS = False
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def build(width: float = 40.0) -> dict:
|
|
54
|
+
base = Box(width, 20, 5)
|
|
55
|
+
pin = Pos(0, 0, 5) * Cylinder(3, 10)
|
|
56
|
+
return {"base": base, "pin": pin}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def preview_spec() -> dict:
|
|
60
|
+
return {"parts": {"bracket_base": {"build_up": [0, 0, 1]}}}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`build()` returns parts by name. A part may itself be a mapping of shells,
|
|
64
|
+
`{"red": shape, "white": shape}`, for one print in several colours. Its
|
|
65
|
+
arguments can be set with `-p NAME=VALUE`, converted to the annotated type.
|
|
66
|
+
|
|
67
|
+
Output files are named after the script:
|
|
68
|
+
|
|
69
|
+
- one plain part: `<name>`
|
|
70
|
+
- several parts: `<name>_<part>` each, plus a combined `<name>` holding all of
|
|
71
|
+
them, unless the script sets `SEPARATE_PRINTS = True`
|
|
72
|
+
- shells: `<name>_<part>_<shell>` each, plus `<name>_<part>` holding the shells
|
|
73
|
+
|
|
74
|
+
## Preview sheets
|
|
75
|
+
|
|
76
|
+
`-f png` writes one sheet per output file to `previews/`, with six orthographic
|
|
77
|
+
views (isometric, underside, front, right, top, bottom) at one shared scale.
|
|
78
|
+
`preview_spec()` adds to them:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
{
|
|
82
|
+
"parts": {
|
|
83
|
+
"<stem>": {
|
|
84
|
+
"build_up": [0, 0, 1],
|
|
85
|
+
"dimensions": [
|
|
86
|
+
{"label": "pin dia", "view": "top", "a": [-3, 0, 15], "b": [3, 0, 15]},
|
|
87
|
+
{"label": "slot", "view": "front", "a": [...], "b": [...], "detail": "slot"},
|
|
88
|
+
],
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"assemblies": {
|
|
92
|
+
"<name>": {
|
|
93
|
+
"seat": [
|
|
94
|
+
{"stem": "<stem>", "at": [0, 0, 0], "build_up": [0, 0, 1]},
|
|
95
|
+
{"stem": "../<other model>/<stem>"},
|
|
96
|
+
],
|
|
97
|
+
"dimensions": [],
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- `build_up` is the direction away from the build plate. With it, faces that
|
|
104
|
+
would print without support are shaded orange.
|
|
105
|
+
- A dimension is drawn in the view it names, between points `a` and `b`. One
|
|
106
|
+
with a `detail` name gets its own zoomed, sectioned tile.
|
|
107
|
+
- An assembly places output files, or files from a sibling script
|
|
108
|
+
(`../<other model>/<other model>.py`), on one sheet.
|
|
109
|
+
|
|
110
|
+
When the spec is present, `-f step` also writes it to `preview.json`.
|
|
111
|
+
|
|
112
|
+
## Printability
|
|
113
|
+
|
|
114
|
+
`brepy.printability` measures a solid the same way the sheets shade it, for
|
|
115
|
+
use in a model's tests:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from brepy import printability
|
|
119
|
+
|
|
120
|
+
assert printability.unsupported_area(part, build_up=(0, 0, 1)) < 0.01
|
|
121
|
+
assert printability.island_area(part, layer_height=0.2, build_up=(0, 0, 1)) < 0.01
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
A face is unsupported where it faces down more than 42 degrees from vertical
|
|
125
|
+
and does not rest on the plate. An island is an area printed in some layer with
|
|
126
|
+
nothing below it. `printability.section(part, z)` returns the plan section at
|
|
127
|
+
height `z`.
|
|
128
|
+
|
|
129
|
+
## Development
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
uv sync --extra viewer
|
|
133
|
+
uv run pytest
|
|
134
|
+
uv run ruff check && uv run ruff format --check
|
|
135
|
+
uv run ty check
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "brepy"
|
|
3
|
+
version = "0.1.2"
|
|
4
|
+
description = "Build, export and preview build123d model scripts"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [{ name = "Brandon Helwig" }]
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"build123d>=0.13",
|
|
12
|
+
"numpy>=2",
|
|
13
|
+
"pillow>=11",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.optional-dependencies]
|
|
17
|
+
viewer = [
|
|
18
|
+
"ocp-viewer>=1.1",
|
|
19
|
+
"pywebview>=6",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
brepy = "brepy.cli:main"
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = ["hatchling"]
|
|
27
|
+
build-backend = "hatchling.build"
|
|
28
|
+
|
|
29
|
+
[dependency-groups]
|
|
30
|
+
dev = [
|
|
31
|
+
"pytest==9.1.1",
|
|
32
|
+
"ruff==0.17.0",
|
|
33
|
+
"ty==0.0.86",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[tool.uv]
|
|
37
|
+
default-groups = ["dev"]
|
|
38
|
+
|
|
39
|
+
[tool.pytest.ini_options]
|
|
40
|
+
testpaths = ["tests"]
|
|
41
|
+
|
|
42
|
+
[tool.ruff]
|
|
43
|
+
line-length = 100
|
|
44
|
+
extend-exclude = ["tests/fixtures"]
|
|
45
|
+
|
|
46
|
+
[tool.ruff.lint]
|
|
47
|
+
select = ["E", "F", "W", "I", "B", "UP", "SIM", "RUF"]
|
|
48
|
+
|
|
49
|
+
[tool.ty.analysis]
|
|
50
|
+
allowed-unresolved-imports = ["OCP.**"]
|
|
51
|
+
|
|
52
|
+
[tool.ty.src]
|
|
53
|
+
exclude = ["tests/fixtures"]
|
|
File without changes
|