Skip to content

Commit 8cdf43c

Browse files
committed
Add plain-start package
1 parent 708bbb0 commit 8cdf43c

File tree

7 files changed

+298
-0
lines changed

7 files changed

+298
-0
lines changed

plain-start/LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2025, Dropseed, LLC
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

plain-start/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
plain/start/README.md

plain-start/plain/start/README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Plain Start
2+
3+
**Bootstrap a new Plain project from official starter templates.**
4+
5+
## Contents
6+
7+
- [Overview](#overview)
8+
- [Starter types](#starter-types)
9+
- [Options](#options)
10+
- [FAQs](#faqs)
11+
- [Installation](#installation)
12+
13+
## Overview
14+
15+
The `plain-start` command provides a streamlined way to create new Plain projects from official starter templates. It clones the starter repository, configures your project name, and optionally runs the installation script to get you up and running quickly.
16+
17+
Basic usage:
18+
19+
```bash
20+
uvx plain-start my-project
21+
cd my-project
22+
uv run plain dev
23+
```
24+
25+
This creates a new project called `my-project` using the full app starter template (with ORM, auth, admin, etc.).
26+
27+
## Starter types
28+
29+
Plain provides two official starter templates:
30+
31+
### App starter (default)
32+
33+
The app starter includes a full-featured setup with:
34+
35+
- Database ORM
36+
- Authentication system
37+
- Admin interface
38+
- Session management
39+
- All core Plain packages
40+
41+
Create an app starter project:
42+
43+
```bash
44+
uvx plain-start my-app
45+
# or explicitly:
46+
uvx plain-start my-app --type app
47+
```
48+
49+
### Bare starter
50+
51+
The bare starter is a minimal setup with:
52+
53+
- Plain framework core
54+
- Development tools only
55+
- No database or auth by default
56+
57+
Create a bare starter project:
58+
59+
```bash
60+
uvx plain-start my-project --type bare
61+
```
62+
63+
## Options
64+
65+
The [`cli`](./cli.py#cli) command accepts the following options:
66+
67+
### `--type`
68+
69+
Choose between `app` (default) or `bare` starter templates.
70+
71+
```bash
72+
uvx plain-start my-project --type bare
73+
```
74+
75+
### `--no-install`
76+
77+
Skip running the `./scripts/install` script after cloning. Useful if you want to review the project structure before installing dependencies.
78+
79+
```bash
80+
uvx plain-start my-project --no-install
81+
```
82+
83+
## FAQs
84+
85+
#### What does the install script do?
86+
87+
The `./scripts/install` script sets up your Python environment using `uv`, installs dependencies, and runs initial migrations for the database. You can always run it manually later if you use `--no-install`.
88+
89+
#### Can I use plain-start with a specific version?
90+
91+
Yes, you can specify a version using `uvx`:
92+
93+
```bash
94+
uvx plain-start@0.1.0 my-project
95+
```
96+
97+
#### What gets replaced in the project?
98+
99+
The command updates the `name` field in your `pyproject.toml` to match your project name. All other configuration remains as-is for you to customize.
100+
101+
## Installation
102+
103+
Install and run `plain-start` using `uvx` (recommended):
104+
105+
```bash
106+
uvx plain-start my-project
107+
```
108+
109+
Or install it globally:
110+
111+
```bash
112+
uv tool install plain-start
113+
plain-start my-project
114+
```
115+
116+
The command clones the starter template, configures your project name, initializes a new git repository, and runs the installation script (unless you pass `--no-install`).

plain-start/plain/start/__init__.py

Whitespace-only changes.

plain-start/plain/start/cli.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import re
2+
import shutil
3+
import subprocess
4+
from pathlib import Path
5+
6+
import click
7+
8+
STARTER_REPOS = {
9+
"app": "https://github.com/dropseed/plain-starter-app",
10+
"bare": "https://github.com/dropseed/plain-starter-bare",
11+
}
12+
13+
14+
@click.command()
15+
@click.argument("project_name")
16+
@click.option(
17+
"--type",
18+
"starter_type",
19+
type=click.Choice(["app", "bare"]),
20+
default="app",
21+
help="Type of starter template to use",
22+
)
23+
@click.option(
24+
"--no-install",
25+
is_flag=True,
26+
help="Skip running ./scripts/install after setup",
27+
)
28+
def cli(project_name: str, starter_type: str, no_install: bool) -> None:
29+
"""Bootstrap a new Plain project from starter templates"""
30+
project_path = Path.cwd() / project_name
31+
32+
if project_path.exists():
33+
click.secho(
34+
f"Error: Directory '{project_name}' already exists", fg="red", err=True
35+
)
36+
raise click.Abort()
37+
38+
# Clone the starter repository
39+
repo_url = STARTER_REPOS[starter_type]
40+
click.secho(f"Cloning {starter_type} starter template...", dim=True)
41+
42+
try:
43+
subprocess.run(
44+
["git", "clone", "--depth", "1", repo_url, project_name],
45+
check=True,
46+
capture_output=True,
47+
)
48+
except subprocess.CalledProcessError as e:
49+
click.secho(
50+
f"Error cloning repository: {e.stderr.decode()}", fg="red", err=True
51+
)
52+
raise click.Abort()
53+
54+
# Remove .git directory and reinitialize
55+
click.secho("Initializing new git repository...", dim=True)
56+
git_dir = project_path / ".git"
57+
if git_dir.exists():
58+
shutil.rmtree(git_dir)
59+
60+
subprocess.run(
61+
["git", "init"],
62+
cwd=project_path,
63+
check=True,
64+
capture_output=True,
65+
)
66+
67+
# Replace project name in pyproject.toml
68+
click.secho("Configuring project...", dim=True)
69+
pyproject_path = project_path / "pyproject.toml"
70+
71+
if pyproject_path.exists():
72+
content = pyproject_path.read_text()
73+
# Replace the name field in pyproject.toml
74+
# Matches: name = "anything" or name = 'anything'
75+
content = re.sub(
76+
r'^name\s*=\s*["\'].*?["\']',
77+
f'name = "{project_name}"',
78+
content,
79+
count=1,
80+
flags=re.MULTILINE,
81+
)
82+
pyproject_path.write_text(content)
83+
84+
# Run install script unless --no-install
85+
if not no_install:
86+
install_script = project_path / "scripts" / "install"
87+
if install_script.exists():
88+
click.echo(
89+
click.style("Running installation:", bold=True)
90+
+ click.style(" ./scripts/install", dim=True)
91+
)
92+
try:
93+
subprocess.run(
94+
["./scripts/install"],
95+
cwd=project_path,
96+
check=True,
97+
)
98+
except subprocess.CalledProcessError as e:
99+
click.secho(
100+
f"Warning: Installation script failed with exit code {e.returncode}",
101+
fg="yellow",
102+
err=True,
103+
)
104+
click.secho(
105+
"You may need to run './scripts/install' manually.",
106+
fg="yellow",
107+
err=True,
108+
)
109+
110+
# Success message
111+
click.echo()
112+
click.secho(
113+
f"✓ Project '{project_name}' created successfully!", fg="green", bold=True
114+
)
115+
click.echo()
116+
click.secho("Next steps:", bold=True)
117+
click.secho(f" cd {project_name}")
118+
if no_install:
119+
click.secho(" ./scripts/install")
120+
click.secho(" uv run plain dev")

plain-start/pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[project]
2+
name = "plain.start"
3+
version = "0.0.0"
4+
description = "Bootstrap a new Plain project from starter templates"
5+
authors = [{name = "Dave Gaeddert", email = "dave.gaeddert@dropseed.dev"}]
6+
license = "BSD-3-Clause"
7+
readme = "README.md"
8+
requires-python = ">=3.13"
9+
dependencies = [
10+
"click>=8.0.0",
11+
]
12+
13+
[project.scripts]
14+
"plain-start" = "plain.start.cli:cli"
15+
16+
[tool.hatch.build.targets.wheel]
17+
packages = ["plain"]
18+
19+
[build-system]
20+
requires = ["hatchling"]
21+
build-backend = "hatchling.build"

uv.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)