Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Migrate to Python 3.7 (#21)
Browse files Browse the repository at this point in the history
Migrate to Python 3.7
  • Loading branch information
Holger Stitz authored Jan 2, 2020
2 parents c91574a + 041a240 commit 005df32
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 116 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
working_directory: ~/phovea
docker:
- image: caleydo/phovea_circleci_python:v3.0
- image: circleci/python:3.7-buster-node-browsers # for node version see Dockerfile on https://hub.docker.com/r/circleci/python
steps:
- checkout
- run:
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
npm run dist
- store_artifacts:
path: dist
prefix: dist
destination: dist
workflows:
version: 2
# build-nightly:
Expand Down
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _resolve_plugin(repo, version):
if os.path.isdir('.git') and repo:
if repo.endswith('.git'):
repo = repo[0:-4]
return repo + '/commit/' + _git_head('.')
return repo + '/commit/' + _git_head('.').decode('utf-8')
# not a git repo
return version

Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
-e git+https://github.com/phovea/phovea_server.git@develop#egg=phovea_server
enum==0.4.6
sklearn==0.0
sklearn==0.0
12 changes: 6 additions & 6 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
flake8==3.0.4
pep8-naming==0.4.1
pytest==3.0.3
pytest-runner==2.9
Sphinx==1.5.2
recommonmark==0.4.0
flake8==3.5.0
pep8-naming==0.5.0
pytest==3.5.0
pytest-runner==4.2
Sphinx==1.7.2
recommonmark==0.6.0
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright (c) The Caleydo Team. All rights reserved.
# Licensed under the new BSD license, available at http://caleydo.org/license
###############################################################################
from __future__ import with_statement, print_function

from setuptools import setup, find_packages
from codecs import open
from os import path
Expand All @@ -26,12 +26,12 @@ def read_it(name):
def packaged(*files):
r = {}
global pkg
r[pkg['name'].encode('ascii')] = list(files)
r[pkg['name']] = list(files)
return r


def requirements(file):
return [r.strip().encode('ascii') for r in read_it(file).strip().split('\n') if not r.startswith('-e git+https://')]
return [r.strip() for r in read_it(file).strip().split('\n') if not r.startswith('-e git+https://')]


def to_version(v):
Expand Down
7 changes: 3 additions & 4 deletions taco_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ def phovea(registry):
:param registry:
"""
# generator-phovea:begin
registry.append('namespace', 'taco', 'taco_server.api',
{
'namespace': '/api/taco'
})
registry.append('namespace', 'taco', 'taco_server.api', {
'namespace': '/api/taco'
})
# generator-phovea:end
pass

Expand Down
3 changes: 2 additions & 1 deletion taco_server/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from phovea_server import ns
import timeit
from src import diff_cache
from .src import diff_cache
import logging


Expand Down Expand Up @@ -102,6 +102,7 @@ def create():
"""
return app


if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=9000)
27 changes: 14 additions & 13 deletions taco_server/src/diff_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
# detail (as detail), middle (as count), overview (as ratios)


from __future__ import print_function
from diff_finder import Table, DiffFinder, Diff, Ratios
from .diff_finder import Table, DiffFinder, Diff, Ratios
import phovea_server.dataset as dataset
import timeit
import json
import pandas.json as ujson
from . import json_encoder
import os
import hashlib
from collections import namedtuple
Expand Down Expand Up @@ -37,6 +36,7 @@ def create_cache_dir():
else:
_log.info('use existing cache directory: ' + _cache_directory)


# run immediately!
create_cache_dir()

Expand All @@ -50,7 +50,7 @@ def get_diff_cache(filename):
file_name = _cache_directory + filename + '.json'
if os.path.isfile(file_name):
with open(file_name) as data_file:
data = ujson.load(data_file)
data = json.load(data_file)
return data
# if the file doesn't exist
return None
Expand Down Expand Up @@ -100,16 +100,17 @@ def get_diff_table(id1, id2, direction, ops, jsonit=True):

if isinstance(diffobj, Diff):
# log the detail
json_result = ujson.dumps(diffobj.serialize())
serialize = Diff.serialize # noqa E121
json_result = (json.dumps(diffobj.__dict__, cls=json_encoder.JsonEncoder))
set_diff_cache(hash_name, json_result)
else:
# todo later find a way to send the error
# e.g. there's no matching column in this case
json_result = ujson.dumps(diffobj) # which is {} for now!
json_result = json.dumps(diffobj, cls=json_encoder.JsonEncoder) # which is {} for now!
set_diff_cache(hash_name, json_result)

elif jsonit is False:
diffobj = Diff().unserialize(ujson.loads(json_result))
diffobj = Diff().unserialize(json.loads(json_result))

if jsonit:
return json_result
Expand Down Expand Up @@ -152,10 +153,10 @@ def get_ratios(id1, id2, direction, ops, bins=1, bins_col=1, jsonit=True):
# bin == 1 -> timeline bar chart
# bin == -1 -> 2d ratio plot
if bins == 1 or bins == -1:
json_ratios = ujson.dumps(ratios.serialize())
json_ratios = json.dumps(ratios.serialize(), cls=json_encoder.JsonEncoder)
# bin > 1 -> 2d ratio histogram
else:
json_ratios = ujson.dumps(ratios)
json_ratios = json.dumps(ratios, cls=json_encoder.JsonEncoder)

# cache this as overview
set_diff_cache(hashname, json_ratios)
Expand Down Expand Up @@ -198,12 +199,12 @@ def stratify_matrix(m):
if row_strat is not None:
rowids = list(m.rowids())
row_indices = [rowids.index(o) for o in row_strat.rowids()]
data = data[row_indices, ...]
data = data[row_indices, ...].astype('str')

if col_strat is not None:
colids = list(m.colids())
col_indices = [colids.index(o) for o in col_strat.rowids()]
data = data[..., col_indices]
data = data[..., col_indices].astype('str')

return Table(rows, cols, data)

Expand Down Expand Up @@ -232,12 +233,12 @@ def create_hashname(id1, id2, bins, bins_col, direction, ops):
:return:
"""
name = str(id1) + '_' + str(id2) + '_' + str(bins) + '_' + str(bins_col) + '_' + str(direction) + '_' + str(ops)
return hashlib.md5(name).hexdigest()
return hashlib.md5(name.encode('utf-8')).hexdigest()


def ratio_from_json(jsonobj):
# idk
r = json.loads(jsonobj, object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
r = json.loads(jsonobj, object_hook=lambda d: namedtuple('X', d.keys())(*list(d.values())))
# todo find a smarter way, really
cr = 0 if not hasattr(r, "c_ratio") else r.c_ratio
ar = 0 if not hasattr(r, "a_ratio") else r.a_ratio
Expand Down
Loading

0 comments on commit 005df32

Please sign in to comment.