-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backend improvements - BREAKING CHANGES (#178)
# Re-read the [installation instructions](https://github.com/HackSoc/hacksoc.org#installation) and use `hacksoc_org run` instead of `flask run` * Added build time global function * WIP changing how the CLI works * Slightly less WIP using `argparse` * Don't need pip-requirements any more. Documentation TODO * Fixed unit tests * github actions moment * Added cmark (cmarkgfm) backend * Updated docs * Added command-line help strings * Installation note * whoops
- Loading branch information
Showing
16 changed files
with
242 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
venv/ | ||
__pycache__/ | ||
build/ | ||
*.egg-info/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from typing import Callable, Dict | ||
from hacksoc_org import app | ||
from hacksoc_org.consts import * | ||
from hacksoc_org.freeze import freeze | ||
from hacksoc_org.serve import serve | ||
|
||
import argparse | ||
|
||
subcommand_handlers: Dict[str, Callable] = {} | ||
|
||
|
||
def subcommand(command_str: str) -> Callable[[Callable], Callable]: | ||
def inner(fn): | ||
subcommand_handlers[command_str] = fn | ||
return fn | ||
|
||
return inner | ||
|
||
|
||
def main(args=None): | ||
parser = argparse.ArgumentParser( | ||
allow_abbrev=False, | ||
epilog=""" | ||
SUBCOMMANDS | ||
run | ||
Starts a local development server on https://localhost:5000/. Automatically | ||
reloads when templates or Python code is changed. Recommended while | ||
developing pages or features. | ||
freeze | ||
Saves all URL routes to HTML files and copies `static/` to the `build/` | ||
directory. The resulting directory can be used with any standard HTTP | ||
server (nginx, Apache, etc). In development, recommend using `serve` | ||
instead for convenience. | ||
serve | ||
Calls `freeze` then starts a local HTTP server from `build/` on | ||
https://localhost:5000/. Will not automatically rebuild the website on | ||
content change, you will need to re-run `serve`. Recommended to use this at | ||
least once to check that a) new content is part of the "frozen" site and b) | ||
no errors occur in freezing the site. | ||
""".strip(), | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
) | ||
|
||
parser.add_argument( | ||
"action", choices=subcommand_handlers.keys(), help="Subcommand to run (see below)" | ||
) | ||
|
||
parser.add_argument( | ||
"--markdown", | ||
choices=["markdown2", "cmark"], | ||
default="markdown2", | ||
help="Markdown backend to use (default markdown2)", | ||
) | ||
|
||
args = parser.parse_args(args=args) | ||
|
||
app.config[CFG_MARKDOWN_IMPL] = args.markdown | ||
|
||
subcommand_handlers[args.action]() | ||
|
||
|
||
@subcommand("run") | ||
def do_run(): | ||
app.run() | ||
|
||
|
||
@subcommand("freeze") | ||
def do_freeze(): | ||
freeze() | ||
|
||
|
||
@subcommand("serve") | ||
def do_serve(): | ||
freeze() | ||
print() | ||
serve() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CFG_MARKDOWN_IMPL = "HACKSOC_ORG_MARKDOWN_IMPLEMENTATION" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
[tool.black] | ||
line-length = 100 | ||
target-version = ['py37', 'py38', 'py39'] | ||
|
||
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[metadata] | ||
name = hacksoc_org | ||
version = 1.0.0 | ||
|
||
[options] | ||
packages = find: | ||
install_requires = | ||
flask | ||
frozen-flask | ||
pyyaml | ||
pygments | ||
python-frontmatter | ||
pygit2 | ||
black | ||
markdown2 | ||
cmarkgfm | ||
# markdown-it-py | ||
# mistletoe | ||
# commonmark | ||
|
||
[options.entry_points] | ||
console_scripts = | ||
hacksoc_org = hacksoc_org.cli:main | ||
|
||
# [options.extras_require] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.