"""Packaging sanity: pyproject.toml is parseable and declares expected metadata. Verifies the metadata we rely on (name, version, console-script entry points) is well-formed, so `pip install .` + `fastengen` CLI work. Runs without network or install; reads the toml file directly (Python 3.11+ tomllib) or a minimal fallback parser for 3.10. No em-dash in code: Python 3.10 source lacks UTF-8 mode (no PEP 540). """ from __future__ import annotations import os import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src")) try: import tomllib # Python 3.11+ def _load_toml(path: str) -> dict: with open(path, "rb") as f: return tomllib.load(f) except ModuleNotFoundError: # Python 3.10 tomllib = None def _load_toml(path: str) -> dict: # Minimal parser for the flat pyproject we own: name/version/deps/scripts. # Sufficient to assert presence of the keys we depend on. # configparser can't parse TOML; fall back to simple key scanning. text = open(path, encoding="utf-8").read() def _field(name): import re m = re.search(name + r'\s*=\s*"([^"]+)"', text) return m.group(1) if m else None return { "name": _field("name"), "version": _field("version"), "scripts_present": "fastengen" in text, } PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) def _pyproject(): return _load_toml(os.path.join(PROJECT_ROOT, "pyproject.toml")) def test_pyproject_has_name_and_version(): cfg = _pyproject() # tomllib result has [project] table; minimal fallback has top-level keys. if tomllib is not None: assert cfg["project"]["name"] assert cfg["project"]["version"] assert "cadquery" in cfg["project"]["dependencies"] assert "fastengen" in cfg["project"]["scripts"] else: assert cfg["name"] == "FastenGen" assert cfg["version"] assert cfg["scripts_present"]