-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move asu/__init__.py to asu/asu.py * add CI to publish releases to PyPi. * apply black style Signed-off-by: Paul Spooren <[email protected]>
- Loading branch information
Showing
8 changed files
with
146 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Upload Python Package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel twine | ||
- name: Build and publish | ||
env: | ||
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | ||
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | ||
run: | | ||
python setup.py sdist bdist_wheel | ||
twine upload dist/* |
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,84 +1 @@ | ||
from pathlib import Path | ||
from redis import Redis | ||
|
||
from flask import Flask, redirect, send_from_directory | ||
from flask_cors import CORS | ||
|
||
import json | ||
from os import getenv | ||
|
||
|
||
def create_app(test_config: dict = None) -> Flask: | ||
"""Create the main Flask application | ||
Args: | ||
test_config (dict): A dictionry containing a configuration during tests | ||
Returns: | ||
Flask: The application | ||
""" | ||
|
||
redis_host = getenv("REDIS_HOST", "localhost") | ||
redis_port = getenv("REDIS_PORT", 6379) | ||
|
||
app = Flask(__name__, instance_relative_config=True) | ||
app.config.from_mapping( | ||
CA_PUBKEY=None, | ||
STORE_PATH=app.instance_path + "/public/store", | ||
JSON_PATH=app.instance_path + "/public/json", | ||
CACHE_PATH=app.instance_path + "/cache/", | ||
REDIS_CONN=Redis(host=redis_host, port=redis_port), | ||
TESTING=False, | ||
DEBUG=False, | ||
UPSTREAM_URL="https://downloads.cdn.openwrt.org", | ||
BRANCHES={}, | ||
) | ||
|
||
if not test_config: | ||
for config_file in [ | ||
"./config.py", | ||
app.instance_path + "/config.py", | ||
"/etc/asu/config.py", | ||
]: | ||
if Path(config_file).exists(): | ||
app.config.from_pyfile(config_file, silent=True) | ||
else: | ||
app.config.from_mapping(test_config) | ||
|
||
for option, value in app.config.items(): | ||
if option.endswith("_PATH") and isinstance(value, str): | ||
app.config[option] = Path(value) | ||
app.config[option].mkdir(parents=True, exist_ok=True) | ||
|
||
Path(app.instance_path).mkdir(exist_ok=True, parents=True) | ||
|
||
CORS(app, resources={r"/api/*": {"origins": "*"}}) | ||
|
||
# only serve files in DEBUG/TESTING mode | ||
# production should use nginx for static files | ||
if app.config["DEBUG"] or app.config["TESTING"]: | ||
|
||
@app.route("/") | ||
@app.route("/<path:path>") | ||
def root(path="index.html"): | ||
return send_from_directory(Path(app.instance_path) / "public", path) | ||
|
||
else: | ||
|
||
@app.route("/") | ||
def root(path="index.html"): | ||
return redirect("https://github.com/aparcar/asu/#api") | ||
|
||
from . import janitor | ||
|
||
app.register_blueprint(janitor.bp) | ||
|
||
from . import api | ||
|
||
app.register_blueprint(api.bp) | ||
|
||
(app.config["JSON_PATH"] / "branches.json").write_text( | ||
json.dumps(app.config["BRANCHES"]) | ||
) | ||
|
||
return app | ||
__version__ = "0.5.0" |
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,84 @@ | ||
from pathlib import Path | ||
from redis import Redis | ||
|
||
from flask import Flask, redirect, send_from_directory | ||
from flask_cors import CORS | ||
|
||
import json | ||
from os import getenv | ||
|
||
|
||
def create_app(test_config: dict = None) -> Flask: | ||
"""Create the main Flask application | ||
Args: | ||
test_config (dict): A dictionry containing a configuration during tests | ||
Returns: | ||
Flask: The application | ||
""" | ||
|
||
redis_host = getenv("REDIS_HOST", "localhost") | ||
redis_port = getenv("REDIS_PORT", 6379) | ||
|
||
app = Flask(__name__, instance_relative_config=True) | ||
app.config.from_mapping( | ||
CA_PUBKEY=None, | ||
STORE_PATH=app.instance_path + "/public/store", | ||
JSON_PATH=app.instance_path + "/public/json", | ||
CACHE_PATH=app.instance_path + "/cache/", | ||
REDIS_CONN=Redis(host=redis_host, port=redis_port), | ||
TESTING=False, | ||
DEBUG=False, | ||
UPSTREAM_URL="https://downloads.cdn.openwrt.org", | ||
BRANCHES={}, | ||
) | ||
|
||
if not test_config: | ||
for config_file in [ | ||
"./config.py", | ||
app.instance_path + "/config.py", | ||
"/etc/asu/config.py", | ||
]: | ||
if Path(config_file).exists(): | ||
app.config.from_pyfile(config_file, silent=True) | ||
else: | ||
app.config.from_mapping(test_config) | ||
|
||
for option, value in app.config.items(): | ||
if option.endswith("_PATH") and isinstance(value, str): | ||
app.config[option] = Path(value) | ||
app.config[option].mkdir(parents=True, exist_ok=True) | ||
|
||
Path(app.instance_path).mkdir(exist_ok=True, parents=True) | ||
|
||
CORS(app, resources={r"/api/*": {"origins": "*"}}) | ||
|
||
# only serve files in DEBUG/TESTING mode | ||
# production should use nginx for static files | ||
if app.config["DEBUG"] or app.config["TESTING"]: | ||
|
||
@app.route("/") | ||
@app.route("/<path:path>") | ||
def root(path="index.html"): | ||
return send_from_directory(Path(app.instance_path) / "public", path) | ||
|
||
else: | ||
|
||
@app.route("/") | ||
def root(path="index.html"): | ||
return redirect("https://github.com/aparcar/asu/#api") | ||
|
||
from . import janitor | ||
|
||
app.register_blueprint(janitor.bp) | ||
|
||
from . import api | ||
|
||
app.register_blueprint(api.bp) | ||
|
||
(app.config["JSON_PATH"] / "branches.json").write_text( | ||
json.dumps(app.config["BRANCHES"]) | ||
) | ||
|
||
return app |
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,14 +1,18 @@ | ||
Click | ||
Flask-Cors | ||
Flask | ||
Jinja2 | ||
MarkupSafe | ||
PyNaCl | ||
Werkzeug | ||
cffi | ||
itsdangerous | ||
pycparser | ||
redis | ||
requests | ||
rq | ||
six | ||
certifi==2020.12.5 | ||
cffi==1.14.5 | ||
chardet==4.0.0 | ||
click==7.1.2 | ||
Flask==1.1.2 | ||
Flask-Cors==3.0.10 | ||
idna==2.10 | ||
itsdangerous==1.1.0 | ||
Jinja2==2.11.3 | ||
MarkupSafe==1.1.1 | ||
pycparser==2.20 | ||
PyNaCl==1.4.0 | ||
redis==3.5.3 | ||
requests==2.25.1 | ||
rq==1.8.0 | ||
six==1.15.0 | ||
urllib3==1.26.4 | ||
Werkzeug==1.0.1 |
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
from setuptools import find_packages, setup | ||
from os.path import dirname, abspath, join | ||
|
||
from asu import __version__ | ||
|
||
|
||
with io.open("README.md", "rt", encoding="utf8") as f: | ||
readme = f.read() | ||
|
@@ -14,7 +16,7 @@ | |
|
||
setup( | ||
name="asu", | ||
version="0.4.1", | ||
version=__version__, | ||
url="https://github.com/aparcar/asu", | ||
maintainer="Paul Spooren", | ||
maintainer_email="[email protected]", | ||
|
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