Skip to content

Commit

Permalink
Merge pull request #72 from c3g/develop
Browse files Browse the repository at this point in the history
Release v0.4.0
  • Loading branch information
zxenia committed Feb 21, 2020
2 parents e63e202 + ee2a68a commit 6eed6a2
Show file tree
Hide file tree
Showing 21 changed files with 452 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ env/
# coverage
.coverage
htmlcov/

# docs build

docs/_build
18 changes: 18 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 0.4.0

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
formats: all

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.7
install:
- requirements: docs/requirements.txt
2 changes: 1 addition & 1 deletion chord_metadata_service/chord/api_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import viewsets
from rest_framework.permissions import BasePermission, SAFE_METHODS
from chord_metadata_service.phenopackets.api_views import LargeResultsSetPagination
from chord_metadata_service.restapi.pagination import LargeResultsSetPagination
from .models import *
from .permissions import OverrideOrSuperUserOnly
from .serializers import *
Expand Down
3 changes: 3 additions & 0 deletions chord_metadata_service/chord/views_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def create_phenotypic_feature(pf):
return pf_obj


# Mounted on /private/, so will get protected anyway; this allows for access from WES
# TODO: Ugly and misleading permissions
@api_view(["POST"])
@permission_classes([AllowAny])
def ingest(request):
# Private ingest endpoints are protected by URL namespace, not by Django permissions.

Expand Down
8 changes: 7 additions & 1 deletion chord_metadata_service/chord/views_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import itertools
from datetime import datetime
import json

from django.db import connection
from django.conf import settings
Expand Down Expand Up @@ -167,6 +166,8 @@ def chord_search(request):
return search(request, internal_data=False)


# Mounted on /private/, so will get protected anyway; this allows for access from federation service
# TODO: Ugly and misleading permissions
@api_view(["POST"])
@permission_classes([AllowAny])
def chord_private_search(request):
Expand Down Expand Up @@ -262,13 +263,18 @@ def fhir_public_search(request):
return fhir_search(request)


# Mounted on /private/, so will get protected anyway
# TODO: Ugly and misleading permissions
@api_view(["POST"])
@permission_classes([AllowAny])
def fhir_private_search(request):
return fhir_search(request, internal_data=True)


# Mounted on /private/, so will get protected anyway; this allows for access from federation service
# TODO: Ugly and misleading permissions
@api_view(["POST"])
@permission_classes([AllowAny])
def chord_private_table_search(request, table_id):
# Search phenopacket data types in specific tables
# Private search endpoints are protected by URL namespace, not by Django permissions.
Expand Down
2 changes: 2 additions & 0 deletions chord_metadata_service/metadata/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

# CHORD-specific settings

CHORD_URL = os.environ.get("CHORD_URL", None) # Leave None if not specified, for running in other contexts

# SECURITY WARNING: Don't run with CHORD_PERMISSIONS turned off in production,
# unless an alternative permissions system is in place.
CHORD_PERMISSIONS = os.environ.get("CHORD_PERMISSIONS", str(not DEBUG)).lower() == "true"
Expand Down
9 changes: 2 additions & 7 deletions chord_metadata_service/patients/api_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rest_framework import viewsets, pagination
from rest_framework import viewsets
from rest_framework.settings import api_settings
from .serializers import IndividualSerializer
from .models import Individual
Expand All @@ -7,12 +7,7 @@
FHIRRenderer,
PhenopacketsRenderer
)


class LargeResultsSetPagination(pagination.PageNumberPagination):
page_size = 25
page_size_query_param = 'page_size'
max_page_size = 10000
from chord_metadata_service.restapi.pagination import LargeResultsSetPagination


class IndividualViewSet(viewsets.ModelViewSet):
Expand Down
14 changes: 5 additions & 9 deletions chord_metadata_service/phenopackets/api_views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from rest_framework import viewsets, pagination
from .serializers import *
from .models import *
from rest_framework import viewsets
from rest_framework.settings import api_settings
from chord_metadata_service.restapi.api_renderers import *


class LargeResultsSetPagination(pagination.PageNumberPagination):
page_size = 25
page_size_query_param = 'page_size'
max_page_size = 10000
from chord_metadata_service.restapi.api_renderers import *
from chord_metadata_service.restapi.pagination import LargeResultsSetPagination
from .serializers import *
from .models import *


class PhenopacketsModelViewSet(viewsets.ModelViewSet):
Expand Down
41 changes: 41 additions & 0 deletions chord_metadata_service/restapi/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from django.conf import settings
from rest_framework import pagination
from urllib.parse import urljoin


__all__ = [
"LargeResultsSetPagination",
]


class LargeResultsSetPagination(pagination.PageNumberPagination):
page_size = 25
page_size_query_param = 'page_size'
max_page_size = 10000

# Fix next/previous links inside sub-path-mounted reverse proxies in the CHORD context:

def _get_chord_absolute_uri(self):
full_path = self.request.get_full_path()
# Strip first slash if necessary, to avoid urljoin removing reverse proxy sub-paths
if len(full_path) > 0 and full_path[0] == "/":
full_path = full_path[1:]
return urljoin(settings.CHORD_URL, full_path)

def get_next_link(self):
if settings.CHORD_URL is not None:
# Monkey-patch rewrite build_absolute_uri
self.request.build_absolute_uri = self._get_chord_absolute_uri
return super(LargeResultsSetPagination, self).get_next_link()

def get_previous_link(self):
if settings.CHORD_URL is not None:
# Monkey-patch rewrite build_absolute_uri
self.request.build_absolute_uri = self._get_chord_absolute_uri
return super(LargeResultsSetPagination, self).get_previous_link()

def get_html_context(self):
if settings.CHORD_URL is not None:
# Monkey-patch rewrite build_absolute_uri
self.request.build_absolute_uri = self._get_chord_absolute_uri
super(LargeResultsSetPagination, self).get_html_context()
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
import django
sys.path.insert(0, os.path.abspath('..'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'chord_metadata_service.metadata.settings'
django.setup()


# -- Project information -----------------------------------------------------

project = 'Metadata service'
copyright = '2020, Ksenia Zaytseva, David Lougheed, Simon Chenard'
author = 'Ksenia Zaytseva, David Lougheed, Simon Chenard'

# The full version, including alpha/beta/rc tags
release = '0.3.0'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
26 changes: 26 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.. metadata service documentation master file, created by
sphinx-quickstart on Thu Feb 20 15:29:45 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to metadata service's documentation!
============================================

.. toctree::
:maxdepth: 2
:caption: Contents:

modules/introduction
modules/installation
modules/models
modules/views




Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
52 changes: 52 additions & 0 deletions docs/modules/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Installation
============

1. Clone the project from github (use :code:`-r` to fetch submodules content)

.. code-block::
git clone https://github.com/c3g/chord_metadata_service.git
2. Install the git submodule for DATS JSON schemas (if you did not clone recursively):

.. code-block::
git submodule update --init
3. Create and activate virtual environment

4. Cd to the main directory and install required packages:

.. code-block::
pip install -r requirements.txt
5. The service uses PostgreSQL database for data storage. Install PostgreSQL following `this tutorial <https://www.postgresql.org/docs/12/tutorial-install.html>`_.

6. Configure database connection in settings.py

e.g. settings if running database on localhost, default port for PostgreSQL is 5432:

.. code-block:: python
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database_name',
'USER': 'user',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '5432',
}
}
7. From the main directory run (where the manage.py file located):

.. code-block::
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
8. Development server runs at :code:`localhost:8000`

0 comments on commit 6eed6a2

Please sign in to comment.