Skip to content

Commit 8ec7724

Browse files
committed
feat: pywrangler init proxies to C3 directly with Python preselected
1 parent d5e46ad commit 8ec7724

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,14 @@ uv run pywrangler sync
3333

3434
### Development
3535

36-
To run the CLI tool while developing it, use:
37-
38-
```bash
39-
export REPO_ROOT=/path/to/repo
40-
uv run --project $REPO_ROOT $REPO_ROOT/src/pywrangler --help
41-
```
42-
43-
On Linux, to install it globally, you may also be able to run:
36+
To run the CLI tool while developing it, install it globally:
4437

4538
```
4639
uv tool install -e .
4740
```
4841

42+
Then run it via `pywrangler`.
43+
4944
Alternatively, you can add `workers-py` to your pyproject.toml:
5045

5146
```

src/pywrangler/cli.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import textwrap
55
import click
66

7-
from .utils import setup_logging, write_success, WRANGLER_COMMAND
7+
from .utils import (
8+
setup_logging,
9+
write_success,
10+
WRANGLER_COMMAND,
11+
WRANGLER_CREATE_COMMAND,
12+
)
813

914
setup_logging()
1015
logger = logging.getLogger("pywrangler")
@@ -60,6 +65,13 @@ def get_command(self, ctx, cmd_name):
6065

6166
check_wrangler_version()
6267

68+
if cmd_name == "init":
69+
# explicitly call `create-cloudflare` so we can instruct it to only show Python templates
70+
_proxy_to_create_cloudflare(
71+
["--lang=python", "--no-deploy"] + remaining_args
72+
)
73+
sys.exit(0)
74+
6375
_proxy_to_wrangler(cmd_name, remaining_args)
6476
sys.exit(0)
6577

@@ -175,3 +187,16 @@ def _proxy_to_wrangler(command_name, args_list):
175187
f"Wrangler not found. Ensure Node.js and Wrangler are installed and in your PATH. Error was: {str(e)}"
176188
)
177189
click.get_current_context().exit(1)
190+
191+
192+
def _proxy_to_create_cloudflare(args_list):
193+
command_to_run = WRANGLER_CREATE_COMMAND + args_list
194+
logger.info(f"Passing command to npx create-cloudflare: {' '.join(command_to_run)}")
195+
try:
196+
process = subprocess.run(command_to_run, check=False, cwd=".")
197+
click.get_current_context().exit(process.returncode)
198+
except FileNotFoundError as e:
199+
logger.error(
200+
f"Create-cloudflare not found. Ensure Node.js and create-cloudflare are installed and in your PATH. Error was: {str(e)}"
201+
)
202+
click.get_current_context().exit(1)

src/pywrangler/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from rich.theme import Theme
88

99
WRANGLER_COMMAND = ["npx", "--yes", "wrangler"]
10+
WRANGLER_CREATE_COMMAND = ["npx", "--yes", "create-cloudflare"]
1011

1112
logger = logging.getLogger(__name__)
1213

0 commit comments

Comments
 (0)