|
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 | + ) |
2 | 36 |
|
3 | 37 |
|
4 | 38 | class Streamlit(ProjectSpec): |
@@ -56,6 +90,9 @@ def parse(self) -> None: |
56 | 90 |
|
57 | 91 |
|
58 | 92 | # TODO: the following are similar to streamlit, but with perhaps even less metadata |
| 93 | +# - flask (from flask import Flask; app = Flask( ) |
| 94 | +# - fastapi (from fastapi import FastAPI; app = FastAPI( ) |
59 | 95 | # - plotly/dash (from dash import Dash; app = Dash(); app.run()) |
60 | 96 | # - voila (this is just a way to display a notebook) |
61 | 97 | # - panel (import panel as pn; .servable()) |
| 98 | +# Each of these takes extra parameters for listen address and port at least. |
0 commit comments