Skip to content

Commit acd42a8

Browse files
create-cloudflare: add types/autocomplete for Python projects (#8197)
* create-cloudflare: add types/autocomplete for Python projects * update the <TBD> to project name in new python files --------- Co-authored-by: Peter Bacon Darwin <[email protected]>
1 parent 5b047e4 commit acd42a8

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed

.changeset/salty-bugs-begin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-cloudflare": minor
3+
---
4+
5+
Python Workers template now includes package for autocomplete and type hints

packages/create-cloudflare/templates/hello-world/c3.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1+
import { readFile, writeFile } from "node:fs/promises";
2+
import { resolve } from "node:path";
3+
import type { TemplateConfig } from "../../src/templates";
4+
15
export default {
26
configVersion: 1,
37
id: "hello-world",
48
displayName: "Hello World Worker",
59
description: "Get started with a basic Worker in the language of your choice",
610
platform: "workers",
11+
async configure(ctx) {
12+
if (ctx.args.lang === "python") {
13+
for (const file of ["pyproject.toml", "uv.lock"]) {
14+
const contents = await readFile(
15+
resolve(ctx.project.path, file),
16+
"utf8",
17+
);
18+
const updated = contents.replaceAll(/<TBD>/g, ctx.project.name);
19+
await writeFile(resolve(ctx.project.path, file), updated);
20+
}
21+
}
22+
},
723
copyFiles: {
824
variants: {
925
js: {
@@ -17,4 +33,4 @@ export default {
1733
},
1834
},
1935
},
20-
};
36+
} satisfies TemplateConfig;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Usage
2+
3+
You can run the worker defined by your new project by executing `wrangler dev` in this
4+
directory. This will start up an HTTP server and will allow you to iterate on your
5+
worker without having to restart `wrangler`.
6+
7+
### Types and autocomplete
8+
9+
This project also includes a pyproject.toml and uv.lock file with some requirements which
10+
set up autocomplete and type hints for this Python Workers project. To get these installed
11+
you can run the following:
12+
13+
```
14+
uv venv
15+
uv sync
16+
```
17+
18+
Then point your editor's Python plugin at the `.venv` directory.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "<TBD>"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = [
8+
"webtypy>=0.1.7",
9+
]

packages/create-cloudflare/templates/hello-world/py/uv.lock

Lines changed: 22 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)