Metadata-Version: 2.4
Name: pybosl2
Version: 0.8.0
Summary: Python ports of the BOSL2 OpenSCAD library for use with PythonSCAD
Author: pinkfish
License-Expression: BSD-2-Clause
Project-URL: Homepage, https://github.com/pinkfish/pybosl2
Project-URL: Repository, https://github.com/pinkfish/pybosl2
Keywords: 3d,openscad,pythonscad,pybosl2,cad,3d-printing
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Manufacturing
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: typing-extensions
Requires-Dist: webcolors>=25
Requires-Dist: svgelements>=1.9
Requires-Dist: shapely>=2
Provides-Extra: test
Requires-Dist: pytest>=7; extra == "test"
Requires-Dist: numpy; extra == "test"
Requires-Dist: pythonscad; extra == "test"
Requires-Dist: typing-extensions; extra == "test"
Requires-Dist: shapely; extra == "test"
Requires-Dist: mypy>=1.8; extra == "test"
Provides-Extra: geo
Provides-Extra: docs
Requires-Dist: sphinx<10,>=7; extra == "docs"
Requires-Dist: shapely; extra == "docs"
Requires-Dist: sphinx-immaterial>=0.13; extra == "docs"
Requires-Dist: ruff==0.17.6; extra == "docs"
Dynamic: license-file

# pybosl2

Python ports of the [BOSL2](https://github.com/BelfrySCAD/BOSL2) OpenSCAD library,
for use with [PythonSCAD](https://pythonscad.org). The package is imported as
`pybosl2`, with one module per wrapped/ported `.scad` file so each Python module can
be read side by side with its OpenSCAD source.

Most modules (constants, math, vectors, paths, shapes2d, …) are standalone pure-Python
ports that work in plain CPython. The modules that build native geometry
(`shapes3d`, `masking`, and the `.polygon()`/`.polyhedron()` boundaries) import the
`pythonscad`/`openscad` native modules at load time.

## Reference

* [Getting started](https://pinkfish.github.io/pybosl2/getting_started.html) — build one part end
  to end: solid, roundover, bore, boss, measurement, exported file
* [Docs](https://pinkfish.github.io/pybosl2/)
* [Specs](https://pinkfish.github.io/pybosl2/specs/index.html) of the various parts
* [SPEC.md](SPEC.md) — what the system is and does, and the contracts it honours
  (generated from [spec/requirements.toml](spec/requirements.toml) by `docs/_reqgen.py`)
* [PLAN.md](PLAN.md) — how that is implemented in Python (typing, classes, docs, tests)
* [TASKS.md](TASKS.md) — the ordered queue of conformance work

## Installation

```bash
pip install pybosl2
```

This pulls in `numpy`. To build native geometry you also need PythonSCAD:

```bash
pip install pythonscad
```

## Usage

Import by submodule (the `square`/`circle`/`cube`/`text` names intentionally shadow
the plain OpenSCAD builtins with BOSL2's anchor/spin/orient-aware versions, so the
package is deliberately not wildcard-re-exported):

```python
from pybosl2 import Anchor, cuboid, cyl

part = cuboid([60, 40, 12], rounding=4, edges=Anchor.Z) - cyl(diameter=10, height=20)
print(part.bounds().size)  # (60.0, 40.0, 12.0)
part.export("bracket.stl")  # .stl / .obj / .off / .ply, no CAD runtime needed
part.show()
```

Booleans are operators (`-`, `|`, `&`), every operation returns a new shape so calls chain, and
`bounds()` measures without rendering. See [Getting
started](https://pinkfish.github.io/pybosl2/getting_started.html) for the guided version.

## Development & tests

**Start with [SPEC.md](SPEC.md), then [PLAN.md](PLAN.md).** Both are normative: the spec says what
the system does and which contracts it honours, the plan says how that is written in Python
(typing, class design, docstrings, errors, tests). Requirements are numbered and permanent — cite
them with their document (`SPEC-P-1`, `PLAN-T-2`) in reviews and commit bodies, since five prefixes
mean different things in the two. [TASKS.md](TASKS.md) is the ordered queue of open
conformance work, [CONFORMANCE.md](CONFORMANCE.md) is the history of what has closed, and
[AGENTS.md](AGENTS.md) is the one-page index.

SPEC.md and PLAN.md are **generated**: edit `spec/requirements.toml` for a requirement or the
frames in `spec/` for prose, then run `python docs/_reqgen.py`.

Before a change is done, all of these must pass:

```bash
export TMPDIR=/path/with/room       # test scratch; a full run can fill a small system disk
pytest                              # STL-render tests skip without the app
mypy --strict pybosl2
ruff check . --fix && ruff format .
```

The test-suite runs against a real, pip-installed `pythonscad` in a virtualenv:

```bash
python -m venv .venv          # create from outside the repo dir, or the local
                              # pybosl2/math.py etc. can shadow stdlib modules
source .venv/bin/activate
pip install -e '.[test]'      # pybosl2 + pytest + numpy + pythonscad + mypy
pytest
```

The `[test]` extra installs the `pythonscad` wheel, which provides the real
`pythonscad`/`openscad` native modules the geometry code imports.

A small number of tests exercise the full **PythonSCAD app** rather than the pip
wheel:

- STL-render tests (`tests/test_stl_render.py`) drive the real PythonSCAD binary
  in a subprocess to export and measure meshes. They skip unless a binary is found
  (set `PYTHONSCAD_BIN`, or install the app to `/Applications`).
- App-only native ops (e.g. `roof()`) skip when the pip wheel does not provide them.

## Documentation

The API docs are built with Sphinx (autodoc + napoleon) straight from the module
docstrings:

```bash
pip install -e '.[docs]'
make -C docs html      # renders into wiki/
```

On push to `main`, the `docs` GitHub Actions workflow builds and publishes them to
**GitHub Pages** (enable Pages with *Settings → Pages → Source: GitHub Actions*).
Examples in the docs embed interactive 3-D STL viewers; the renders are cached under
`docs/_generated/` and `docs/_extra/_stl/` — commit those caches so the images appear
on Pages, since CI has no PythonSCAD binary to render them.

## License

BSD 2-Clause License — see [LICENSE](LICENSE).
