plain.dev 0.0.1__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
plain/dev/README.md CHANGED
@@ -1,34 +1,34 @@
1
- # plain-dev
1
+ # plain.dev
2
2
 
3
- A single command to run everything you need for local Plain development.
3
+ A single command that runs everything you need for local development.
4
4
 
5
- ![Plain work command example](https://user-images.githubusercontent.com/649496/176533533-cfd44dc5-afe5-42af-8b5d-33a9fa23f8d9.gif)
5
+ ![Plain dev command example](https://github.com/dropseed/plain/assets/649496/3643bb64-a99b-4a8e-adab-8c6b81791ea9)
6
6
 
7
- The `plain dev` command runs a combination of local commands + a Docker container for your database.
7
+ The `plain.dev` package can be [installed from PyPI](https://pypi.org/project/plain.dev/), and does *not* need to be added to `INSTALLED_PACKAGES`.
8
8
 
9
- The following processes will run simultaneously (some will only run if they are detected as available):
9
+ - [`plain dev`](#plain-dev)
10
+ - [`plain dev services`](#plain-dev-services)
11
+ - [`plain pre-commit`](#plain-pre-commit)
12
+ - [`plain contrib`](#plain-contrib)
13
+ - [VS Code debugging](#vscode-debugging)
10
14
 
11
- <!-- - [`manage.py runserver` (and migrations)](#runserver)
12
- - [`plain-models start --logs`](#plain-models)
13
- - [`plain-tailwind compile --watch`](#plain-tailwind)
14
- - [`npm run watch`](#package-json)
15
- - [`stripe listen --forward-to`](#stripe)
16
- - [`ngrok http --subdomain`](#ngrok)
15
+ ## `plain dev`
17
16
 
18
- It also comes with [debugging](#debugging) tools to make local debugging easier with VS Code. -->
17
+ The `plain dev` command does several things:
19
18
 
20
- ## Installation
19
+ - Sets `PLAIN_CSRF_TRUSTED_ORIGINS` to localhost by default
20
+ - Runs `plain preflight` to check for any issues
21
+ - Executes any pending model migrations
22
+ - Starts `gunicorn` with `--reload`
23
+ - Runs `plain tailwind compile --watch`, if `plain.tailwind` is installed
24
+ - Any custom process defined in `pyproject.toml` at `tool.plain.dev.run`
25
+ - Necessary services (ex. Postgres) defined in `pyproject.toml` at `tool.plain.dev.services`
21
26
 
22
- ```sh
23
- pip install plain-dev
24
- ```
27
+ ### Services
25
28
 
26
- If you have `plain-models` installed (i.e. you're using a database),
27
- then add `DATABASE_URL` to your `.env` file.
29
+ Use services to define databases or other processes that your app *needs* to be functional. The services will be started automatically in `plain dev`, but also in `plain pre-commit` (so preflight and tests have a database).
28
30
 
29
- ```sh
30
- DATABASE_URL=postgres://postgres:postgres@localhost:54321/postgres
31
- ```
31
+ Ultimately, how you run your development database is up to you. But a recommended starting point is to use Docker:
32
32
 
33
33
  ```toml
34
34
  # pyproject.toml
@@ -36,59 +36,41 @@ DATABASE_URL=postgres://postgres:postgres@localhost:54321/postgres
36
36
  postgres = {cmd = "docker run --name app-postgres --rm -p 54321:5432 -v $(pwd)/.plain/dev/pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=postgres postgres:15 postgres"}
37
37
  ```
38
38
 
39
- ```sh
40
- plain dev
41
- ```
42
-
43
- ## `plain dev`
44
-
45
- ### Default processes
46
-
47
- - plain preflight
48
- - gunicorn
49
- - migrations
50
- - tailwind
51
-
52
39
  ### Custom processes
53
40
 
54
- - package.json "dev" script
55
- - pyproject.toml `tool.plain.dev.run = {command = "..."}`
56
-
57
- ### GitHub Codespaces
58
-
59
- The `BASE_URL` setting is automatically set to the Codespace URL.
60
-
61
- TODO
62
-
63
- ## `plain dev db`
64
-
65
- Only supports Postgres currently.
66
-
67
- - snapshot
68
- - import
69
- - export
41
+ Unlike [services](#services), custom processes are *only* run during `plain dev`. This is a good place to run something like [ngrok](https://ngrok.com/) or a [Plain worker](../../../plain-worker), which you might need to use your local site, but don't need running for executing tests, for example.
70
42
 
43
+ ```toml
44
+ # pyproject.toml
45
+ [tool.plain.dev.run]
46
+ ngrok = {command = "ngrok http $PORT"}
47
+ ```
71
48
 
72
- ## Development processes
49
+ ## `plain dev services`
73
50
 
74
- ### Gunicorn
51
+ Starts your [services](#services) by themselves.
75
52
 
76
- The key process here is still `manage.py runserver`.
77
- But, before that runs, it will also wait for the database to be available and run `manage.py migrate`.
53
+ ## `plain pre-commit`
78
54
 
79
- ### plain-models
55
+ A built-in pre-commit hook that can be installed with `plain pre-commit --install`.
80
56
 
81
- If [`plain-models`](https://github.com/plainpackages/plain-models) is installed, it will automatically start and show the logs of the running database container.
57
+ Runs:
82
58
 
83
- ### plain-tailwind
59
+ - Custom commands defined in `pyproject.toml` at `tool.plain.pre-commit.run`
60
+ - `plain code check`, if [`plain.code`](https://plainframework.com/docs/plain-code/plain/code/) is installed
61
+ - `poetry check --lock`, if using [Poetry](https://python-poetry.org/)
62
+ - `plain preflight --database default`
63
+ - `plain legacy migrate --check`
64
+ - `plain legacy makemigrations --dry-run --check`
65
+ - `plain compile`
66
+ - `plain test`
84
67
 
85
- If [`plain-tailwind`](https://github.com/plainpackages/plain-tailwind) is installed, it will automatically run the Tailwind `compile --watch` process.
68
+ ## VS Code debugging
86
69
 
87
- ## Debugging
70
+ ![Debug Plain with VS Code](https://github.com/dropseed/plain-public/assets/649496/250138b6-7702-4ab6-bf38-e0c8e3c56d06)
88
71
 
89
- [View on YouTube ](https://www.youtube.com/watch?v=pG0KaJSVyBw)
72
+ Since `plain dev` runs multiple processes at once, the regular [pdb](https://docs.python.org/3/library/pdb.html) debuggers don't quite work.
90
73
 
91
- Since `plain work` runs multiple processes at once, the regular [pdb](https://docs.python.org/3/library/pdb.html) debuggers can be hard to use.
92
74
  Instead, we include [microsoft/debugpy](https://github.com/microsoft/debugpy) and an `attach` function to make it even easier to use VS Code's debugger.
93
75
 
94
76
  First, import and run the `debug.attach()` function:
@@ -97,13 +79,13 @@ First, import and run the `debug.attach()` function:
97
79
  class HomeView(TemplateView):
98
80
  template_name = "home.html"
99
81
 
100
- def get_context(self, **kwargs):
101
- context = super().get_context(**kwargs)
82
+ def get_template_context(self):
83
+ context = super().get_template_context()
102
84
 
103
85
  # Make sure the debugger is attached (will need to be if runserver reloads)
104
- from plain.work import debug; debug.attach()
86
+ from plain.dev import debug; debug.attach()
105
87
 
106
- # Add a breakpoint (or use the gutter in VSCode to add one)
88
+ # Add a breakpoint (or use the gutter in VS Code to add one)
107
89
  breakpoint()
108
90
 
109
91
  return context
@@ -111,38 +93,4 @@ class HomeView(TemplateView):
111
93
 
112
94
  When you load the page, you'll see "Waiting for debugger to attach...".
113
95
 
114
- Add a new VS Code debug configuration (using localhost and port 5768) by saving this to `.vscode/launch.json` or using the GUI:
115
-
116
- ```json
117
- // .vscode/launch.json
118
- {
119
- // Use IntelliSense to learn about possible attributes.
120
- // Hover to view descriptions of existing attributes.
121
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
122
- "version": "0.2.0",
123
- "configurations": [
124
- {
125
- "name": "Plain: Attach to Django",
126
- "type": "python",
127
- "request": "attach",
128
- "connect": {
129
- "host": "localhost",
130
- "port": 5678
131
- },
132
- "pathMappings": [
133
- {
134
- "localRoot": "${workspaceFolder}",
135
- "remoteRoot": "."
136
- }
137
- ],
138
- "justMyCode": true,
139
- "django": true
140
- }
141
- ]
142
- }
143
- ```
144
-
145
- Then in the "Run and Debug" tab, you can click the green arrow next to "Plain: Attach to Django" to start the debugger.
146
-
147
- In your terminal is should tell you it was attached, and when you hit a breakpoint you'll see the debugger information in VS Code.
148
- If Django's runserver reloads, you'll be prompted to reattach by clicking the green arrow again.
96
+ You can then run the VS Code debugger and attach to an existing Python process, at localhost:5678.
@@ -61,7 +61,7 @@ def cli(install):
61
61
  check_short("Running plain code checks", "plain", "code", "check")
62
62
 
63
63
  if Path("poetry.lock").exists():
64
- check_short("Checking poetry.lock", "poetry", "lock", "--check")
64
+ check_short("Checking poetry.lock", "poetry", "check", "--lock")
65
65
 
66
66
  if plain_db_connected():
67
67
  check_short(
@@ -0,0 +1,124 @@
1
+ Metadata-Version: 2.1
2
+ Name: plain.dev
3
+ Version: 0.2.0
4
+ Summary: Local development tools for Plain.
5
+ Home-page: https://plainframework.com
6
+ License: BSD-3-Clause
7
+ Author: Dave Gaeddert
8
+ Author-email: dave.gaeddert@dropseed.dev
9
+ Requires-Python: >=3.11,<4.0
10
+ Classifier: License :: OSI Approved :: BSD License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Dist: click (>=8.0.0)
15
+ Requires-Dist: debugpy (>=1.6.3,<2.0.0)
16
+ Requires-Dist: gunicorn (>20)
17
+ Requires-Dist: honcho (>=1.1.0,<2.0.0)
18
+ Requires-Dist: plain (<1.0.0)
19
+ Requires-Dist: psycopg2-binary (>=2.9.3,<3.0.0)
20
+ Requires-Dist: requests (>=2.0.0)
21
+ Requires-Dist: tomli (>=2.0.1,<3.0.0) ; python_version < "3.11"
22
+ Project-URL: Documentation, https://plainframework.com/docs/
23
+ Project-URL: Repository, https://github.com/dropseed/plain
24
+ Description-Content-Type: text/markdown
25
+
26
+ <!-- This file is compiled from plain-dev/plain/dev/README.md. Do not edit this file directly. -->
27
+
28
+ # plain.dev
29
+
30
+ A single command that runs everything you need for local development.
31
+
32
+ ![Plain dev command example](https://github.com/dropseed/plain/assets/649496/3643bb64-a99b-4a8e-adab-8c6b81791ea9)
33
+
34
+ The `plain.dev` package can be [installed from PyPI](https://pypi.org/project/plain.dev/), and does *not* need to be added to `INSTALLED_PACKAGES`.
35
+
36
+ - [`plain dev`](#plain-dev)
37
+ - [`plain dev services`](#plain-dev-services)
38
+ - [`plain pre-commit`](#plain-pre-commit)
39
+ - [`plain contrib`](#plain-contrib)
40
+ - [VS Code debugging](#vscode-debugging)
41
+
42
+ ## `plain dev`
43
+
44
+ The `plain dev` command does several things:
45
+
46
+ - Sets `PLAIN_CSRF_TRUSTED_ORIGINS` to localhost by default
47
+ - Runs `plain preflight` to check for any issues
48
+ - Executes any pending model migrations
49
+ - Starts `gunicorn` with `--reload`
50
+ - Runs `plain tailwind compile --watch`, if `plain.tailwind` is installed
51
+ - Any custom process defined in `pyproject.toml` at `tool.plain.dev.run`
52
+ - Necessary services (ex. Postgres) defined in `pyproject.toml` at `tool.plain.dev.services`
53
+
54
+ ### Services
55
+
56
+ Use services to define databases or other processes that your app *needs* to be functional. The services will be started automatically in `plain dev`, but also in `plain pre-commit` (so preflight and tests have a database).
57
+
58
+ Ultimately, how you run your development database is up to you. But a recommended starting point is to use Docker:
59
+
60
+ ```toml
61
+ # pyproject.toml
62
+ [tool.plain.dev.services]
63
+ postgres = {cmd = "docker run --name app-postgres --rm -p 54321:5432 -v $(pwd)/.plain/dev/pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=postgres postgres:15 postgres"}
64
+ ```
65
+
66
+ ### Custom processes
67
+
68
+ Unlike [services](#services), custom processes are *only* run during `plain dev`. This is a good place to run something like [ngrok](https://ngrok.com/) or a [Plain worker](../../../plain-worker), which you might need to use your local site, but don't need running for executing tests, for example.
69
+
70
+ ```toml
71
+ # pyproject.toml
72
+ [tool.plain.dev.run]
73
+ ngrok = {command = "ngrok http $PORT"}
74
+ ```
75
+
76
+ ## `plain dev services`
77
+
78
+ Starts your [services](#services) by themselves.
79
+
80
+ ## `plain pre-commit`
81
+
82
+ A built-in pre-commit hook that can be installed with `plain pre-commit --install`.
83
+
84
+ Runs:
85
+
86
+ - Custom commands defined in `pyproject.toml` at `tool.plain.pre-commit.run`
87
+ - `plain code check`, if [`plain.code`](https://plainframework.com/docs/plain-code/plain/code/) is installed
88
+ - `poetry check --lock`, if using [Poetry](https://python-poetry.org/)
89
+ - `plain preflight --database default`
90
+ - `plain legacy migrate --check`
91
+ - `plain legacy makemigrations --dry-run --check`
92
+ - `plain compile`
93
+ - `plain test`
94
+
95
+ ## VS Code debugging
96
+
97
+ ![Debug Plain with VS Code](https://github.com/dropseed/plain-public/assets/649496/250138b6-7702-4ab6-bf38-e0c8e3c56d06)
98
+
99
+ Since `plain dev` runs multiple processes at once, the regular [pdb](https://docs.python.org/3/library/pdb.html) debuggers don't quite work.
100
+
101
+ Instead, we include [microsoft/debugpy](https://github.com/microsoft/debugpy) and an `attach` function to make it even easier to use VS Code's debugger.
102
+
103
+ First, import and run the `debug.attach()` function:
104
+
105
+ ```python
106
+ class HomeView(TemplateView):
107
+ template_name = "home.html"
108
+
109
+ def get_template_context(self):
110
+ context = super().get_template_context()
111
+
112
+ # Make sure the debugger is attached (will need to be if runserver reloads)
113
+ from plain.dev import debug; debug.attach()
114
+
115
+ # Add a breakpoint (or use the gutter in VS Code to add one)
116
+ breakpoint()
117
+
118
+ return context
119
+ ```
120
+
121
+ When you load the page, you'll see "Waiting for debugger to attach...".
122
+
123
+ You can then run the VS Code debugger and attach to an existing Python process, at localhost:5678.
124
+
@@ -1,4 +1,4 @@
1
- plain/dev/README.md,sha256=WUuS441Nn0hiolb105wXPiip4l-WN_K_FU7bvwrPg58,4393
1
+ plain/dev/README.md,sha256=XQEE75kBhUC3gf2GtMIfqCWYZ5E97xZnCZLuxTLiX-I,3713
2
2
  plain/dev/__init__.py,sha256=C1JrkNE5XX2DLgBXXLAV_UyhofwVd0ZPL59fPUMbOKo,139
3
3
  plain/dev/cli.py,sha256=hOQuAAGsMZ2tkFlDNfYl393Kn-QLhN4ruF1N5BZBzDQ,4859
4
4
  plain/dev/config.py,sha256=h6o5YZtJhg-cFIWoqIDWuMCC5T09cxEsBaa3BP4Nii0,632
@@ -11,15 +11,15 @@ plain/dev/debug.py,sha256=fIrecLfAK_lXSDyn3WmYikzZSse3KY47xcVVbZqJGhk,294
11
11
  plain/dev/default_settings.py,sha256=uXWYORWP_aRDwXIFXdu5kHyiBFUZzARIJdhPeFaX35c,75
12
12
  plain/dev/pid.py,sha256=gRMBf7aGndrra1TnmKtPghTijnd0i0Xeo63mzfPWp7M,436
13
13
  plain/dev/precommit/__init__.py,sha256=9ByBOIdM8DebChjNz-RH2atdz4vWe8somlwNEsbhwh4,40
14
- plain/dev/precommit/cli.py,sha256=mvP5pxuVZdmOKXgDpJkoShx-28Py3XdS8jKKzsWLmrc,3554
14
+ plain/dev/precommit/cli.py,sha256=5aesbLn5YqU0Y9SUVBsw9TWdhhFtNf9wYD3-g5kW9wQ,3554
15
15
  plain/dev/requests.py,sha256=0HyCH7iZ32ne94ypMdE96z5iYb_Qbd705WItVik1SyA,6839
16
16
  plain/dev/services.py,sha256=m4XOcY8qcUVA4u8vsFZmU-wChgQvy5uiu5abOR9wZfg,2127
17
17
  plain/dev/templates/dev/requests.html,sha256=kQKJZq5L77juuL_t8UjcAehEU61U4RXNnKaAET-wAm8,7627
18
18
  plain/dev/urls.py,sha256=b4NL2I6Ok-t7nTPjRnKoz_LQRttE3_mp8l2NlmeYQ9I,146
19
19
  plain/dev/utils.py,sha256=mL3C3l3GsKmtI6eF4sRjv7w9n7Y9lLVqJulj81JrqWw,312
20
20
  plain/dev/views.py,sha256=r2Ivk7OXytpRhXq4DZpsb7FXNP9vzmEE3D5kLajYG4w,1073
21
- plain_dev-0.0.1.dist-info/LICENSE,sha256=cvKM3OlqHx3ijD6e34zsSUkPvzl-ya3Dd63A6EHL94U,1500
22
- plain_dev-0.0.1.dist-info/METADATA,sha256=qbY1kQqIOfSi-QC-VZn6ZDEIw7Tn14PoT0FCn8sZwHs,5536
23
- plain_dev-0.0.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
24
- plain_dev-0.0.1.dist-info/entry_points.txt,sha256=rBo-S4THn07f55UwHBuUhIbDhlUq3EzTOD8mIb5fGQg,99
25
- plain_dev-0.0.1.dist-info/RECORD,,
21
+ plain_dev-0.2.0.dist-info/LICENSE,sha256=cvKM3OlqHx3ijD6e34zsSUkPvzl-ya3Dd63A6EHL94U,1500
22
+ plain_dev-0.2.0.dist-info/METADATA,sha256=pmeDN3wYcbBguKpLR8PvqYFd1uTB-BQYXtiGvGTg9Us,4741
23
+ plain_dev-0.2.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
24
+ plain_dev-0.2.0.dist-info/entry_points.txt,sha256=rBo-S4THn07f55UwHBuUhIbDhlUq3EzTOD8mIb5fGQg,99
25
+ plain_dev-0.2.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.8.1
2
+ Generator: poetry-core 1.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,178 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: plain.dev
3
- Version: 0.0.1
4
- Summary: Work library for Plain
5
- Home-page: https://www.plainpackages.com/
6
- License: MIT
7
- Author: Dave Gaeddert
8
- Author-email: dave.gaeddert@dropseed.dev
9
- Requires-Python: >=3.8,<4.0
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.8
13
- Classifier: Programming Language :: Python :: 3.9
14
- Classifier: Programming Language :: Python :: 3.10
15
- Classifier: Programming Language :: Python :: 3.11
16
- Classifier: Programming Language :: Python :: 3.12
17
- Requires-Dist: click (>=8.0.0)
18
- Requires-Dist: debugpy (>=1.6.3,<2.0.0)
19
- Requires-Dist: gunicorn (>20)
20
- Requires-Dist: honcho (>=1.1.0,<2.0.0)
21
- Requires-Dist: psycopg2-binary (>=2.9.3,<3.0.0)
22
- Requires-Dist: requests (>=2.0.0)
23
- Requires-Dist: tomli (>=2.0.1,<3.0.0) ; python_version < "3.11"
24
- Project-URL: Documentation, https://www.plainpackages.com/docs/
25
- Project-URL: Repository, https://github.com/plainpackages/plain-dev
26
- Description-Content-Type: text/markdown
27
-
28
- <!-- This file is compiled from plain-dev/plain/dev/README.md. Do not edit this file directly. -->
29
-
30
- # plain-dev
31
-
32
- A single command to run everything you need for local Plain development.
33
-
34
- ![Plain work command example](https://user-images.githubusercontent.com/649496/176533533-cfd44dc5-afe5-42af-8b5d-33a9fa23f8d9.gif)
35
-
36
- The `plain dev` command runs a combination of local commands + a Docker container for your database.
37
-
38
- The following processes will run simultaneously (some will only run if they are detected as available):
39
-
40
- <!-- - [`manage.py runserver` (and migrations)](#runserver)
41
- - [`plain-models start --logs`](#plain-models)
42
- - [`plain-tailwind compile --watch`](#plain-tailwind)
43
- - [`npm run watch`](#package-json)
44
- - [`stripe listen --forward-to`](#stripe)
45
- - [`ngrok http --subdomain`](#ngrok)
46
-
47
- It also comes with [debugging](#debugging) tools to make local debugging easier with VS Code. -->
48
-
49
- ## Installation
50
-
51
- ```sh
52
- pip install plain-dev
53
- ```
54
-
55
- If you have `plain-models` installed (i.e. you're using a database),
56
- then add `DATABASE_URL` to your `.env` file.
57
-
58
- ```sh
59
- DATABASE_URL=postgres://postgres:postgres@localhost:54321/postgres
60
- ```
61
-
62
- ```toml
63
- # pyproject.toml
64
- [tool.plain.dev.services]
65
- postgres = {cmd = "docker run --name app-postgres --rm -p 54321:5432 -v $(pwd)/.plain/dev/pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=postgres postgres:15 postgres"}
66
- ```
67
-
68
- ```sh
69
- plain dev
70
- ```
71
-
72
- ## `plain dev`
73
-
74
- ### Default processes
75
-
76
- - plain preflight
77
- - gunicorn
78
- - migrations
79
- - tailwind
80
-
81
- ### Custom processes
82
-
83
- - package.json "dev" script
84
- - pyproject.toml `tool.plain.dev.run = {command = "..."}`
85
-
86
- ### GitHub Codespaces
87
-
88
- The `BASE_URL` setting is automatically set to the Codespace URL.
89
-
90
- TODO
91
-
92
- ## `plain dev db`
93
-
94
- Only supports Postgres currently.
95
-
96
- - snapshot
97
- - import
98
- - export
99
-
100
-
101
- ## Development processes
102
-
103
- ### Gunicorn
104
-
105
- The key process here is still `manage.py runserver`.
106
- But, before that runs, it will also wait for the database to be available and run `manage.py migrate`.
107
-
108
- ### plain-models
109
-
110
- If [`plain-models`](https://github.com/plainpackages/plain-models) is installed, it will automatically start and show the logs of the running database container.
111
-
112
- ### plain-tailwind
113
-
114
- If [`plain-tailwind`](https://github.com/plainpackages/plain-tailwind) is installed, it will automatically run the Tailwind `compile --watch` process.
115
-
116
- ## Debugging
117
-
118
- [View on YouTube →](https://www.youtube.com/watch?v=pG0KaJSVyBw)
119
-
120
- Since `plain work` runs multiple processes at once, the regular [pdb](https://docs.python.org/3/library/pdb.html) debuggers can be hard to use.
121
- Instead, we include [microsoft/debugpy](https://github.com/microsoft/debugpy) and an `attach` function to make it even easier to use VS Code's debugger.
122
-
123
- First, import and run the `debug.attach()` function:
124
-
125
- ```python
126
- class HomeView(TemplateView):
127
- template_name = "home.html"
128
-
129
- def get_context(self, **kwargs):
130
- context = super().get_context(**kwargs)
131
-
132
- # Make sure the debugger is attached (will need to be if runserver reloads)
133
- from plain.work import debug; debug.attach()
134
-
135
- # Add a breakpoint (or use the gutter in VSCode to add one)
136
- breakpoint()
137
-
138
- return context
139
- ```
140
-
141
- When you load the page, you'll see "Waiting for debugger to attach...".
142
-
143
- Add a new VS Code debug configuration (using localhost and port 5768) by saving this to `.vscode/launch.json` or using the GUI:
144
-
145
- ```json
146
- // .vscode/launch.json
147
- {
148
- // Use IntelliSense to learn about possible attributes.
149
- // Hover to view descriptions of existing attributes.
150
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
151
- "version": "0.2.0",
152
- "configurations": [
153
- {
154
- "name": "Plain: Attach to Django",
155
- "type": "python",
156
- "request": "attach",
157
- "connect": {
158
- "host": "localhost",
159
- "port": 5678
160
- },
161
- "pathMappings": [
162
- {
163
- "localRoot": "${workspaceFolder}",
164
- "remoteRoot": "."
165
- }
166
- ],
167
- "justMyCode": true,
168
- "django": true
169
- }
170
- ]
171
- }
172
- ```
173
-
174
- Then in the "Run and Debug" tab, you can click the green arrow next to "Plain: Attach to Django" to start the debugger.
175
-
176
- In your terminal is should tell you it was attached, and when you hit a breakpoint you'll see the debugger information in VS Code.
177
- If Django's runserver reloads, you'll be prompted to reattach by clicking the green arrow again.
178
-