Skip to content

Commit 82fd7bb

Browse files
committed
Bare minimum django parsing
1 parent 8d746af commit 82fd7bb

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

src/projspec/artifact/process.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class Process(BaseArtifact):
99
Can include batch jobs and long-running services.
1010
"""
1111

12-
def _make(self):
12+
def _make(self, **kwargs):
1313
if self.proc is None:
14-
self.proc = subprocess.Popen(self.cmd, **self.kw)
14+
self.proc = subprocess.Popen(self.cmd, **kwargs)
1515

1616
def _is_done(self) -> bool:
1717
return self.proc is not None and self.proc.poll() is None

src/projspec/proj/django.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/projspec/proj/webapp.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
1-
from projspec.proj import ProjectSpec
1+
from projspec.proj import ProjectSpec, ParseFailed
2+
3+
4+
class Django(ProjectSpec):
5+
"""A python web app using the django framework"""
6+
7+
def match(self):
8+
return "manage.py" in self.proj.basenames
9+
10+
def parse(self) -> None:
11+
from projspec.artifact.process import Server
12+
13+
# global settings are in ./*/settings.py in a directory also containing urls.py
14+
# the top-level; manage.py may have the line to locate it:
15+
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
16+
# and "mysite" is the suggestion in the tutorials;
17+
# can also be given as --settings to manage.py
18+
allpy = self.proj.fs.glob(f"{self.proj.url}/*/*.py")
19+
20+
# We could also choose to parse the settings or URLs - but they are required
21+
s_dirs = {_.rsplit("/", 1)[0] for _ in allpy if _.endswith("settings.py")}
22+
u_dirs = {_.rsplit("/", 1)[0] for _ in allpy if _.endswith("urls.py")}
23+
maindir = s_dirs.intersection(u_dirs)
24+
if not maindir:
25+
raise ParseFailed
26+
27+
# each site is a subdirectory with admin.py and other stuff, typically
28+
# each mapped to a different sub-URL.
29+
appdirs = [_.rsplit("/", 2)[-2] for _ in allpy if _.endswith("admin.py")]
30+
if appdirs:
31+
self.contents["apps"] = appdirs
32+
33+
self.artifacts["server"] = Server(
34+
proj=self.proj, cmd=["python", "manage.py", "runserver"]
35+
)
236

337

438
class Streamlit(ProjectSpec):
@@ -59,3 +93,4 @@ def parse(self) -> None:
5993
# - plotly/dash (from dash import Dash; app = Dash(); app.run())
6094
# - voila (this is just a way to display a notebook)
6195
# - panel (import panel as pn; .servable())
96+
# Each of these takes extra parameters for listen address and port at least.

0 commit comments

Comments
 (0)