Skip to content

Commit 93058e7

Browse files
committed
Moved api.py to top level
It does build and serve locally from uv
1 parent 798c2d8 commit 93058e7

File tree

7 files changed

+62
-29
lines changed

7 files changed

+62
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**/.venv
22
*.py[cod]
33
**/__*/**
4+
api/

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
serve_falcon:
3+
./api.py \
4+
--path_static static/ \
5+
--path_language language_reference/languages/ \
6+
--path_project ~/code/personal/TeachProgramming/teachprogramming/static/projects/
7+
8+
build:
9+
./api.py \
10+
--path_static static/ \
11+
--path_language language_reference/languages/ \
12+
--path_project ~/code/personal/TeachProgramming/teachprogramming/static/projects/ \
13+
--export .
14+
15+
serve:
16+
python3 -m http.server

make_ver/api.py renamed to api.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
#!/usr/bin/env -S uv run --script
2+
# /// script
3+
# requires-python = "~=3.14"
4+
# dependencies = [
5+
# "falcon",
6+
# ]
7+
# ///
8+
19
import logging
210
from pathlib import Path
311
from typing import Iterable
@@ -6,9 +14,9 @@
614

715
import _falcon_helpers
816

9-
from .make_ver import LANGUAGES
10-
from .language_versions import LanguageVersions
11-
from .project_versions import ProjectVersions
17+
from make_ver.make_ver import LANGUAGES
18+
from make_ver.language_versions import LanguageVersions
19+
from make_ver.project_versions import ProjectVersions
1220

1321
log = logging.getLogger(__name__)
1422

@@ -89,13 +97,13 @@ def _filter_file(f):
8997

9098
# Setup App -------------------------------------------------------------------
9199

92-
def create_wsgi_app(project_path=None, language_path=None, **kwargs):
100+
def create_wsgi_app(path_project: Path, path_language: Path, path_static: Path, **kwargs):
93101
app = falcon.App()
94102
app.add_route(r'/', IndexResource())
95-
app.add_static_route(r'/static', str(Path('static').resolve()))
96-
app.add_route(r'/api/v1/language_reference.json', LanguageReferenceResource(language_path))
97-
app.add_route(r'/api/v1/projects.json', ProjectListResource(project_path))
98-
_falcon_helpers.add_sink(app, r'/api/v1/projects/', ProjectResource(project_path), func_path_normalizer=_falcon_helpers.func_path_normalizer_no_extension)
103+
app.add_static_route(r'/static', str(path_static.resolve()))
104+
app.add_route(r'/api/v1/language_reference.json', LanguageReferenceResource(path_language))
105+
app.add_route(r'/api/v1/projects.json', ProjectListResource(path_project))
106+
_falcon_helpers.add_sink(app, r'/api/v1/projects/', ProjectResource(path_project), func_path_normalizer=_falcon_helpers.func_path_normalizer_no_extension)
99107
_falcon_helpers.update_json_handlers(app)
100108
# TODO: Currently unable to drop into debugger on error - investigate?
101109
# https://falcon.readthedocs.io/en/stable/api/app.html#falcon.App.add_error_handler
@@ -109,9 +117,9 @@ def export(output_path: Path = Path()) -> None:
109117
test_client = falcon_testing.TestClient(app)
110118
def read_write(url):
111119
log.info(url)
112-
path = output_path.joinpath(url.strip('/'))
113-
path.parent.mkdir(parents=True, exist_ok=True)
114-
with path.open('wt', encoding="utf-8") as filehandle:
120+
file_path = output_path.joinpath(url.strip('/'))
121+
file_path.parent.mkdir(parents=True, exist_ok=True)
122+
with file_path.open('wt', encoding="utf-8") as filehandle:
115123
data = test_client.simulate_get(url)
116124
filehandle.write(data.text)
117125
return data.json
@@ -133,13 +141,14 @@ def get_args():
133141
''',
134142
)
135143

136-
parser.add_argument('project_path', action='store', default='./', help='')
137-
parser.add_argument('language_path', action='store', default='./', help='')
144+
parser.add_argument('--path_project', action='store', default='./', help='', type=Path)
145+
parser.add_argument('--path_language', action='store', default='./', help='', type=Path)
146+
parser.add_argument('--path_static', action='store', default='./', help='', type=Path)
138147

139148
parser.add_argument('--host', action='store', default='0.0.0.0', help='')
140149
parser.add_argument('--port', action='store', default=8000, type=int, help='')
141150

142-
parser.add_argument('--export', action='store', type=Path)
151+
parser.add_argument('--export', action='store', default=None, type=Path)
143152

144153
parser.add_argument('--log_level', action='store', type=int, help='loglevel of output to stdout', default=logging.INFO)
145154

make_ver/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ test_docker:
3131
build_static_local:
3232
python3 api.py ../static/projects/ ../static/language_reference/languages/ --export
3333
serve_local:
34-
uv run -m pdb -c continue api.py ../static/projects/ ../static/language_reference/languages/
34+
#uv run -m pdb -c continue \
35+
api.py \
36+
--path_static ../static/ \
37+
--path_language ../language_reference/languages/ \
38+
--path_project ~/code/personal/TeachProgramming/teachprogramming/static/projects/ \
39+
3540
# http://localhost:8000/static/index.html
3641
# http://localhost:8000/api/v1/language_reference.json
3742
test:

make_ver/README.md

Whitespace-only changes.

make_ver/pyproject.toml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
[project]
2-
name = "make_ver"
3-
version = "0.0.0"
4-
description = ""
5-
readme = "README.md"
6-
requires-python = ">= 3.14"
7-
dependencies = [
8-
"falcon",
9-
]
2+
name = "make_ver"
3+
version = "0.0.0"
4+
description = ""
5+
readme = "README.md"
6+
requires-python = ">= 3.14"
7+
dependencies = [
8+
"falcon",
9+
]
10+
1011
[dependency-groups]
11-
dev = [
12-
"pytest",
13-
]
12+
dev = [
13+
"pytest",
14+
]
15+
1416
[tool.pytest]
15-
addopts = ["--doctest-modules"]
16-
pythonpath = ["."]
17-
cache_dir = "../.pytest_cache"
17+
addopts = ["--doctest-modules"]
18+
pythonpath = ["."]
19+
cache_dir = "../.pytest_cache"

0 commit comments

Comments
 (0)