Skip to content

Commit dcd4057

Browse files
committed
Squashed 'vimhelp/' content from commit b9410f6
git-subtree-dir: vimhelp git-subtree-split: b9410f6b039500d0b96585d2b3af51c85a77e29c
0 parents  commit dcd4057

35 files changed

+2927
-0
lines changed

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203,W503
4+
per-file-ignores = vimhelp/vimh2h.py:E126,E201,E202,E221,E272,E501,E701,W504
5+
exclude = .venv

.gcloudignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/.git
2+
/.gitignore
3+
/.gcloudignore
4+
/.venv
5+
/scripts
6+
/README.md
7+
/LICENSE
8+
/tasks.py
9+
__pycache__/

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TODO
2+
/vimhelp/secret.py
3+
/.venv/
4+
__pycache__/

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2016 Carlo Teubner
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# vimhelp.org
2+
3+
This is the code behind the https://vimhelp.org website. It runs on
4+
[Google App Engine](https://cloud.google.com/appengine/).
5+
6+
To make testing and deploying easier, a `tasks.py` file exists for use
7+
with the [_Invoke_](https://www.pyinvoke.org/) tool (which is similar in
8+
spirit to _Make_).
9+
10+
## Generating static pages
11+
12+
To generate static HTML pages instead of running on Google App Engine:
13+
14+
- Create a virtualenv. If you have _Invoke_ installed, this is as easy as
15+
`inv venv`. Alternatively:
16+
```
17+
python3 -m venv --upgrade-deps .venv
18+
.venv/bin/pip install -r requirements.txt
19+
```
20+
- Run the following (replace the `-i` parameter with the Vim documentation
21+
location on your computer):
22+
```
23+
scripts/h2h.py -i /usr/share/vim/vim90/doc/ -o html/
24+
```
25+
The script offers a few options; run with `-h` to see what is available.
26+
27+
## License
28+
29+
This code is made freely available under the MIT License (see file LICENSE).

app.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
runtime: python310
2+
3+
automatic_scaling:
4+
max_instances: 2
5+
max_idle_instances: 1
6+
target_cpu_utilization: 0.9
7+
target_throughput_utilization: 0.9
8+
max_concurrent_requests: 50
9+
min_pending_latency: 500ms
10+
11+
entrypoint: gunicorn -b :$PORT -k gevent -w 1 'vimhelp.webapp:create_app()'
12+
13+
default_expiration: "1h"
14+
15+
inbound_services:
16+
- warmup
17+
18+
handlers:
19+
- url: /(?:.*\.html)?
20+
script: auto
21+
secure: always
22+
- url: /api/.+
23+
script: auto
24+
secure: always
25+
- url: /(?:robots|sitemap)\.txt
26+
script: auto
27+
secure: always
28+
- url: /favicon\.ico
29+
script: auto
30+
secure: always
31+
- url: /(?:enqueue_)?update
32+
script: auto
33+
secure: always
34+
- url: /_ah/warmup
35+
script: auto
36+
secure: always
37+
- url: /(.+)
38+
static_files: static/\1
39+
upload: static/(.*)
40+
secure: always

cron.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cron:
2+
- description: fetch and process vim docs
3+
url: /enqueue_update?project=vim
4+
schedule: every 31 minutes
5+
- description: fetch and process neovim docs
6+
url: /enqueue_update?project=neovim
7+
schedule: every 32 minutes

gunicorn.conf.dev.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import traceback
2+
3+
4+
loglevel = "debug"
5+
reload = True
6+
reload_extra_files = ["static", "templates"]
7+
timeout = 15
8+
worker_class = "gevent"
9+
wsgi_app = "vimhelp.webapp:create_app()"
10+
11+
12+
def worker_abort(worker):
13+
traceback.print_stack()

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Flask ~= 2.2
2+
gevent ~= 22.10
3+
geventhttpclient ~= 2.0
4+
google-cloud-ndb ~= 2.1
5+
google-cloud-tasks ~= 2.12
6+
gunicorn ~= 20.1

scripts/h2h.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/usr/bin/env .venv/bin/python3
2+
3+
# This script is meant to be run from the top-level directory of the
4+
# repository, as 'scripts/h2h.py'. The virtualenv must already exist
5+
# (use "inv venv" to create it).
6+
7+
import argparse
8+
import os.path
9+
import pathlib
10+
import sys
11+
12+
import flask
13+
14+
root_path = pathlib.Path(__file__).parent.parent
15+
16+
sys.path.append(str(root_path))
17+
18+
from vimhelp.vimh2h import VimH2H # noqa: E402
19+
20+
21+
def main():
22+
parser = argparse.ArgumentParser(description="Convert Vim help files to HTML")
23+
parser.add_argument(
24+
"--in-dir",
25+
"-i",
26+
required=True,
27+
type=pathlib.Path,
28+
help="Directory of Vim doc files",
29+
)
30+
parser.add_argument(
31+
"--out-dir",
32+
"-o",
33+
type=pathlib.Path,
34+
help="Output directory (omit for no output)",
35+
)
36+
parser.add_argument(
37+
"--project",
38+
"-p",
39+
choices=("vim", "neovim"),
40+
default="vim",
41+
help="Vim flavour (default: vim)",
42+
)
43+
parser.add_argument(
44+
"--web-version",
45+
"-w",
46+
action="store_true",
47+
help="Generate the web version of the files (default: offline version)",
48+
)
49+
parser.add_argument(
50+
"--theme",
51+
"-t",
52+
choices=("light", "dark"),
53+
help="Color theme (default: OS-native)",
54+
)
55+
parser.add_argument(
56+
"--no-tags",
57+
"-T",
58+
action="store_true",
59+
help="Ignore any tags file, always recreate tags from scratch",
60+
)
61+
parser.add_argument(
62+
"--profile", "-P", action="store_true", help="Profile performance"
63+
)
64+
parser.add_argument(
65+
"basenames", nargs="*", help="List of files to process (default: all)"
66+
)
67+
args = parser.parse_args()
68+
69+
app = flask.Flask(
70+
__name__,
71+
root_path=pathlib.Path(__file__).resolve().parent,
72+
static_url_path="",
73+
static_folder="../static",
74+
template_folder="../templates",
75+
)
76+
app.jinja_options["trim_blocks"] = True
77+
app.jinja_options["lstrip_blocks"] = True
78+
79+
with app.app_context():
80+
if args.profile:
81+
import cProfile
82+
import pstats
83+
84+
with cProfile.Profile() as pr:
85+
run(args)
86+
stats = pstats.Stats(pr).sort_stats("cumulative")
87+
stats.print_stats()
88+
else:
89+
run(args)
90+
91+
92+
def run(args):
93+
if not args.in_dir.is_dir():
94+
raise RuntimeError(f"{args.in_dir} is not a directory")
95+
96+
prelude = VimH2H.prelude(theme=args.theme)
97+
98+
mode = "hybrid" if args.web_version else "offline"
99+
100+
if not args.no_tags and (tags_file := args.in_dir / "tags").is_file():
101+
print("Processing tags file...")
102+
h2h = VimH2H(mode=mode, project=args.project, tags=tags_file.read_text())
103+
faq = args.in_dir / "vim_faq.txt"
104+
if faq.is_file():
105+
print("Processing FAQ tags...")
106+
h2h.add_tags(faq.name, faq.read_text())
107+
else:
108+
print("Initializing tags...")
109+
h2h = VimH2H(mode=mode, project=args.project)
110+
for infile in args.in_dir.iterdir():
111+
if infile.suffix == ".txt":
112+
h2h.add_tags(infile.name, infile.read_text())
113+
114+
if args.out_dir is not None:
115+
args.out_dir.mkdir(exist_ok=True)
116+
117+
for infile in args.in_dir.iterdir():
118+
if len(args.basenames) != 0 and infile.name not in args.basenames:
119+
continue
120+
if infile.suffix != ".txt" and infile.name != "tags":
121+
print(f"Ignoring {infile}")
122+
continue
123+
content = infile.read_text()
124+
print(f"Processing {infile}...")
125+
html = h2h.to_html(infile.name, content)
126+
if args.out_dir is not None:
127+
with (args.out_dir / f"{infile.name}.html").open("w") as f:
128+
f.write(prelude)
129+
f.write(html)
130+
131+
if args.out_dir is not None:
132+
print("Symlinking static files...")
133+
static_dir_rel = os.path.relpath(root_path / "static", args.out_dir)
134+
for target in (root_path / "static").iterdir():
135+
target_name = target.name
136+
if target_name == f"favicon-{args.project}.ico":
137+
src_name = "favicon.ico"
138+
elif target_name.startswith("favicon-"):
139+
continue
140+
else:
141+
src_name = target_name
142+
src = pathlib.Path(args.out_dir / src_name)
143+
src.unlink(missing_ok=True)
144+
src.symlink_to(f"{static_dir_rel}/{target_name}")
145+
146+
print("Done.")
147+
148+
149+
main()

0 commit comments

Comments
 (0)