Skip to content

Commit

Permalink
run web tests before publishing release; updated convert_map, fixes #82
Browse files Browse the repository at this point in the history
…; also:

- fixes bugs with Python 3 and url response decoding
- make maps full height in latest iPython notebooks
- update notebooks
- run py.test web tests on Travis to make sure they work across python versions
- website merge instructions
- version 1.1.2
  • Loading branch information
zakandrewking committed Apr 22, 2015
1 parent 8ebc221 commit cf08ba6
Show file tree
Hide file tree
Showing 16 changed files with 983 additions and 866 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ before_install:
install:
- python setup.py develop
# # command to run tests
script: python setup.py test --noweb --pyonly
script: python setup.py test --pyonly
notifications:
email: false
7 changes: 7 additions & 0 deletions WEBSITE_MERGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
git fetch escher
git merge escher/1.1.2-fix --no-commit --no-ff
source env/bin/activate
python setup.py buildgh
git add -A :/
gc -m"version 1.1.2"
git push
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
# built documents.
#
# The short X.Y version.
version = '1.1.1'
version = '1.1.2'
# The full version, including alpha/beta/rc tags.
release = '1.1.1'
release = '1.1.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
1,047 changes: 543 additions & 504 deletions docs/notebooks/COBRApy and Escher.ipynb

Large diffs are not rendered by default.

675 changes: 345 additions & 330 deletions docs/notebooks/JavaScript development and offline maps.ipynb

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion escher/convert_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def convert(map, model):

# add missing elements
for k in ['nodes', 'reactions', 'text_labels']:
if k not in map_body:
if k not in map_body or len(map_body[k]) == 0:
map_body[k] = {}
# default canvas
if 'canvas' not in map_body:
Expand Down Expand Up @@ -154,11 +154,21 @@ def convert(map, model):
"genes", "metabolites", "segments"]:
del reaction[key]

# cast attributes
for k in ['label_x', 'label_y']:
reaction[k] = float(reaction[k])

# unsupported attributes in segments
for s_id, segment in reaction['segments'].items():
for key in list(segment.keys()):
if not key in ["from_node_id", "to_node_id", "b1", "b2"]:
del segment[key]

# cast attributes
for k in ['b1', 'b2']:
if segment[k] is not None and (segment[k]['x'] is None or segment[k]['y'] is None):
segment[k] = None

# keep track of nodes that have appeared here
for key in ['from_node_id', 'to_node_id']:
try:
Expand Down
4 changes: 2 additions & 2 deletions escher/css/builder-1.1.1.css → escher/css/builder-1.1.2.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
/* position: absolute; */
/* top: 0px; */
/* left: 0px; */
width: 100%;
height: 100%;
width: 100% !important;
height: 100% !important;
}
/* Status */
#status {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
43 changes: 23 additions & 20 deletions escher/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from warnings import warn
try:
from urllib.request import urlopen
from urllib.error import HTTPError, URLError
from urllib.error import URLError
except:
from urllib2 import urlopen, HTTPError, URLError
from urllib2 import urlopen, URLError
import json
import shutil
import re
Expand Down Expand Up @@ -81,7 +81,8 @@ def server_index():
download = urlopen(url)
except URLError:
raise URLError('Could not contact Escher server')
index = json.loads(download.read())
data = _decode_response(download)
index = json.loads(data)
return index

def list_available_maps():
Expand Down Expand Up @@ -130,9 +131,9 @@ def match_in_index(name, index, kind):
warn('%s not in cache. Attempting download from %s' % (kind.title(), url))
try:
download = urlopen(url)
except HTTPError:
except URLError:
raise ValueError('No %s found in cache or at %s' % (kind, url))
data = download.read()
data = _decode_response(download)
# save the file
org_path = join(cache_dir, kind + 's', org)
try:
Expand All @@ -141,7 +142,7 @@ def match_in_index(name, index, kind):
pass
with open(join(org_path, name + '.json'), 'w') as outfile:
outfile.write(data)
return data.decode('utf-8')
return data

def model_json_for_name(model_name, cache_dir=get_cache_dir()):
return _json_for_name(model_name, 'model', cache_dir)
Expand All @@ -155,6 +156,19 @@ def _get_an_id():
return (''.join(random.choice(string.ascii_lowercase)
for _ in range(10)))

def _decode_response(download):
"""Decode the urllib.response.addinfourl response."""
data = download.read()
try: # Python 2
encoding = download.headers.getparam('charset')
except AttributeError: # Python 3
encoding = download.headers.get_param('charset')
if encoding:
data = data.decode(encoding)
else:
data = data.decode('utf-8')
return data

def _load_resource(resource, name, safe=False):
"""Load a resource that could be a file, URL, or json string."""
# if it's a url, download it
Expand All @@ -164,13 +178,7 @@ def _load_resource(resource, name, safe=False):
except URLError as err:
raise err
else:
data = download.read()
encoding = download.headers.getparam('charset')
if encoding:
data = data.decode(encoding)
else:
data = data.decode('utf-8')
return data
return _decode_response(download)
# if it's a filepath, load it
if os.path.exists(resource):
if (safe):
Expand Down Expand Up @@ -424,16 +432,11 @@ def _embedded_css(self, url_source):
local_host=self.local_host, protocol='https')
try:
download = urlopen(loc)
except ValueError:
except URLError:
raise Exception(('Could not find builder_embed_css. Be sure to pass '
'a local_host argument to Builder if js_source is dev or local '
'and you are in an iPython notebook or a static html file.'))
data = download.read()
encoding = download.headers.getparam('charset')
if encoding:
data = data.decode(encoding)
else:
data = data.decode('utf-8')
data = _decode_response(download)
return data.replace('\n', ' ')

def _initialize_javascript(self, the_id, url_source):
Expand Down
21 changes: 18 additions & 3 deletions escher/tests/test_convert_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,31 @@ def test_convert():

# map
old_map = {'reactions': {'1': {'bigg_id': 'GAPD',
'label_x': 0,
'label_x': '0',
'label_y': 0,
'segments': {'2': {'from_node_id': '0',
'to_node_id': '1',
'b1': None,
'b1': {'x': None, 'y': None},
'b2': None}}},
'2': {'bigg_id': 'PDH'}},
'nodes': {'3': {'node_type': 'metabolite',
'nodes': {'0': {'node_type': 'multimarker',
'x': 1,
'y': 2},
'1': {'node_type': 'metabolite',
'label_x': 10,
'label_y': 12.2,
'x': 1,
'y': 2,
'bigg_id': 'g3p_c',
'name': 'glycerol-3-phosphate'},
'3': {'node_type': 'metabolite',
'x': 1,
'y': 2,
'bigg_id': 'glc__D_c',
'name': 'D-Glucose'}}}

new_map = convert(old_map, model)
print(new_map)

# no segments: delete reaction
assert '2' not in new_map[1]['reactions']
Expand All @@ -44,5 +55,9 @@ def test_convert():
# annoying.
assert '3' not in new_map[1]['nodes']

# casting
assert type(new_map[1]['reactions']['1']['label_x']) is float
assert new_map[1]['reactions']['1']['segments']['2']['b1'] is None

def test_genes_for_gene_reaction_rule():
assert genes_for_gene_reaction_rule('((G1 and G2)or G3and)') == ['G1', 'G2', 'G3and']
2 changes: 1 addition & 1 deletion escher/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.1.1'
__version__ = '1.1.2'
__schema_version__ = '1-0-0'
25 changes: 25 additions & 0 deletions publish_release
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#! /usr/bin/env bash

python setup.py test --pyonly

if [ $? = "1" ]; then
echo "Did not pass Python tests. Exiting."
exit 1
fi

python setup.py test --jsonly

echo -n "Did the Jasmine tests pass? (y/n): "
while true; do
read character
if [ $character = "n" ] ; then
echo "Did not pass Jasmine tests. Exiting."
exit 1
fi
if [ $character = "y" ] ; then
echo "Publishing."
python setup.py sdist bdist upload
exit $?
fi
echo -n "Did the Jasmine tests pass? Must enter 'y' or 'n': "
done
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

try:
from setuptools import setup, Command
except:
from setuptools.command.sdist import sdist as SDistCommand
from setuptools.command.bdist import bdist as BDistCommand
from setuptools.command.upload import upload as UploadCommand
except ImportError:
from distutils.core import setup, Command

directory = dirname(realpath(__file__))
Expand Down
2 changes: 1 addition & 1 deletion spec/javascripts/support/jasmine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
src_files:
- escher/lib/d3.min.js
- escher/lib/escher-1.1.1.js
- escher/lib/escher-1.1.2.js
- escher/lib/jquery-2.1.0.min.js
- escher/lib/bootstrap-3.1.1.min.js

Expand Down

0 comments on commit cf08ba6

Please sign in to comment.