Source code for jitxlib.gerber

"""Export Gerber X2/X3 fabrication data from JITX designs.

The package splits in two: `format` is a standalone Gerber/XNC/gbrjob writer
with no JITX dependencies, and `extract` populates the format model from a
captured JITX RuntimeDesign. The `plugin` module registers the jitx export
entry point.

`export_gerber` is the Python API. It exists alongside the plugin rather than
behind it because the plugin registry derives its command-line flags from the
signature of `export`, so everything reachable that way is a flat scalar: a
caller that wants to pass a configured naming strategy, or to be told which
files were written, needs a door that is not the CLI's.

See `plans/gerber-export-plan.md` for the design and §9 for the milestones.
"""

from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING

from .format.compat import DEFAULT as DEFAULT_COMPAT
from .format.compat import Compat
from .format.model import DrillFormat
from .format.naming import FileNaming

if TYPE_CHECKING:
    from jitx.run import RuntimeDesign

    from .extract.job import GerberResult

__all__ = ["Compat", "DrillFormat", "FileNaming", "export_gerber"]


[docs] def export_gerber( design: "RuntimeDesign", *, output: Path, naming: str | FileNaming = "descriptive", overwrite: bool = False, drill_format: DrillFormat = DrillFormat.GERBER, creation_date: str | None = None, compat: Compat = DEFAULT_COMPAT, ) -> "GerberResult": """Write a complete Gerber data set for a captured design. Args: output: the directory to write into, or a path ending in `.zip`, which writes exactly that archive with the files at its root - the layout fab upload forms expect - and nothing beside it. Nothing here ever removes a directory; `overwrite` is permission to replace a previous export of ours, file by file, and never more than that. naming: a registered scheme name or a `FileNaming` strategy object. drill_format: which format the drill files are written in. Exactly one, never both. creation_date: ISO 8601 with a time zone, overriding the clock, for reproducible output. compat: output adjustments for readers that deviate from the specification; none by default. Returns: The output path, the archive when the output was one, and every file with the file function that describes it. """ from .extract.job import export return export( design, output=output, naming_scheme=naming, overwrite=overwrite, creation_date=creation_date, drill_format=drill_format, compat=compat, )