plain.dev 0.27.1__py3-none-any.whl → 0.28.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
@@ -1,11 +1,11 @@
1
1
  import importlib
2
2
  import json
3
+ import multiprocessing
3
4
  import os
4
5
  import platform
5
6
  import signal
6
7
  import subprocess
7
8
  import sys
8
- import threading
9
9
  import time
10
10
  import tomllib
11
11
  from importlib.metadata import entry_points
@@ -223,21 +223,16 @@ class Dev:
223
223
  # If plain.models is installed (common) then we
224
224
  # will do a couple extra things before starting all of the app-related
225
225
  # processes (this way they don't all have to db-wait or anything)
226
+ process = None
226
227
  if find_spec("plain.models") is not None:
227
228
  # Use a custom signal to tell the main thread to add
228
229
  # the app processes once the db is ready
229
230
  signal.signal(signal.SIGUSR1, self.start_app)
230
231
 
231
- def _thread(env):
232
- subprocess.run(["plain", "models", "db-wait"], env=env, check=True)
233
- subprocess.run(["plain", "migrate", "--backup"], env=env, check=True)
234
- # preflight with db?
235
- os.kill(os.getpid(), signal.SIGUSR1)
236
-
237
- thread = threading.Thread(
238
- target=_thread, daemon=True, args=(self.plain_env,)
232
+ process = multiprocessing.Process(
233
+ target=_process_task, args=(self.plain_env,)
239
234
  )
240
- thread.start()
235
+ process.start()
241
236
  else:
242
237
  # Start the app processes immediately
243
238
  self.start_app(None, None)
@@ -253,6 +248,14 @@ class Dev:
253
248
  if services_pid:
254
249
  services_pid.rm()
255
250
 
251
+ # Make sure the process is terminated if it is still running
252
+ if process and process.is_alive():
253
+ os.killpg(os.getpgid(process.pid), signal.SIGTERM)
254
+ process.join(timeout=3)
255
+ if process.is_alive():
256
+ os.killpg(os.getpgid(process.pid), signal.SIGKILL)
257
+ process.join()
258
+
256
259
  return self.poncho.returncode
257
260
 
258
261
  def start_app(self, signum, frame):
@@ -349,24 +352,26 @@ class Dev:
349
352
  sys.exit(1)
350
353
 
351
354
  def set_csrf_and_allowed_hosts(self):
352
- csrf_trusted_origins = json.dumps(
353
- [
354
- self.url,
355
- ]
356
- )
357
- allowed_hosts = json.dumps([self.hostname])
358
-
359
- # Set environment variables
360
- self.plain_env["PLAIN_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
361
- self.custom_process_env["PLAIN_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
362
-
363
- self.plain_env["PLAIN_ALLOWED_HOSTS"] = allowed_hosts
364
- self.custom_process_env["PLAIN_ALLOWED_HOSTS"] = allowed_hosts
355
+ if "PLAIN_CSRF_TRUSTED_ORIGINS" not in os.environ:
356
+ csrf_trusted_origins = json.dumps(
357
+ [
358
+ self.url,
359
+ ]
360
+ )
361
+ self.plain_env["PLAIN_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
362
+ self.custom_process_env["PLAIN_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
363
+ click.secho(
364
+ f"Automatically set PLAIN_CSRF_TRUSTED_ORIGINS={csrf_trusted_origins}",
365
+ dim=True,
366
+ )
365
367
 
366
- click.secho(
367
- f"Automatically set PLAIN_ALLOWED_HOSTS={allowed_hosts} PLAIN_CSRF_TRUSTED_ORIGINS={csrf_trusted_origins}",
368
- dim=True,
369
- )
368
+ if "PLAIN_ALLOWED_HOSTS" not in os.environ:
369
+ allowed_hosts = json.dumps([self.hostname])
370
+ self.plain_env["PLAIN_ALLOWED_HOSTS"] = allowed_hosts
371
+ self.custom_process_env["PLAIN_ALLOWED_HOSTS"] = allowed_hosts
372
+ click.secho(
373
+ f"Automatically set PLAIN_ALLOWED_HOSTS={allowed_hosts}", dim=True
374
+ )
370
375
 
371
376
  def run_preflight(self):
372
377
  click.echo()
@@ -439,3 +444,16 @@ class Dev:
439
444
  **data.get("env", {}),
440
445
  }
441
446
  self.poncho.add_process(name, data["cmd"], env=env)
447
+
448
+
449
+ def _process_task(env):
450
+ # Make this process the leader of a new group which can be killed together if it doesn't finish
451
+ os.setsid()
452
+
453
+ subprocess.run(["plain", "models", "db-wait"], env=env, check=True)
454
+ subprocess.run(["plain", "migrate", "--backup"], env=env, check=True)
455
+
456
+ # preflight with db?
457
+
458
+ # Send SIGUSR1 to the parent process so the parent's handler is invoked
459
+ os.kill(os.getppid(), signal.SIGUSR1)
@@ -8,7 +8,7 @@ from plain.cli import register_cli
8
8
 
9
9
 
10
10
  @register_cli("contrib")
11
- @click.command("contribute")
11
+ @click.command("contribute", hidden=True)
12
12
  @click.option("--repo", default="../plain", help="Path to the plain repo")
13
13
  @click.option(
14
14
  "--reset", is_flag=True, help="Undo any changes to pyproject.toml and uv.lock"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plain.dev
3
- Version: 0.27.1
3
+ Version: 0.28.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,6 +1,6 @@
1
1
  plain/dev/README.md,sha256=EQJ9lF-JQ9KQWJZ_j6CD3jbRquOLgDRlIPbgT7A2gG4,3658
2
2
  plain/dev/__init__.py,sha256=nRX1B0Br8gmqhJLqo5Z9PqzReDahBtbmwH6C-7hzuls,103
3
- plain/dev/cli.py,sha256=z6xDeU1hcu3dTI55H7MllKZBQz4fnAO_Y-VoIKPLO7M,14843
3
+ plain/dev/cli.py,sha256=lyiIJveVedrO1MDwTlV-C-UYzMHR48q7MWEUODEQMUc,15605
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
@@ -14,7 +14,7 @@ plain/dev/utils.py,sha256=4wMzpvj1Is_c0QxhsTu34_P9wAYlzw4glNPfVtZr_0A,123
14
14
  plain/dev/views.py,sha256=r2Ivk7OXytpRhXq4DZpsb7FXNP9vzmEE3D5kLajYG4w,1073
15
15
  plain/dev/contribute/README.md,sha256=v9Ympugu2wvDEe_045WJnF1dmC4ZH7v_Bnxkpfaf_rM,329
16
16
  plain/dev/contribute/__init__.py,sha256=9ByBOIdM8DebChjNz-RH2atdz4vWe8somlwNEsbhwh4,40
17
- plain/dev/contribute/cli.py,sha256=jSfocR754VGMzcnb62zJA2lxxjry1Bdzupbsm3McgdY,3084
17
+ plain/dev/contribute/cli.py,sha256=YirzF4YCQoFhWS-JgQHNxqJIX9BY_m9lb3_ZdrI7sn4,3097
18
18
  plain/dev/poncho/__init__.py,sha256=MDOk2rhhoR3V-I-rg6tMHFeX60vTGJuQ14RI-_N6tQY,97
19
19
  plain/dev/poncho/color.py,sha256=Dk77inPR9qNc9vCaZOGk8W9skXfRgoUlxp_E6mhPNns,610
20
20
  plain/dev/poncho/compat.py,sha256=l66WZLR7kRpO8P8DI5-aUsbNlohPaXEurQ5xXESQYDs,1276
@@ -24,8 +24,8 @@ plain/dev/poncho/process.py,sha256=JJOKy-C6vMCg7-6JMCtu6C649h7HmOBSJqDP_hnX49I,2
24
24
  plain/dev/precommit/__init__.py,sha256=9ByBOIdM8DebChjNz-RH2atdz4vWe8somlwNEsbhwh4,40
25
25
  plain/dev/precommit/cli.py,sha256=KVHcG3Y_JZJNu3_MLIrO5s6yMYQfAArIU5L0hNWZUjg,3441
26
26
  plain/dev/templates/dev/requests.html,sha256=kQKJZq5L77juuL_t8UjcAehEU61U4RXNnKaAET-wAm8,7627
27
- plain_dev-0.27.1.dist-info/METADATA,sha256=CgZpO23_EYRFL2OX0AC8glbya4WORC1kPaduysWuq-c,4163
28
- plain_dev-0.27.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
- plain_dev-0.27.1.dist-info/entry_points.txt,sha256=zrcTOiFk_MLKsnYVlwVP7aMm1XLEqq7w4EBkJ-3ge-g,114
30
- plain_dev-0.27.1.dist-info/licenses/LICENSE,sha256=Cx4Dq9yR2fLHthf8Ke36B8QJvE1bZFXVzDIGE8wGzsY,4132
31
- plain_dev-0.27.1.dist-info/RECORD,,
27
+ plain_dev-0.28.0.dist-info/METADATA,sha256=e9YKAUJem8n9tLYT0kCmFD5aEKPE5fBX5dmwu-RUWyk,4163
28
+ plain_dev-0.28.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
+ plain_dev-0.28.0.dist-info/entry_points.txt,sha256=zrcTOiFk_MLKsnYVlwVP7aMm1XLEqq7w4EBkJ-3ge-g,114
30
+ plain_dev-0.28.0.dist-info/licenses/LICENSE,sha256=Cx4Dq9yR2fLHthf8Ke36B8QJvE1bZFXVzDIGE8wGzsY,4132
31
+ plain_dev-0.28.0.dist-info/RECORD,,