Skip to content

Commit

Permalink
Formatted endpoints (#284)
Browse files Browse the repository at this point in the history
* Formatted endpoints

* Added black as dev dependency

* Added a workflow script that will run black on every PR

* Forgot to save when vscode was open

* Fixing error in yml file

* Changed pyproject.toml to configure blakc

* Addressing PR comments

* Amending Dockerfile
  • Loading branch information
aviraljain99 committed Jun 15, 2022
1 parent 9487403 commit 902bc57
Show file tree
Hide file tree
Showing 9 changed files with 414 additions and 410 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/black_python_formatter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Black Python Formatter

on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
# Name the Job
name: Python Formatter
# Set the agent to run on
runs-on: ubuntu-20.04

##################
# Load all steps #
##################
steps:
##########################
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v2
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0

###################################
# Run Formatter against code base #
###################################
- name: Format Python Files
uses: github/super-linter@v4
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_PYTHON_BLACK: true
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ ADD http://www.random.org/strings/?num=10&len=8&digits=on&upperalpha=on&loweralp
WORKDIR /

RUN echo "===> Install Elpis"
# Remove `--single-branch` or include `--branch hft` below for development
# Remove `--single-branch` and replace with `--branch <your_branch_name>` below for development
RUN git clone --single-branch --depth=1 https://github.com/CoEDL/elpis.git

WORKDIR /elpis
Expand Down
66 changes: 19 additions & 47 deletions elpis/endpoints/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,43 @@
bp = Blueprint("config", __name__, url_prefix="/config")


@bp.route("/reset", methods=['GET', 'POST'])
@bp.route("/reset", methods=["GET", "POST"])
def reset():
current_interface_path = app.config['INTERFACE'].path
app.config['INTERFACE'] = Interface(current_interface_path)
data = {
"message": "reset ok"
}
return jsonify({
"status": 200,
"data": data
})
current_interface_path = app.config["INTERFACE"].path
app.config["INTERFACE"] = Interface(current_interface_path)
data = {"message": "reset ok"}
return jsonify({"status": 200, "data": data})


@bp.route("/engine/list", methods=['GET', 'POST'])
@bp.route("/engine/list", methods=["GET", "POST"])
def engine_list():
data = {
"engine_list": list(ENGINES.keys())
}
return jsonify({
"status": 200,
"data": data
})
data = {"engine_list": list(ENGINES.keys())}
return jsonify({"status": 200, "data": data})


@bp.route("/engine/load", methods=['GET', 'POST'])
@bp.route("/engine/load", methods=["GET", "POST"])
def engine_load():
engine_name = request.json["engine_name"]
if engine_name not in ENGINES:
return jsonify({"status": 404,
"data": "Engine not found in ENGINES"})
return jsonify({"status": 404, "data": "Engine not found in ENGINES"})
engine = ENGINES[engine_name]
interface = app.config['INTERFACE']
interface = app.config["INTERFACE"]
interface.set_engine(engine)
data = {
"engine": engine_name
}
return jsonify({
"status": 200,
"data": data
})
data = {"engine": engine_name}
return jsonify({"status": 200, "data": data})


@bp.route("/object-names", methods=['GET', 'POST'])
@bp.route("/object-names", methods=["GET", "POST"])
def object_names():
interface: Interface = app.config['INTERFACE']
interface: Interface = app.config["INTERFACE"]
data = {
"object_names": {
"datasets": interface.list_datasets(),
"pron_dicts": interface.list_pron_dicts_verbose(), # includes pd name and ds name
"models": interface.list_models()
"models": interface.list_models(),
}
}
return jsonify({
"status": 200,
"data": data
})
return jsonify({"status": 200, "data": data})


# /api/config/list
Expand All @@ -76,14 +57,5 @@ def config_list():
dev_mode = False
# Add config settings explicitly, we don't need to share everything
# Also pass back the engine list so that we can populate dev widgets without making another request
data = {
"config": {
"dev_mode": dev_mode
},
"engine_list": list(ENGINES.keys())
}
return jsonify({
"status": 200,
"data": data
})

data = {"config": {"dev_mode": dev_mode}, "engine_list": list(ENGINES.keys())}
return jsonify({"status": 200, "data": data})

0 comments on commit 902bc57

Please sign in to comment.