Skip to content

Commit

Permalink
version: bump to 0.5.0
Browse files Browse the repository at this point in the history
* 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
aparcar committed Apr 12, 2021
1 parent 2829cdc commit 2b92548
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 106 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/publish.yml
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/*
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ Install *asu*:

Start the server via the following commands:

export FLASK_APP=asu # set Flask app to asu
flask janitor update # download upstream profiles/packages
flask run # run development server
export FLASK_APP=asu.asu # set Flask app to asu
flask janitor update # download upstream profiles/packages
flask run # run development server

Start the worker via the following comand:

Expand Down Expand Up @@ -94,8 +94,8 @@ the dependencies:
python3 -m venv .
source bin/activate
pip install -r requirements.txt
export FLASK_APP=asu # set Flask app to asu
export FLASK_DEBUG=1 # run Flask in debug mode (autoreload)
export FLASK_APP=asu.asu # set Flask app to asu
export FLASK_DEBUG=1 # run Flask in debug mode (autoreload)
flask run

## API
Expand Down
85 changes: 1 addition & 84 deletions asu/__init__.py
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"
84 changes: 84 additions & 0 deletions asu/asu.py
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
2 changes: 1 addition & 1 deletion asu/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_request_hash(req: dict) -> str:
req.get("profile", "").replace(",", "_"),
get_packages_hash(req.get("packages", "")),
get_manifest_hash(req.get("packages_versions", {})),
str(req.get("diff_packages", False))
str(req.get("diff_packages", False)),
]
return get_str_hash(" ".join(request_array), 12)

Expand Down
32 changes: 18 additions & 14 deletions requirements.txt
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
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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]",
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def redis():
"profiles-SNAPSHOT-SNAPSHOT",
mapping={"testprofile": "testtarget/testsubtarget"},
)
r.hset("mapping-SNAPSHOT-SNAPSHOT", mapping={"testvendor,testprofile": "testprofile"})
r.hset(
"mapping-SNAPSHOT-SNAPSHOT", mapping={"testvendor,testprofile": "testprofile"}
)
r.sadd("targets-SNAPSHOT", "testtarget/testsubtarget")
yield r

Expand Down

0 comments on commit 2b92548

Please sign in to comment.