Skip to content

Commit d84d063

Browse files
committed
Reorganize into proper Python package
1 parent d227325 commit d84d063

File tree

19 files changed

+129
-56
lines changed

19 files changed

+129
-56
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ python:
55
- "2.7"
66
- "3.3"
77
- "3.4"
8+
- "3.5"
89
install:
9-
- pip install -r requirements.txt
10-
- python main.py quickstart
10+
- pip install -e .
11+
- mme-server quickstart
1112
script:
12-
- coverage run -m unittest
13+
- coverage run --source=mme_server setup.py test
1314
services:
1415
- elasticsearch
1516
before_script:

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Include static package files
2+
include LICENSE.txt
3+
include README.md
4+
include MANIFEST.in
5+
recursive-include mme_server/schemas *.json

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,54 @@ This code is intended to be illustrative and is **not** guaranteed to perform we
77

88

99
## Dependencies
10-
- Python 2.7 or 3.X
10+
- Python 2.7 or 3.3+
1111
- ElasticSearch
1212

1313

1414
## Quickstart
1515

1616
1. Clone the repository:
1717

18-
```bash
18+
```sh
1919
git clone https://github.com/MatchmakerExchange/reference-server.git
2020
cd reference-server
2121
```
2222

23-
1. Install the Python package dependencies (it's recommended that you use a [Python virtual environment](#install-es)):
23+
1. Install the Python package dependencies (it's recommended that you do this inside a [Python virtual environment](#install-venv)):
2424
25-
```bash
26-
pip install -r requirements.txt
25+
```sh
26+
pip install -e .
2727
```
2828
2929
1. Start up your elasticsearch server in another shell (see the [ElasticSearch instructions](#install-es) for more information).
3030
31-
```bash
31+
```sh
3232
./path/to/elasticsearch
3333
```
3434
3535
1. Download and index vocabularies and sample data:
3636
37-
```bash
38-
python server.py quickstart
37+
```sh
38+
mme-server quickstart
3939
```
4040
4141
1. Run tests:
4242
43-
```bash
44-
python test.py
43+
```sh
44+
mme-server test
4545
```
4646
4747
1. Start up MME reference server:
4848
49-
```bash
50-
python server.py run
49+
```sh
50+
mme-server start
5151
```
5252
5353
By default, the server listens globally (`--host 0.0.0.0`) on port 8000 (`--port 8000`).
5454
5555
1. Try it out:
5656
57-
```bash
57+
```sh
5858
curl -XPOST -H 'Content-Type: application/vnd.ga4gh.matchmaker.v1.0+json' \
5959
-H 'Accept: application/vnd.ga4gh.matchmaker.v1.0+json' \
6060
-d '{"patient":{
@@ -73,32 +73,32 @@ It's recommended that you run the server within a Python virtual environment so
7373

7474
To set up your Python virtual environment:
7575

76-
```bash
76+
```sh
7777
# Set up virtual environment within a folder '.virtualenv' (add `-p python3` to force python 3)
7878
virtualenv .virtualenv
7979
8080
# Install dependencies
81-
pip install -r requirements.txt
81+
pip install -e .
8282
```
8383

8484
You can then activate this environment within a particular shell with:
8585

86-
```bash
86+
```sh
8787
source .virtualenv/bin/activate
8888
```
8989

9090
### <a name="install-es"></a> ElasticSearch
9191

9292
First, download elasticsearch:
9393

94-
```bash
94+
```sh
9595
wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.1.1/elasticsearch-2.1.1.tar.gz
9696
tar -xzf elasticsearch-2.1.1.tar.gz
9797
```
9898

9999
Then, start up a local elasticsearch cluster to serve as our database (`-Des.path.data=data` puts the elasticsearch indices in a subdirectory called `data`):
100100

101-
```bash
101+
```sh
102102
./elasticsearch-2.1.1/bin/elasticsearch -Des.path.data=data
103103
```
104104

@@ -109,22 +109,22 @@ Then, start up a local elasticsearch cluster to serve as our database (`-Des.pat
109109
Custom patient data can be indexed by the server in two ways (if a patient 'id' matches an existing patient, the existing patient is updated):
110110

111111
1. Batch index from the command line:
112-
```bash
113-
python server.py index patients --filename patients.json
112+
```sh
113+
mme-server index patients --filename patients.json
114114
```
115115

116116
1. Batch index from the Python interface:
117117

118-
```python
119-
>>> from models import DatastoreConnection
118+
```py
119+
>>> from mme_server.models import DatastoreConnection
120120
>>> db = DatastoreConnection()
121121
>>> db.patients.index('/path/to/patients.json')
122122
```
123123

124124
1. Single patient index the Python interface:
125125

126-
```python
127-
>>> from models import Patient, DatastoreConnection
126+
```py
127+
>>> from mme_server.models import Patient, DatastoreConnection
128128
>>> db = DatastoreConnection()
129129
>>> patient = Patient.from_api({...})
130130
>>> db.patients.index_patient(patient)

mme_server/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .cli import main

mme_server/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .cli import main
2+
3+
main()

main.py renamed to mme_server/cli.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import sys
77
import os
88
import logging
9+
import unittest
910

10-
from compat import urlretrieve
11-
12-
from models import get_backend
13-
from server import app
11+
from .compat import urlretrieve
12+
from .models import get_backend
13+
from .server import app
1414

1515

1616
DEFAULT_HOST = '0.0.0.0'
@@ -73,6 +73,11 @@ def fetch_resource(filename, url):
7373
logger.info('Saved file to: {}'.format(filename))
7474

7575

76+
def run_tests():
77+
suite = unittest.TestLoader().discover('.'.join([__package__, 'tests']))
78+
unittest.TextTestRunner().run(suite)
79+
80+
7681
def parse_args(args):
7782
from argparse import ArgumentParser
7883

@@ -102,7 +107,7 @@ def parse_args(args):
102107
help="Download data from the following url")
103108
subparser.set_defaults(function=index_file)
104109

105-
subparser = subparsers.add_parser('run', description="Start running a simple Matchmaker Exchange API server")
110+
subparser = subparsers.add_parser('start', description="Start running a simple Matchmaker Exchange API server")
106111
subparser.add_argument("-p", "--port", default=DEFAULT_PORT,
107112
dest="port", type=int, metavar="PORT",
108113
help="The port the server will listen on (default: %(default)s)")
@@ -111,6 +116,9 @@ def parse_args(args):
111116
help="The host the server will listen to (0.0.0.0 to listen globally; 127.0.0.1 to listen locally; default: %(default)s)")
112117
subparser.set_defaults(function=app.run)
113118

119+
subparser = subparsers.add_parser('test', description="Run tests")
120+
subparser.set_defaults(function=run_tests)
121+
114122
args = parser.parse_args(args)
115123
if not hasattr(args, 'function'):
116124
parser.error('a subcommand must be specified')
File renamed without changes.

datastore.py renamed to mme_server/datastore.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
import codecs
1515

1616
from elasticsearch import Elasticsearch
17-
from parsers import OBOParser, GeneParser
17+
18+
from .parsers import OBOParser, GeneParser
1819

1920

2021
logger = logging.getLogger(__name__)
@@ -56,7 +57,7 @@ def __init__(self, index='patients', backend=None):
5657

5758
def index(self, filename):
5859
"""Populate the database with patient data from the given file"""
59-
from models import Patient
60+
from .models import Patient
6061

6162
with codecs.open(filename, encoding='utf-8') as ifp:
6263
data = json.load(ifp)

models.py renamed to mme_server/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from copy import deepcopy
99

1010
import flask
11-
from datastore import DatastoreConnection
11+
12+
from .datastore import DatastoreConnection
1213

1314

1415
class Feature:
File renamed without changes.

0 commit comments

Comments
 (0)