Skip to content

Commit

Permalink
Merge pull request #33 from bento-platform/features/service-drs-version
Browse files Browse the repository at this point in the history
Features/service drs version
  • Loading branch information
ppillot authored Oct 7, 2022
2 parents dda2986 + 4885131 commit 4e9f390
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ htmlcov/
.idea/workspace.xml
*.swp
*.swo
.vscode

# others
*.pyc
Expand Down
5 changes: 5 additions & 0 deletions chord_drs/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import subprocess

from bento_lib.responses import flask_errors
from flask import Flask
from flask_migrate import Migrate
Expand Down Expand Up @@ -44,6 +46,9 @@
if not application.config["CHORD_URL"]:
metrics.init_app(application)

if application.config["BENTO_DEBUG"]:
subprocess.run(["git", "config", "--global", "--add", "safe.directory", str(APP_DIR)])

# # debugger section
# Ensure 'debugpy' is installed (via requirements.txt or manually)
DEBUG = os.environ.get('FLASK_DEBUG', False)
Expand Down
2 changes: 2 additions & 0 deletions chord_drs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Config:
MINIO_USERNAME: Optional[str] = MINIO_USERNAME
MINIO_PASSWORD: Optional[str] = MINIO_PASSWORD
MINIO_BUCKET: Optional[str] = os.environ.get("MINIO_BUCKET") if MINIO_URL else None
BENTO_DEBUG = os.environ.get("FLASK_DEBUG", os.environ.get("FLASK_ENV", "production")).strip().lower() in (
'true', '1', 'development')


print(f"[{SERVICE_NAME}] Using: database URI {Config.SQLALCHEMY_DATABASE_URI}")
Expand Down
2 changes: 1 addition & 1 deletion chord_drs/package.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = chord_drs
version = 0.5.3
version = 0.6.0
authors = Simon Chénard, David Lougheed
author_emails = simon.chenard2@mcgill.ca, david.lougheed@mail.mcgill.ca
24 changes: 22 additions & 2 deletions chord_drs/routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import urllib.parse
import subprocess

from bento_lib.responses import flask_errors
from flask import (
Expand Down Expand Up @@ -145,7 +146,7 @@ def build_object_json(drs_object: DrsObject, inside_container: bool = False) ->
@drs_service.route("/service-info", methods=["GET"])
def service_info():
# Spec: https://github.com/ga4gh-discovery/ga4gh-service-info
return jsonify({
info = {
"id": current_app.config["SERVICE_ID"],
"name": SERVICE_NAME,
"type": SERVICE_TYPE,
Expand All @@ -156,7 +157,26 @@ def service_info():
},
"contactUrl": "mailto:simon.chenard2@mcgill.ca",
"version": __version__,
})
"environment": "prod"
}

if not current_app.config["BENTO_DEBUG"]:
return jsonify(info)

info["environment"] = "dev"
try:
res_tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"])
if res_tag:
info["git_tag"] = res_tag.decode().rstrip()
res_branch = subprocess.check_output(["git", "branch", "--show-current"])
if res_branch:
info["git_branch"] = res_branch.decode().rstrip()

except Exception as e:
except_name = type(e).__name__
print("Error in dev-mode retrieving git information", except_name, e)

return jsonify(info)


@drs_service.route("/objects/<string:object_id>", methods=["GET"])
Expand Down

0 comments on commit 4e9f390

Please sign in to comment.