Skip to content

Commit 772a5bf

Browse files
committed
Fork honcho in dev
1 parent 474c72d commit 772a5bf

File tree

10 files changed

+486
-31
lines changed

10 files changed

+486
-31
lines changed

plain-dev/LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## Plain is released under the BSD 3-Clause License
2+
13
BSD 3-Clause License
24

35
Copyright (c) 2023, Dropseed, LLC
@@ -26,3 +28,26 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2628
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2729
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2830
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
## This package contains code forked from github.com/nickstenning/honcho
33+
34+
Copyright (c) 2012-2024 Nick Stenning, https://whiteink.com/
35+
36+
Permission is hereby granted, free of charge, to any person obtaining
37+
a copy of this software and associated documentation files (the
38+
"Software"), to deal in the Software without restriction, including
39+
without limitation the rights to use, copy, modify, merge, publish,
40+
distribute, sublicense, and/or sell copies of the Software, and to
41+
permit persons to whom the Software is furnished to do so, subject to
42+
the following conditions:
43+
44+
The above copyright notice and this permission notice shall be
45+
included in all copies or substantial portions of the Software.
46+
47+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
52+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
53+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

plain-dev/plain/dev/cli.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
import click
1010
import tomllib
11-
from honcho.manager import Manager as HonchoManager
1211

1312
from plain.runtime import APP_PATH, settings
1413

1514
from .db import cli as db_cli
1615
from .mkcert import MkcertManager
1716
from .pid import Pid
17+
from .poncho.manager import Manager as PonchoManager
1818
from .services import Services
1919
from .utils import has_pyproject_toml, plainpackage_installed
2020

@@ -48,7 +48,7 @@ def services():
4848

4949
class Dev:
5050
def __init__(self, *, port):
51-
self.manager = HonchoManager()
51+
self.poncho = PonchoManager()
5252
self.port = port
5353
self.plain_env = {
5454
**os.environ,
@@ -76,9 +76,11 @@ def run(self):
7676
storage_path=Path(settings.PLAIN_TEMP_PATH) / "dev" / "certs",
7777
)
7878
self.modify_hosts_file()
79-
self.add_csrf_trusted_origins()
80-
self.add_allowed_hosts()
79+
self.set_csrf_trusted_origins()
80+
self.set_allowed_hosts()
8181
self.run_preflight()
82+
83+
# Processes for poncho to run simultaneously
8284
self.add_gunicorn()
8385
self.add_tailwind()
8486
self.add_pyproject_run()
@@ -91,9 +93,9 @@ def run(self):
9193
bold=True,
9294
)
9395

94-
self.manager.loop()
96+
self.poncho.loop()
9597

96-
return self.manager.returncode
98+
return self.poncho.returncode
9799
finally:
98100
pid.rm()
99101

@@ -152,7 +154,7 @@ def modify_hosts_file(self):
152154
)
153155
sys.exit(1)
154156

155-
def add_csrf_trusted_origins(self):
157+
def set_csrf_trusted_origins(self):
156158
csrf_trusted_origins = json.dumps(
157159
[
158160
f"https://{self.domain}:{self.port}",
@@ -168,7 +170,7 @@ def add_csrf_trusted_origins(self):
168170
self.plain_env["PLAIN_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
169171
self.custom_process_env["PLAIN_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
170172

171-
def add_allowed_hosts(self):
173+
def set_allowed_hosts(self):
172174
allowed_hosts = json.dumps([self.domain])
173175

174176
click.secho(
@@ -226,13 +228,13 @@ def add_gunicorn(self):
226228
# Default to two workers to prevent lockups
227229
self.plain_env["WEB_CONCURRENCY"] = "2"
228230

229-
self.manager.add_process("plain", runserver_cmd, env=self.plain_env)
231+
self.poncho.add_process("plain", runserver_cmd, env=self.plain_env)
230232

231233
def add_tailwind(self):
232234
if not plainpackage_installed("tailwind"):
233235
return
234236

235-
self.manager.add_process("tailwind", "plain tailwind compile --watch")
237+
self.poncho.add_process("tailwind", "plain tailwind compile --watch")
236238

237239
def add_pyproject_run(self):
238240
if not has_pyproject_toml(APP_PATH.parent):
@@ -249,7 +251,7 @@ def add_pyproject_run(self):
249251
**self.custom_process_env,
250252
**data.get("env", {}),
251253
}
252-
self.manager.add_process(name, data["cmd"], env=env)
254+
self.poncho.add_process(name, data["cmd"], env=env)
253255

254256
def add_services(self):
255257
services = Services.get_services(APP_PATH.parent)
@@ -259,7 +261,7 @@ def add_services(self):
259261
"PYTHONUNBUFFERED": "true",
260262
**data.get("env", {}),
261263
}
262-
self.manager.add_process(name, data["cmd"], env=env)
264+
self.poncho.add_process(name, data["cmd"], env=env)
263265

264266

265267
cli.add_command(db_cli)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
try:
2+
from ._version import __version__
3+
except ImportError:
4+
__version__ = "0.0.0+unknown"

plain-dev/plain/dev/poncho/color.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ANSI_COLOURS = ["grey", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]
2+
3+
for i, name in enumerate(ANSI_COLOURS):
4+
globals()[name] = str(30 + i)
5+
globals()["intense_" + name] = str(30 + i) + ";1"
6+
7+
8+
def get_colors():
9+
cs = [
10+
"cyan",
11+
"yellow",
12+
"green",
13+
"magenta",
14+
"red",
15+
"blue",
16+
"intense_cyan",
17+
"intense_yellow",
18+
"intense_green",
19+
"intense_magenta",
20+
"intense_red",
21+
"intense_blue",
22+
]
23+
cs = [globals()[c] for c in cs]
24+
25+
i = 0
26+
while True:
27+
yield cs[i % len(cs)]
28+
i += 1

plain-dev/plain/dev/poncho/compat.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Compatibility layer and utilities, mostly for proper Windows and Python 3
3+
support.
4+
"""
5+
import errno
6+
import os
7+
import signal
8+
import sys
9+
10+
# This works for both 32 and 64 bit Windows
11+
ON_WINDOWS = "win32" in str(sys.platform).lower()
12+
13+
if ON_WINDOWS:
14+
import ctypes
15+
16+
17+
class ProcessManager:
18+
if ON_WINDOWS:
19+
20+
def terminate(self, pid):
21+
# The first argument to OpenProcess represents the desired access
22+
# to the process. 1 represents the PROCESS_TERMINATE access right.
23+
handle = ctypes.windll.kernel32.OpenProcess(1, False, pid)
24+
ctypes.windll.kernel32.TerminateProcess(handle, -1)
25+
ctypes.windll.kernel32.CloseHandle(handle)
26+
else:
27+
28+
def terminate(self, pid):
29+
try:
30+
os.killpg(pid, signal.SIGTERM)
31+
except OSError as e:
32+
if e.errno not in [errno.EPERM, errno.ESRCH]:
33+
raise
34+
35+
if ON_WINDOWS:
36+
37+
def kill(self, pid):
38+
# There's no SIGKILL on Win32...
39+
self.terminate(pid)
40+
else:
41+
42+
def kill(self, pid):
43+
try:
44+
os.killpg(pid, signal.SIGKILL)
45+
except OSError as e:
46+
if e.errno not in [errno.EPERM, errno.ESRCH]:
47+
raise

0 commit comments

Comments
 (0)