plain.dev 0.24.0__py3-none-any.whl → 0.25.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/cli.py CHANGED
@@ -19,7 +19,6 @@ from plain.cli import register_cli
19
19
  from plain.runtime import APP_PATH, settings
20
20
 
21
21
  from .mkcert import MkcertManager
22
- from .pid import Pid
23
22
  from .poncho.manager import Manager as PonchoManager
24
23
  from .poncho.printer import Printer
25
24
  from .services import Services
@@ -104,7 +103,11 @@ def debug():
104
103
  @cli.command()
105
104
  def services():
106
105
  """Start additional services defined in pyproject.toml"""
107
- Services().run()
106
+ _services = Services()
107
+ if _services.are_running():
108
+ click.secho("Services already running", fg="yellow")
109
+ return
110
+ _services.run()
108
111
 
109
112
 
110
113
  @cli.command()
@@ -154,65 +157,59 @@ class Dev:
154
157
  self.poncho = PonchoManager(printer=Printer(lambda s: self.console.out(s)))
155
158
 
156
159
  def run(self):
157
- pid = Pid()
158
- pid.write()
159
-
160
- try:
161
- mkcert_manager = MkcertManager()
162
- mkcert_manager.setup_mkcert(install_path=Path.home() / ".plain" / "dev")
163
- self.ssl_cert_path, self.ssl_key_path = mkcert_manager.generate_certs(
164
- domain=self.hostname,
165
- storage_path=Path(settings.PLAIN_TEMP_PATH) / "dev" / "certs",
166
- )
160
+ mkcert_manager = MkcertManager()
161
+ mkcert_manager.setup_mkcert(install_path=Path.home() / ".plain" / "dev")
162
+ self.ssl_cert_path, self.ssl_key_path = mkcert_manager.generate_certs(
163
+ domain=self.hostname,
164
+ storage_path=Path(settings.PLAIN_TEMP_PATH) / "dev" / "certs",
165
+ )
167
166
 
168
- self.symlink_plain_src()
169
- self.modify_hosts_file()
170
- self.set_csrf_and_allowed_hosts()
171
- self.run_preflight()
172
-
173
- # Processes for poncho to run simultaneously
174
- self.add_gunicorn()
175
- self.add_entrypoints()
176
- self.add_pyproject_run()
177
- self.add_services()
178
-
179
- click.secho("\nStarting dev...", italic=True, dim=True)
180
-
181
- if self.tunnel_url:
182
- status_bar = Columns(
183
- [
184
- Text.from_markup(
185
- f"[bold]Tunnel[/bold] [underline][link={self.tunnel_url}]{self.tunnel_url}[/link][/underline]"
186
- ),
187
- Text.from_markup(
188
- f"[dim][bold]Server[/bold] [link={self.url}]{self.url}[/link][/dim]"
189
- ),
190
- Text.from_markup(
191
- "[dim][bold]Ctrl+C[/bold] to stop[/dim]",
192
- justify="right",
193
- ),
194
- ],
195
- expand=True,
196
- )
197
- else:
198
- status_bar = Columns(
199
- [
200
- Text.from_markup(
201
- f"[bold]Server[/bold] [underline][link={self.url}]{self.url}[/link][/underline]"
202
- ),
203
- Text.from_markup(
204
- "[dim][bold]Ctrl+C[/bold] to stop[/dim]", justify="right"
205
- ),
206
- ],
207
- expand=True,
208
- )
167
+ self.symlink_plain_src()
168
+ self.modify_hosts_file()
169
+ self.set_csrf_and_allowed_hosts()
170
+ self.run_preflight()
171
+
172
+ # Processes for poncho to run simultaneously
173
+ self.add_gunicorn()
174
+ self.add_entrypoints()
175
+ self.add_pyproject_run()
176
+ self.add_services()
177
+
178
+ click.secho("\nStarting dev...", italic=True, dim=True)
179
+
180
+ if self.tunnel_url:
181
+ status_bar = Columns(
182
+ [
183
+ Text.from_markup(
184
+ f"[bold]Tunnel[/bold] [underline][link={self.tunnel_url}]{self.tunnel_url}[/link][/underline]"
185
+ ),
186
+ Text.from_markup(
187
+ f"[dim][bold]Server[/bold] [link={self.url}]{self.url}[/link][/dim]"
188
+ ),
189
+ Text.from_markup(
190
+ "[dim][bold]Ctrl+C[/bold] to stop[/dim]",
191
+ justify="right",
192
+ ),
193
+ ],
194
+ expand=True,
195
+ )
196
+ else:
197
+ status_bar = Columns(
198
+ [
199
+ Text.from_markup(
200
+ f"[bold]Server[/bold] [underline][link={self.url}]{self.url}[/link][/underline]"
201
+ ),
202
+ Text.from_markup(
203
+ "[dim][bold]Ctrl+C[/bold] to stop[/dim]", justify="right"
204
+ ),
205
+ ],
206
+ expand=True,
207
+ )
209
208
 
210
- with self.console.status(status_bar):
211
- self.poncho.loop()
209
+ with self.console.status(status_bar):
210
+ self.poncho.loop()
212
211
 
213
- return self.poncho.returncode
214
- finally:
215
- pid.rm()
212
+ return self.poncho.returncode
216
213
 
217
214
  def symlink_plain_src(self):
218
215
  """Symlink the plain package into .plain so we can look at it easily"""
@@ -388,6 +385,12 @@ class Dev:
388
385
 
389
386
  def add_services(self):
390
387
  """Services are things that also run during tests (like a database), and are critical for the app to function."""
388
+
389
+ if Services.are_running():
390
+ click.secho("Services already running", fg="yellow")
391
+ return
392
+
393
+ # Split each service into a separate process
391
394
  services = Services.get_services(APP_PATH.parent)
392
395
  for name, data in services.items():
393
396
  env = {
plain/dev/services.py CHANGED
@@ -7,13 +7,29 @@ from pathlib import Path
7
7
 
8
8
  import click
9
9
 
10
- from plain.runtime import APP_PATH
10
+ from plain.runtime import APP_PATH, settings
11
11
 
12
- from .pid import Pid
13
12
  from .poncho.manager import Manager as PonchoManager
14
13
  from .utils import has_pyproject_toml
15
14
 
16
15
 
16
+ class ServicesPid:
17
+ def __init__(self):
18
+ self.pidfile = settings.PLAIN_TEMP_PATH / "dev" / "services.pid"
19
+
20
+ def write(self):
21
+ pid = os.getpid()
22
+ self.pidfile.parent.mkdir(parents=True, exist_ok=True)
23
+ with self.pidfile.open("w+") as f:
24
+ f.write(str(pid))
25
+
26
+ def rm(self):
27
+ self.pidfile.unlink()
28
+
29
+ def exists(self):
30
+ return self.pidfile.exists()
31
+
32
+
17
33
  class Services:
18
34
  @staticmethod
19
35
  def get_services(root):
@@ -33,25 +49,39 @@ class Services:
33
49
  def __init__(self):
34
50
  self.poncho = PonchoManager()
35
51
 
36
- def run(self):
37
- services = self.get_services(APP_PATH.parent)
38
- for name, data in services.items():
39
- env = {
40
- **os.environ,
41
- "PYTHONUNBUFFERED": "true",
42
- **data.get("env", {}),
43
- }
44
- self.poncho.add_process(name, data["cmd"], env=env)
52
+ @staticmethod
53
+ def are_running():
54
+ pid = ServicesPid()
55
+ return pid.exists()
45
56
 
46
- self.poncho.loop()
57
+ def run(self):
58
+ # Each user of Services will have to check if it is running by:
59
+ # - using the context manager (with Services())
60
+ # - calling are_running() directly
61
+ pid = ServicesPid()
62
+ pid.write()
63
+
64
+ try:
65
+ services = self.get_services(APP_PATH.parent)
66
+ for name, data in services.items():
67
+ env = {
68
+ **os.environ,
69
+ "PYTHONUNBUFFERED": "true",
70
+ **data.get("env", {}),
71
+ }
72
+ self.poncho.add_process(name, data["cmd"], env=env)
73
+
74
+ self.poncho.loop()
75
+ finally:
76
+ pid.rm()
47
77
 
48
78
  def __enter__(self):
49
79
  if not self.get_services(APP_PATH.parent):
50
80
  # No-op if no services are defined
51
81
  return
52
82
 
53
- if Pid().exists():
54
- click.secho("Services already running in `plain dev` command", fg="yellow")
83
+ if self.are_running():
84
+ click.secho("Services already running", fg="yellow")
55
85
  return
56
86
 
57
87
  print("Starting `plain dev services`")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plain.dev
3
- Version: 0.24.0
3
+ Version: 0.25.0
4
4
  Summary: Local development tools for Plain.
5
5
  Author-email: Dave Gaeddert <dave.gaeddert@dropseed.dev>
6
6
  License-Expression: BSD-3-Clause
@@ -1,15 +1,14 @@
1
1
  plain/dev/README.md,sha256=r_sONnN4zVlDdQrst_51iScrm3PlrcoPNmX9yX3MKXo,3658
2
2
  plain/dev/__init__.py,sha256=nRX1B0Br8gmqhJLqo5Z9PqzReDahBtbmwH6C-7hzuls,103
3
- plain/dev/cli.py,sha256=YWKBOuf-ryu5QXDtU2AZu1TH7ZzYCX3yJmKgr61Ec-M,13131
3
+ plain/dev/cli.py,sha256=e1yBvB5PyQxTk4O9BP_73aJckL05jBAFVq2Kli6Jd-s,13138
4
4
  plain/dev/debug.py,sha256=Ka84K8zUdF0kMYNyqiLYDrdzU1jU8LSOkts3hcw_Gok,1005
5
5
  plain/dev/default_settings.py,sha256=uXWYORWP_aRDwXIFXdu5kHyiBFUZzARIJdhPeFaX35c,75
6
6
  plain/dev/entrypoints.py,sha256=diqNwA6eydUMtoO7p_rH-DtSYsw5-GBmjFe1Z5bHagc,579
7
7
  plain/dev/gunicorn_logging.json,sha256=yU23jzs5G4YGdDWBNiyAc3KypR4HirR6afIkD7w6DhU,1113
8
8
  plain/dev/mkcert.py,sha256=fm1U_UTGPREso6ZaP79WqEvd9uvA4lYWFo6fKhNglMM,3911
9
9
  plain/dev/pdb.py,sha256=4ru3rlIIyuYVXteyI7v42i4MmdBIjpJP0IJemBpf83A,3742
10
- plain/dev/pid.py,sha256=gRMBf7aGndrra1TnmKtPghTijnd0i0Xeo63mzfPWp7M,436
11
10
  plain/dev/requests.py,sha256=D1NX0qC8ADtf_zwsGMTp9aiE6Sh9QmoxFJCU_V8Wers,6839
12
- plain/dev/services.py,sha256=26WnVNjNAh37BA-wHQSGQY_9Ofw8oGgJdHhxnFaSKkg,2059
11
+ plain/dev/services.py,sha256=bfIXEVsot20cDbyIeRJ9xAiTTVxowHrLAiZM2aOMXDU,2845
13
12
  plain/dev/urls.py,sha256=6fyl-DvxDgKjUjpyhuLN8m6GisB8L-eH4rhYH_eRmGA,188
14
13
  plain/dev/utils.py,sha256=4wMzpvj1Is_c0QxhsTu34_P9wAYlzw4glNPfVtZr_0A,123
15
14
  plain/dev/views.py,sha256=r2Ivk7OXytpRhXq4DZpsb7FXNP9vzmEE3D5kLajYG4w,1073
@@ -25,8 +24,8 @@ plain/dev/poncho/process.py,sha256=JJOKy-C6vMCg7-6JMCtu6C649h7HmOBSJqDP_hnX49I,2
25
24
  plain/dev/precommit/__init__.py,sha256=9ByBOIdM8DebChjNz-RH2atdz4vWe8somlwNEsbhwh4,40
26
25
  plain/dev/precommit/cli.py,sha256=KVHcG3Y_JZJNu3_MLIrO5s6yMYQfAArIU5L0hNWZUjg,3441
27
26
  plain/dev/templates/dev/requests.html,sha256=kQKJZq5L77juuL_t8UjcAehEU61U4RXNnKaAET-wAm8,7627
28
- plain_dev-0.24.0.dist-info/METADATA,sha256=8JYKVWAVB9KWsXvCG7v0sIxY9hBFGjMd1kIA8NSmYko,4163
29
- plain_dev-0.24.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
30
- plain_dev-0.24.0.dist-info/entry_points.txt,sha256=zrcTOiFk_MLKsnYVlwVP7aMm1XLEqq7w4EBkJ-3ge-g,114
31
- plain_dev-0.24.0.dist-info/licenses/LICENSE,sha256=Cx4Dq9yR2fLHthf8Ke36B8QJvE1bZFXVzDIGE8wGzsY,4132
32
- plain_dev-0.24.0.dist-info/RECORD,,
27
+ plain_dev-0.25.0.dist-info/METADATA,sha256=oOof38mcG0119ENTH8LH0hFpECPCmE_apn9-pZ4J_I0,4163
28
+ plain_dev-0.25.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
+ plain_dev-0.25.0.dist-info/entry_points.txt,sha256=zrcTOiFk_MLKsnYVlwVP7aMm1XLEqq7w4EBkJ-3ge-g,114
30
+ plain_dev-0.25.0.dist-info/licenses/LICENSE,sha256=Cx4Dq9yR2fLHthf8Ke36B8QJvE1bZFXVzDIGE8wGzsY,4132
31
+ plain_dev-0.25.0.dist-info/RECORD,,
plain/dev/pid.py DELETED
@@ -1,20 +0,0 @@
1
- import os
2
-
3
- from plain.runtime import settings
4
-
5
-
6
- class Pid:
7
- def __init__(self):
8
- self.pidfile = settings.PLAIN_TEMP_PATH / "dev.pid"
9
-
10
- def write(self):
11
- pid = os.getpid()
12
- self.pidfile.parent.mkdir(parents=True, exist_ok=True)
13
- with self.pidfile.open("w+") as f:
14
- f.write(str(pid))
15
-
16
- def rm(self):
17
- self.pidfile.unlink()
18
-
19
- def exists(self):
20
- return self.pidfile.exists()