Skip to content

Commit 2b92548

Browse files
committed
version: bump to 0.5.0
* move asu/__init__.py to asu/asu.py * add CI to publish releases to PyPi. * apply black style Signed-off-by: Paul Spooren <mail@aparcar.org>
1 parent 2829cdc commit 2b92548

File tree

8 files changed

+146
-106
lines changed

8 files changed

+146
-106
lines changed

.github/workflows/publish.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Upload Python Package
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
deploy:
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: '3.x'
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install setuptools wheel twine
24+
25+
- name: Build and publish
26+
env:
27+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
28+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
29+
run: |
30+
python setup.py sdist bdist_wheel
31+
twine upload dist/*

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ Install *asu*:
6464

6565
Start the server via the following commands:
6666

67-
export FLASK_APP=asu # set Flask app to asu
68-
flask janitor update # download upstream profiles/packages
69-
flask run # run development server
67+
export FLASK_APP=asu.asu # set Flask app to asu
68+
flask janitor update # download upstream profiles/packages
69+
flask run # run development server
7070

7171
Start the worker via the following comand:
7272

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

101101
## API

asu/__init__.py

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1 @@
1-
from pathlib import Path
2-
from redis import Redis
3-
4-
from flask import Flask, redirect, send_from_directory
5-
from flask_cors import CORS
6-
7-
import json
8-
from os import getenv
9-
10-
11-
def create_app(test_config: dict = None) -> Flask:
12-
"""Create the main Flask application
13-
14-
Args:
15-
test_config (dict): A dictionry containing a configuration during tests
16-
17-
Returns:
18-
Flask: The application
19-
"""
20-
21-
redis_host = getenv("REDIS_HOST", "localhost")
22-
redis_port = getenv("REDIS_PORT", 6379)
23-
24-
app = Flask(__name__, instance_relative_config=True)
25-
app.config.from_mapping(
26-
CA_PUBKEY=None,
27-
STORE_PATH=app.instance_path + "/public/store",
28-
JSON_PATH=app.instance_path + "/public/json",
29-
CACHE_PATH=app.instance_path + "/cache/",
30-
REDIS_CONN=Redis(host=redis_host, port=redis_port),
31-
TESTING=False,
32-
DEBUG=False,
33-
UPSTREAM_URL="https://downloads.cdn.openwrt.org",
34-
BRANCHES={},
35-
)
36-
37-
if not test_config:
38-
for config_file in [
39-
"./config.py",
40-
app.instance_path + "/config.py",
41-
"/etc/asu/config.py",
42-
]:
43-
if Path(config_file).exists():
44-
app.config.from_pyfile(config_file, silent=True)
45-
else:
46-
app.config.from_mapping(test_config)
47-
48-
for option, value in app.config.items():
49-
if option.endswith("_PATH") and isinstance(value, str):
50-
app.config[option] = Path(value)
51-
app.config[option].mkdir(parents=True, exist_ok=True)
52-
53-
Path(app.instance_path).mkdir(exist_ok=True, parents=True)
54-
55-
CORS(app, resources={r"/api/*": {"origins": "*"}})
56-
57-
# only serve files in DEBUG/TESTING mode
58-
# production should use nginx for static files
59-
if app.config["DEBUG"] or app.config["TESTING"]:
60-
61-
@app.route("/")
62-
@app.route("/<path:path>")
63-
def root(path="index.html"):
64-
return send_from_directory(Path(app.instance_path) / "public", path)
65-
66-
else:
67-
68-
@app.route("/")
69-
def root(path="index.html"):
70-
return redirect("https://github.com/aparcar/asu/#api")
71-
72-
from . import janitor
73-
74-
app.register_blueprint(janitor.bp)
75-
76-
from . import api
77-
78-
app.register_blueprint(api.bp)
79-
80-
(app.config["JSON_PATH"] / "branches.json").write_text(
81-
json.dumps(app.config["BRANCHES"])
82-
)
83-
84-
return app
1+
__version__ = "0.5.0"

asu/asu.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from pathlib import Path
2+
from redis import Redis
3+
4+
from flask import Flask, redirect, send_from_directory
5+
from flask_cors import CORS
6+
7+
import json
8+
from os import getenv
9+
10+
11+
def create_app(test_config: dict = None) -> Flask:
12+
"""Create the main Flask application
13+
14+
Args:
15+
test_config (dict): A dictionry containing a configuration during tests
16+
17+
Returns:
18+
Flask: The application
19+
"""
20+
21+
redis_host = getenv("REDIS_HOST", "localhost")
22+
redis_port = getenv("REDIS_PORT", 6379)
23+
24+
app = Flask(__name__, instance_relative_config=True)
25+
app.config.from_mapping(
26+
CA_PUBKEY=None,
27+
STORE_PATH=app.instance_path + "/public/store",
28+
JSON_PATH=app.instance_path + "/public/json",
29+
CACHE_PATH=app.instance_path + "/cache/",
30+
REDIS_CONN=Redis(host=redis_host, port=redis_port),
31+
TESTING=False,
32+
DEBUG=False,
33+
UPSTREAM_URL="https://downloads.cdn.openwrt.org",
34+
BRANCHES={},
35+
)
36+
37+
if not test_config:
38+
for config_file in [
39+
"./config.py",
40+
app.instance_path + "/config.py",
41+
"/etc/asu/config.py",
42+
]:
43+
if Path(config_file).exists():
44+
app.config.from_pyfile(config_file, silent=True)
45+
else:
46+
app.config.from_mapping(test_config)
47+
48+
for option, value in app.config.items():
49+
if option.endswith("_PATH") and isinstance(value, str):
50+
app.config[option] = Path(value)
51+
app.config[option].mkdir(parents=True, exist_ok=True)
52+
53+
Path(app.instance_path).mkdir(exist_ok=True, parents=True)
54+
55+
CORS(app, resources={r"/api/*": {"origins": "*"}})
56+
57+
# only serve files in DEBUG/TESTING mode
58+
# production should use nginx for static files
59+
if app.config["DEBUG"] or app.config["TESTING"]:
60+
61+
@app.route("/")
62+
@app.route("/<path:path>")
63+
def root(path="index.html"):
64+
return send_from_directory(Path(app.instance_path) / "public", path)
65+
66+
else:
67+
68+
@app.route("/")
69+
def root(path="index.html"):
70+
return redirect("https://github.com/aparcar/asu/#api")
71+
72+
from . import janitor
73+
74+
app.register_blueprint(janitor.bp)
75+
76+
from . import api
77+
78+
app.register_blueprint(api.bp)
79+
80+
(app.config["JSON_PATH"] / "branches.json").write_text(
81+
json.dumps(app.config["BRANCHES"])
82+
)
83+
84+
return app

asu/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def get_request_hash(req: dict) -> str:
7575
req.get("profile", "").replace(",", "_"),
7676
get_packages_hash(req.get("packages", "")),
7777
get_manifest_hash(req.get("packages_versions", {})),
78-
str(req.get("diff_packages", False))
78+
str(req.get("diff_packages", False)),
7979
]
8080
return get_str_hash(" ".join(request_array), 12)
8181

requirements.txt

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
Click
2-
Flask-Cors
3-
Flask
4-
Jinja2
5-
MarkupSafe
6-
PyNaCl
7-
Werkzeug
8-
cffi
9-
itsdangerous
10-
pycparser
11-
redis
12-
requests
13-
rq
14-
six
1+
certifi==2020.12.5
2+
cffi==1.14.5
3+
chardet==4.0.0
4+
click==7.1.2
5+
Flask==1.1.2
6+
Flask-Cors==3.0.10
7+
idna==2.10
8+
itsdangerous==1.1.0
9+
Jinja2==2.11.3
10+
MarkupSafe==1.1.1
11+
pycparser==2.20
12+
PyNaCl==1.4.0
13+
redis==3.5.3
14+
requests==2.25.1
15+
rq==1.8.0
16+
six==1.15.0
17+
urllib3==1.26.4
18+
Werkzeug==1.0.1

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from setuptools import find_packages, setup
44
from os.path import dirname, abspath, join
55

6+
from asu import __version__
7+
68

79
with io.open("README.md", "rt", encoding="utf8") as f:
810
readme = f.read()
@@ -14,7 +16,7 @@
1416

1517
setup(
1618
name="asu",
17-
version="0.4.1",
19+
version=__version__,
1820
url="https://github.com/aparcar/asu",
1921
maintainer="Paul Spooren",
2022
maintainer_email="mail@aparcar.org",

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def redis():
3737
"profiles-SNAPSHOT-SNAPSHOT",
3838
mapping={"testprofile": "testtarget/testsubtarget"},
3939
)
40-
r.hset("mapping-SNAPSHOT-SNAPSHOT", mapping={"testvendor,testprofile": "testprofile"})
40+
r.hset(
41+
"mapping-SNAPSHOT-SNAPSHOT", mapping={"testvendor,testprofile": "testprofile"}
42+
)
4143
r.sadd("targets-SNAPSHOT", "testtarget/testsubtarget")
4244
yield r
4345

0 commit comments

Comments
 (0)