Poetry: uvicorn with .env and command line arguments (#836)
* fixed poetry logs * make isort happy * Poetry: uvicorn .env and command line arguments * restore commands.py * format * own it Co-authored-by: dni <dni.khr@gmail.com>
This commit is contained in:
parent
91fefdb83d
commit
2edaa0ee03
2 changed files with 41 additions and 19 deletions
15
build.py
15
build.py
|
|
@ -8,6 +8,7 @@ from pathlib import Path
|
||||||
|
|
||||||
LNBITS_PATH = path.dirname(path.realpath(__file__)) + "/lnbits"
|
LNBITS_PATH = path.dirname(path.realpath(__file__)) + "/lnbits"
|
||||||
|
|
||||||
|
|
||||||
def get_js_vendored(prefer_minified: bool = False) -> List[str]:
|
def get_js_vendored(prefer_minified: bool = False) -> List[str]:
|
||||||
paths = get_vendored(".js", prefer_minified)
|
paths = get_vendored(".js", prefer_minified)
|
||||||
|
|
||||||
|
|
@ -71,6 +72,7 @@ def get_vendored(ext: str, prefer_minified: bool = False) -> List[str]:
|
||||||
def url_for_vendored(abspath: str) -> str:
|
def url_for_vendored(abspath: str) -> str:
|
||||||
return "/" + os.path.relpath(abspath, LNBITS_PATH)
|
return "/" + os.path.relpath(abspath, LNBITS_PATH)
|
||||||
|
|
||||||
|
|
||||||
def transpile_scss():
|
def transpile_scss():
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter("ignore")
|
warnings.simplefilter("ignore")
|
||||||
|
|
@ -80,6 +82,7 @@ def transpile_scss():
|
||||||
with open(os.path.join(LNBITS_PATH, "static/css/base.css"), "w") as css:
|
with open(os.path.join(LNBITS_PATH, "static/css/base.css"), "w") as css:
|
||||||
css.write(compile_string(scss.read()))
|
css.write(compile_string(scss.read()))
|
||||||
|
|
||||||
|
|
||||||
def bundle_vendored():
|
def bundle_vendored():
|
||||||
for getfiles, outputpath in [
|
for getfiles, outputpath in [
|
||||||
(get_js_vendored, os.path.join(LNBITS_PATH, "static/bundle.js")),
|
(get_js_vendored, os.path.join(LNBITS_PATH, "static/bundle.js")),
|
||||||
|
|
@ -96,15 +99,7 @@ def bundle_vendored():
|
||||||
def build():
|
def build():
|
||||||
transpile_scss()
|
transpile_scss()
|
||||||
bundle_vendored()
|
bundle_vendored()
|
||||||
# root = Path("lnbits/static/foo")
|
|
||||||
# root.mkdir(parents=True)
|
|
||||||
# root.joinpath("example.css").write_text("")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
build()
|
build()
|
||||||
|
|
||||||
#def build(setup_kwargs):
|
|
||||||
# """Build """
|
|
||||||
# transpile_scss()
|
|
||||||
# bundle_vendored()
|
|
||||||
# subprocess.run(["ls", "-la", "./lnbits/static"])
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,45 @@
|
||||||
|
import time
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
|
from lnbits.settings import HOST, PORT
|
||||||
|
|
||||||
@click.command()
|
|
||||||
@click.option("--port", default="5000", help="Port to run LNBits on")
|
@click.command(
|
||||||
@click.option("--host", default="127.0.0.1", help="Host to run LNBits on")
|
context_settings=dict(
|
||||||
def main(port, host):
|
ignore_unknown_options=True,
|
||||||
|
allow_extra_args=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
@click.option("--port", default=PORT, help="Port to listen on")
|
||||||
|
@click.option("--host", default=HOST, help="Host to run LNBits on")
|
||||||
|
@click.option("--ssl-keyfile", default=None, help="Path to SSL keyfile")
|
||||||
|
@click.option("--ssl-certfile", default=None, help="Path to SSL certificate")
|
||||||
|
@click.pass_context
|
||||||
|
def main(ctx, port: int, host: str, ssl_keyfile: str, ssl_certfile: str):
|
||||||
"""Launched with `poetry run lnbits` at root level"""
|
"""Launched with `poetry run lnbits` at root level"""
|
||||||
uvicorn.run("lnbits.__main__:app", port=port, host=host)
|
# this beautiful beast parses all command line arguments and passes them to the uvicorn server
|
||||||
|
d = dict(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
item[0].strip("--").replace("-", "_"),
|
||||||
|
int(item[1]) if item[1].isdigit() else item[1],
|
||||||
|
)
|
||||||
|
for item in zip(*[iter(ctx.args)] * 2)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
config = uvicorn.Config(
|
||||||
|
"lnbits.__main__:app",
|
||||||
|
port=port,
|
||||||
|
host=host,
|
||||||
|
ssl_keyfile=ssl_keyfile,
|
||||||
|
ssl_certfile=ssl_certfile,
|
||||||
|
**d
|
||||||
|
)
|
||||||
|
server = uvicorn.Server(config)
|
||||||
|
server.run()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
# def main():
|
|
||||||
# """Launched with `poetry run start` at root level"""
|
|
||||||
# uvicorn.run("lnbits.__main__:app")
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue