From 50061c313e3cedf1d0bf77450b118c9295252163 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Tue, 9 Dec 2025 17:20:50 +0545 Subject: [PATCH] fix(templates): fix justfile syntax and update readme --- djinit/templates/project/ci/github_actions.j2 | 4 +- djinit/templates/project/justfile.j2 | 65 +++++++++++++++++++ djinit/templates/project/readme.j2 | 10 ++- 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/djinit/templates/project/ci/github_actions.j2 b/djinit/templates/project/ci/github_actions.j2 index 6200b9c..e9dbe7a 100644 --- a/djinit/templates/project/ci/github_actions.j2 +++ b/djinit/templates/project/ci/github_actions.j2 @@ -31,10 +31,10 @@ jobs: steps: - uses: actions/checkout@v4 - {% raw %}- name: Set up Python ${{ matrix.python-version }}{% endraw %} + - name: Set up Python {{ '{{ matrix.python-version }}' }} uses: actions/setup-python@v5 with: - {% raw %}python-version: ${{ matrix.python-version }}{% endraw %} + python-version: {{ '{{ matrix.python-version }}' }} - name: Install uv uses: astral-sh/setup-uv@v4 diff --git a/djinit/templates/project/justfile.j2 b/djinit/templates/project/justfile.j2 index a4e0052..b5e511d 100644 --- a/djinit/templates/project/justfile.j2 +++ b/djinit/templates/project/justfile.j2 @@ -128,9 +128,74 @@ clean: rm -rf htmlcov/ rm -rf .pytest_cache/ +# Pin dependencies in pyproject.toml using versions from uv.lock, keeping >= and extras +pin-deps: + #!/usr/bin/env -S uv run python + import tomllib, re + from pathlib import Path + + lock = Path("uv.lock") + if not lock.exists(): + print("uv.lock not found — run `uv sync` first") + raise SystemExit(0) + + data = tomllib.loads(lock.read_text()) + packages = {p["name"].lower(): p["version"] for p in data.get("package", [])} + + py = Path("pyproject.toml") + lines = py.read_text().splitlines() + + pattern = re.compile(r'^(\s*)"([^"]+)"(,?)') + + out = [] + for line in lines: + m = pattern.match(line) + if not m: + out.append(line) + continue + + indent, dep, comma = m.groups() + + base = dep + extras = "" + operator = ">=" + version = None + + # extras: django[postgres] + if "[" in base and "]" in base: + before, after = base.split("[", 1) + extras = "[" + after.split("]")[0] + "]" + base = before + + # detect >= or == + if ">=" in dep: + operator = ">=" + base, version = dep.split(">=") + base = base.strip() + elif "==" in dep: + operator = "==" + base, version = dep.split("==") + base = base.strip() + else: + base = dep + + base_lower = base.lower() + new_version = packages.get(base_lower) + + if new_version: + new_dep = f'{base}{extras}{operator}{new_version}' + line = f'{indent}"{new_dep}"{comma}' + + out.append(line) + + py.write_text("\n".join(out) + "\n") + print("Pinned dependencies (>= preserved, extras preserved).") + + # Setup project for development (using uv) setup: uv sync + just pin-deps uv run python manage.py migrate uv run python manage.py createsuperuser diff --git a/djinit/templates/project/readme.j2 b/djinit/templates/project/readme.j2 index 515dbbf..1aac23c 100644 --- a/djinit/templates/project/readme.j2 +++ b/djinit/templates/project/readme.j2 @@ -1,6 +1,6 @@ # {{ project_name }} -A Django project created with [djinitx/djinit/dj](https://github.com/S4NKALP/djinit). +A Django project folder structure is generated with [djinitx/djinit/dj](https://github.com/S4NKALP/djinit). ## Features @@ -62,6 +62,11 @@ Run `just` to see all available commands, including: - `just format` - Format code - `just shell` - Django shell - `just clean` - Clean cache files +- `just install ` - Install package +- `just remove ` - Remove package +- `just server` - Run production server +- `just ci` - Run all linting and checks +- `just test-coverage` - Run tests with coverage ## Project Structure @@ -107,6 +112,7 @@ Run `just` to see all available commands, including: ├── manage.py ├── requirements.txt ├── pyproject.toml +├── uv.lock ├── .env.sample ├── justfile ├── Procfile @@ -146,6 +152,7 @@ Run `just` to see all available commands, including: ├── manage.py ├── requirements.txt ├── pyproject.toml +├── uv.lock ├── .env.sample ├── justfile ├── Procfile @@ -173,6 +180,7 @@ Run `just` to see all available commands, including: ├── manage.py ├── requirements.txt ├── pyproject.toml +├── uv.lock ├── .env.sample └── README.md