plain.dev 0.11.0__py3-none-any.whl → 0.13.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 +48 -20
- {plain_dev-0.11.0.dist-info → plain_dev-0.13.0.dist-info}/METADATA +1 -1
- {plain_dev-0.11.0.dist-info → plain_dev-0.13.0.dist-info}/RECORD +6 -6
- {plain_dev-0.11.0.dist-info → plain_dev-0.13.0.dist-info}/LICENSE +0 -0
- {plain_dev-0.11.0.dist-info → plain_dev-0.13.0.dist-info}/WHEEL +0 -0
- {plain_dev-0.11.0.dist-info → plain_dev-0.13.0.dist-info}/entry_points.txt +0 -0
plain/dev/cli.py
CHANGED
@@ -30,15 +30,32 @@ ENTRYPOINT_GROUP = "plain.dev"
|
|
30
30
|
default=8443,
|
31
31
|
type=int,
|
32
32
|
help="Port to run the web server on",
|
33
|
-
envvar="PORT",
|
34
33
|
)
|
35
|
-
|
34
|
+
@click.option(
|
35
|
+
"--hostname",
|
36
|
+
"-h",
|
37
|
+
default=None,
|
38
|
+
type=str,
|
39
|
+
help="Hostname to run the web server on",
|
40
|
+
)
|
41
|
+
@click.option(
|
42
|
+
"--log-level",
|
43
|
+
"-l",
|
44
|
+
default="info",
|
45
|
+
type=click.Choice(["debug", "info", "warning", "error", "critical"]),
|
46
|
+
help="Log level",
|
47
|
+
)
|
48
|
+
def cli(ctx, port, hostname, log_level):
|
36
49
|
"""Start local development"""
|
37
50
|
|
38
51
|
if ctx.invoked_subcommand:
|
39
52
|
return
|
40
53
|
|
41
|
-
|
54
|
+
if not hostname:
|
55
|
+
project_name = os.path.basename(os.getcwd())
|
56
|
+
hostname = f"{project_name}.localhost"
|
57
|
+
|
58
|
+
returncode = Dev(port=port, hostname=hostname, log_level=log_level).run()
|
42
59
|
if returncode:
|
43
60
|
sys.exit(returncode)
|
44
61
|
|
@@ -68,21 +85,29 @@ def entrypoint(show_list, entrypoint):
|
|
68
85
|
|
69
86
|
|
70
87
|
class Dev:
|
71
|
-
def __init__(self, *, port):
|
72
|
-
self.poncho = PonchoManager()
|
88
|
+
def __init__(self, *, port, hostname, log_level):
|
73
89
|
self.port = port
|
90
|
+
self.hostname = hostname
|
91
|
+
self.log_level = log_level
|
92
|
+
|
93
|
+
self.poncho = PonchoManager()
|
94
|
+
|
95
|
+
self.ssl_key_path = None
|
96
|
+
self.ssl_cert_path = None
|
97
|
+
|
98
|
+
self.url = f"https://{self.hostname}:{self.port}"
|
99
|
+
|
74
100
|
self.plain_env = {
|
75
|
-
**os.environ,
|
76
101
|
"PYTHONUNBUFFERED": "true",
|
102
|
+
"PLAIN_LOG_LEVEL": self.log_level.upper(),
|
103
|
+
"APP_LOG_LEVEL": self.log_level.upper(),
|
104
|
+
**os.environ,
|
77
105
|
}
|
78
106
|
self.custom_process_env = {
|
79
107
|
**self.plain_env,
|
80
108
|
"PORT": str(self.port),
|
109
|
+
"PLAIN_DEV_URL": self.url,
|
81
110
|
}
|
82
|
-
self.project_name = os.path.basename(os.getcwd())
|
83
|
-
self.domain = f"{self.project_name}.localhost"
|
84
|
-
self.ssl_cert_path = None
|
85
|
-
self.ssl_key_path = None
|
86
111
|
|
87
112
|
def run(self):
|
88
113
|
pid = Pid()
|
@@ -92,7 +117,7 @@ class Dev:
|
|
92
117
|
mkcert_manager = MkcertManager()
|
93
118
|
mkcert_manager.setup_mkcert(install_path=Path.home() / ".plain" / "dev")
|
94
119
|
self.ssl_cert_path, self.ssl_key_path = mkcert_manager.generate_certs(
|
95
|
-
domain=self.
|
120
|
+
domain=self.hostname,
|
96
121
|
storage_path=Path(settings.PLAIN_TEMP_PATH) / "dev" / "certs",
|
97
122
|
)
|
98
123
|
self.modify_hosts_file()
|
@@ -106,9 +131,8 @@ class Dev:
|
|
106
131
|
self.add_services()
|
107
132
|
|
108
133
|
# Output the clickable link before starting the manager loop
|
109
|
-
url = f"https://{self.domain}:{self.port}/"
|
110
134
|
click.secho(
|
111
|
-
f"\nYour app will run at: {click.style(url, fg='green', underline=True)}\n",
|
135
|
+
f"\nYour app will run at: {click.style(self.url, fg='green', underline=True)}\n",
|
112
136
|
bold=True,
|
113
137
|
)
|
114
138
|
|
@@ -123,7 +147,7 @@ class Dev:
|
|
123
147
|
def modify_hosts_file(self):
|
124
148
|
"""Modify the hosts file to map the custom domain to 127.0.0.1."""
|
125
149
|
entry_identifier = "# Added by plain"
|
126
|
-
hosts_entry = f"127.0.0.1 {self.
|
150
|
+
hosts_entry = f"127.0.0.1 {self.hostname} {entry_identifier}"
|
127
151
|
|
128
152
|
if platform.system() == "Windows":
|
129
153
|
hosts_path = Path(r"C:\Windows\System32\drivers\etc\hosts")
|
@@ -137,7 +161,7 @@ class Dev:
|
|
137
161
|
# Entry does not exist; add it
|
138
162
|
with hosts_path.open("a") as f:
|
139
163
|
f.write(f"{hosts_entry}\n")
|
140
|
-
click.secho(f"Added {self.
|
164
|
+
click.secho(f"Added {self.hostname} to {hosts_path}", bold=True)
|
141
165
|
except PermissionError:
|
142
166
|
click.secho(
|
143
167
|
"Permission denied while modifying hosts file. Please run the script as an administrator.",
|
@@ -156,12 +180,12 @@ class Dev:
|
|
156
180
|
|
157
181
|
# Entry does not exist; append it using sudo
|
158
182
|
click.secho(
|
159
|
-
"
|
183
|
+
f"Adding {self.hostname} to /etc/hosts file. You may be prompted for your password.\n",
|
160
184
|
bold=True,
|
161
185
|
)
|
162
186
|
cmd = f"echo '{hosts_entry}' | sudo tee -a {hosts_path} >/dev/null"
|
163
187
|
subprocess.run(cmd, shell=True, check=True)
|
164
|
-
click.secho(f"Added {self.
|
188
|
+
click.secho(f"Added {self.hostname} to {hosts_path}\n", bold=True)
|
165
189
|
except PermissionError:
|
166
190
|
click.secho(
|
167
191
|
"Permission denied while accessing hosts file.",
|
@@ -178,10 +202,10 @@ class Dev:
|
|
178
202
|
def set_csrf_and_allowed_hosts(self):
|
179
203
|
csrf_trusted_origins = json.dumps(
|
180
204
|
[
|
181
|
-
|
205
|
+
self.url,
|
182
206
|
]
|
183
207
|
)
|
184
|
-
allowed_hosts = json.dumps([self.
|
208
|
+
allowed_hosts = json.dumps([self.hostname])
|
185
209
|
|
186
210
|
# Set environment variables
|
187
211
|
self.plain_env["PLAIN_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
|
@@ -214,7 +238,7 @@ class Dev:
|
|
214
238
|
gunicorn_cmd = [
|
215
239
|
"gunicorn",
|
216
240
|
"--bind",
|
217
|
-
f"{self.
|
241
|
+
f"{self.hostname}:{self.port}",
|
218
242
|
"--certfile",
|
219
243
|
str(self.ssl_cert_path),
|
220
244
|
"--keyfile",
|
@@ -223,6 +247,8 @@ class Dev:
|
|
223
247
|
"plain.wsgi:app",
|
224
248
|
"--timeout",
|
225
249
|
"60",
|
250
|
+
"--log-level",
|
251
|
+
self.log_level,
|
226
252
|
"--access-logfile",
|
227
253
|
"-",
|
228
254
|
"--error-logfile",
|
@@ -255,6 +281,7 @@ class Dev:
|
|
255
281
|
)
|
256
282
|
|
257
283
|
def add_pyproject_run(self):
|
284
|
+
"""Additional processes that only run during `plain dev`."""
|
258
285
|
if not has_pyproject_toml(APP_PATH.parent):
|
259
286
|
return
|
260
287
|
|
@@ -272,6 +299,7 @@ class Dev:
|
|
272
299
|
self.poncho.add_process(name, data["cmd"], env=env)
|
273
300
|
|
274
301
|
def add_services(self):
|
302
|
+
"""Services are things that also run during tests (like a database), and are critical for the app to function."""
|
275
303
|
services = Services.get_services(APP_PATH.parent)
|
276
304
|
for name, data in services.items():
|
277
305
|
env = {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
plain/dev/README.md,sha256=BQDaRKfsafIPzx7vtVt-zS-a8l6sxbQThhQTvu7tp3Y,3699
|
2
2
|
plain/dev/__init__.py,sha256=C1JrkNE5XX2DLgBXXLAV_UyhofwVd0ZPL59fPUMbOKo,139
|
3
|
-
plain/dev/cli.py,sha256=
|
3
|
+
plain/dev/cli.py,sha256=IzO14253uPogLV2emmZHKhBQgc7mCtr8VmfhR_g2O7g,10082
|
4
4
|
plain/dev/config.py,sha256=h6o5YZtJhg-cFIWoqIDWuMCC5T09cxEsBaa3BP4Nii0,632
|
5
5
|
plain/dev/contribute/__init__.py,sha256=9ByBOIdM8DebChjNz-RH2atdz4vWe8somlwNEsbhwh4,40
|
6
6
|
plain/dev/contribute/cli.py,sha256=qZ7YmE_upbw-Y5NRpvaHnJTPp9kvn21fPQ7G0n1LAkg,2277
|
@@ -27,8 +27,8 @@ plain/dev/templates/dev/requests.html,sha256=kQKJZq5L77juuL_t8UjcAehEU61U4RXNnKa
|
|
27
27
|
plain/dev/urls.py,sha256=b4NL2I6Ok-t7nTPjRnKoz_LQRttE3_mp8l2NlmeYQ9I,146
|
28
28
|
plain/dev/utils.py,sha256=4wMzpvj1Is_c0QxhsTu34_P9wAYlzw4glNPfVtZr_0A,123
|
29
29
|
plain/dev/views.py,sha256=r2Ivk7OXytpRhXq4DZpsb7FXNP9vzmEE3D5kLajYG4w,1073
|
30
|
-
plain_dev-0.
|
31
|
-
plain_dev-0.
|
32
|
-
plain_dev-0.
|
33
|
-
plain_dev-0.
|
34
|
-
plain_dev-0.
|
30
|
+
plain_dev-0.13.0.dist-info/LICENSE,sha256=YDg-l_Rj7LVP5uDXy04eQPGb_DYVXAHAHYd9r3pU1Cg,2713
|
31
|
+
plain_dev-0.13.0.dist-info/METADATA,sha256=6EtnSY-Be2p9DZNOB5nactlYNSpUl5z09ACD42ywjyM,4722
|
32
|
+
plain_dev-0.13.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
33
|
+
plain_dev-0.13.0.dist-info/entry_points.txt,sha256=1FaE_73k95WYOJrmB0hcHBnEIFQa-Cfl56Z1LGxyvak,164
|
34
|
+
plain_dev-0.13.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|