|
| 1 | + |
| 2 | +# Scaffold Python Package – Create & Launch New Project |
| 3 | + |
| 4 | +## 🎯 Purpose |
| 5 | +Implement a scaffolding project that allows you to launch new Python packages with full setup: `uv` venv management, `pyproject.toml`, `pytest + coverage`, `Sphinx` docs, Git repo, CI config. |
| 6 | + |
| 7 | +## ✅ Inputs |
| 8 | +- `package_name` — Package name (PEP 8 valid, e.g. `my_cool_pkg`) |
| 9 | +- `target_dir` — Absolute path to parent directory where the project folder will be created |
| 10 | + |
| 11 | +## ✅ Sequence of Tasks |
| 12 | + |
| 13 | +### 1. Validate inputs |
| 14 | +- [ ] Run shell script to check `package_name` matches `[a-zA-Z_][a-zA-Z0-9_]*` |
| 15 | +- [ ] Ensure `target_dir` is an absolute path |
| 16 | +```bash |
| 17 | +set -e |
| 18 | +PKG="${package_name}" |
| 19 | +DIR="${target_dir}" |
| 20 | +python3 - <<'PY' |
| 21 | +import re, sys, os |
| 22 | +pkg=sys.argv[1]; dir_=sys.argv[2] |
| 23 | +if not re.fullmatch(r'[a-zA-Z_][a-zA-Z0-9_]*', pkg): |
| 24 | + print(f"Invalid package_name: {pkg}"); sys.exit(1) |
| 25 | +if not os.path.isabs(dir_): |
| 26 | + print(f"target_dir must be absolute: {dir_}"); sys.exit(1) |
| 27 | +print("Inputs OK.") |
| 28 | +PY "$PKG" "$DIR" |
| 29 | +```` |
| 30 | + |
| 31 | +### 2. Prepare template workspace |
| 32 | + |
| 33 | +* [ ] Create a temporary workspace `.cline_tmp_pkg_template` |
| 34 | +* [ ] Within it, create directory structure for TEMPLATE: |
| 35 | + |
| 36 | + * `TEMPLATE/{{PKG}}/` |
| 37 | + * `TEMPLATE/tests/` |
| 38 | + * `TEMPLATE/docs/` |
| 39 | + * `TEMPLATE/.github/workflows/` |
| 40 | +* [ ] Add the following files in TEMPLATE (with placeholder `{{PKG}}` inside): |
| 41 | + |
| 42 | + * `pyproject.toml` |
| 43 | + * `README.md` |
| 44 | + * `LICENSE` |
| 45 | + * `.gitignore` |
| 46 | + * `.github/workflows/ci.yaml` |
| 47 | + * `{{PKG}}/__init__.py`, `{{PKG}}/hello.py` |
| 48 | + * `tests/test_hello.py` |
| 49 | + * `docs/conf.py`, `docs/index.rst` |
| 50 | + * `requirements-dev.txt` |
| 51 | + * `Makefile` |
| 52 | + * Optional `setup.cfg` or patch file for dev-extras |
| 53 | + |
| 54 | +### 3. Materialize project & substitute placeholders |
| 55 | + |
| 56 | +* [ ] Compute `DEST="${target_dir}/${package_name}"` |
| 57 | +* [ ] Fail if `DEST` already exists |
| 58 | +* [ ] Copy all files from workspace TEMPLATE to `${DEST}` |
| 59 | +* [ ] Recursively replace placeholder `{{PKG}}` with actual `package_name` in all files |
| 60 | +* [ ] Print “Project created at: ${DEST}” |
| 61 | + |
| 62 | +### 4. Initialize git repository |
| 63 | + |
| 64 | +* [ ] `cd` into `${DEST}` |
| 65 | +* [ ] `git init` |
| 66 | +* [ ] `git add .` |
| 67 | +* [ ] `git commit -m "chore: initial scaffold"` |
| 68 | +* [ ] Print “Git repo initialized.” |
| 69 | + |
| 70 | +### 5. Setup `uv` environment & install dev extras |
| 71 | + |
| 72 | +* [ ] `cd "${DEST}"` |
| 73 | +* [ ] `uv venv` |
| 74 | +* [ ] `uv pip install -e ".[dev]"` |
| 75 | +* [ ] Print “Environment ready.” |
| 76 | + |
| 77 | +### 6. Run tests & coverage |
| 78 | + |
| 79 | +* [ ] `cd "${DEST}"` |
| 80 | +* [ ] `uv run pytest --cov="${package_name}" --cov-report=term-missing` |
| 81 | + |
| 82 | +### 7. Build Sphinx documentation |
| 83 | + |
| 84 | +* [ ] `cd "${DEST}"` |
| 85 | +* [ ] `uv run sphinx-build -b html docs docs/_build/html` |
| 86 | +* [ ] Print “Docs built at: docs/_build/html” |
| 87 | + |
| 88 | +### 8. Output summary |
| 89 | + |
| 90 | +* [ ] Print “Scaffold complete.” |
| 91 | +* [ ] Print project path: `${DEST}` |
| 92 | +* [ ] Print next steps: |
| 93 | + |
| 94 | + ```text |
| 95 | + cd "${DEST}" |
| 96 | + source .venv/bin/activate # (or use uv run) |
| 97 | + uv run python -c "import ${package_name}; print(${package_name}.hello())" |
| 98 | + ``` |
| 99 | + |
| 100 | +## 📁 Generated Structure |
| 101 | + |
| 102 | +``` |
| 103 | +${package_name}/ |
| 104 | + .github/workflows/ci.yaml |
| 105 | + docs/ |
| 106 | + conf.py |
| 107 | + index.rst |
| 108 | + _build/ (after docs build) |
| 109 | + tests/ |
| 110 | + test_hello.py |
| 111 | + ${package_name}/ |
| 112 | + __init__.py |
| 113 | + hello.py |
| 114 | + .gitignore |
| 115 | + LICENSE |
| 116 | + Makefile |
| 117 | + README.md |
| 118 | + pyproject.toml |
| 119 | + requirements-dev.txt |
| 120 | + setup.cfg |
| 121 | +``` |
| 122 | + |
| 123 | +## 📝 Notes |
| 124 | + |
| 125 | +* Uses `uv` for virtualenv management. |
| 126 | +* Configured for `pytest + pytest-cov`. |
| 127 | +* Sphinx docs with theme `furo` (can edit in `docs/conf.py`). |
| 128 | +* Dev extras via `pyproject.toml` optional-deps. |
| 129 | +* CI workflow provided in `.github/workflows/ci.yaml`. |
| 130 | + |
| 131 | +``` |
0 commit comments