Skip to content
This repository was archived by the owner on Aug 4, 2022. It is now read-only.

Commit fb4542d

Browse files
author
quantmind
committed
pep8
1 parent 875dd42 commit fb4542d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+898
-726
lines changed

.coveragerc

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[run]
22
source = stdnet
3-
omit = stdnet/apps/searchengine/processors/metaphone.py,stdnet/apps/searchengine/processors/porter.py,stdnet/utils/fallbacks/*,stdnet/apps/columnts/npts.py
3+
omit =
4+
*stdnet/apps/searchengine/processors/metaphone.py
5+
*stdnet/apps/searchengine/processors/porter.py
6+
*stdnet/utils/fallbacks/*
7+
*stdnet/apps/columnts/npts.py

.travis.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ install:
1717
- sudo rm -rf pulsar
1818
- pip install -r requirements_dev.txt --use-mirrors
1919
- python setup.py install
20-
- sudo rm -rf stdnet
2120
- sudo rm -rf /dev/shm && sudo ln -s /run/shm /dev/shm
2221
script:
23-
coverage run runtests.py --concurrency thread
24-
after_success:
25-
coveralls
22+
- pep8 stdnet --exclude stdnet/apps/searchengine/processors
23+
- sudo rm -rf stdnet
24+
- python -m covrun -w 2
25+
26+
notifications:
27+
email: false
2628

2729
# Only test master and dev
2830
branches:

CHANGELOG.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ Ver. 0.9.0 - Development
66
* Added the :meth:`odm.Manager.save` as shortcut for immediately committing
77
changes to a model.
88
* Bug fix in model registration.
9-
* **504 regression tests** with **93%** coverage.
10-
9+
* **479 regression tests** with **93%** coverage.
1110

1211
Ver. 0.8.2 - 2013 July 4
1312
===============================

covrun.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sys
2+
import os
3+
4+
from runtests import run
5+
6+
7+
if __name__ == '__main__':
8+
if sys.version_info > (3, 3):
9+
run(coverage=True, show_leaks=2, coveralls=True)
10+
else:
11+
run()

requirements_dev.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
redis
2-
coveralls

runtests.py

+23-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import pulsar
1717
from pulsar.apps.test import TestSuite
1818
from pulsar.apps.test.plugins import bench, profile
19+
from pulsar.utils.path import Path
1920
#
2021
try:
2122
import dynts
@@ -28,11 +29,23 @@
2829
except ImportError:
2930
pass
3031

31-
from stdnet.utils import test
32+
33+
def run(**params):
34+
args = params.get('argv', sys.argv)
35+
if '--coverage' in args or params.get('coverage'):
36+
import coverage
37+
p = current_process()
38+
p._coverage = coverage.coverage(data_suffix=True)
39+
p._coverage.start()
40+
runtests(**params)
3241

3342

34-
def start():
35-
os.environ['stdnet_test_suite'] = 'pulsar'
43+
def runtests():
44+
import stdnet
45+
from stdnet.utils import test
46+
#
47+
strip_dirs = [Path(stdnet.__file__).parent.parent, os.getcwd()]
48+
#
3649
suite = TestSuite(description='Stdnet Asynchronous test suite',
3750
modules=('tests.all',),
3851
plugins=(test.StdnetPlugin(),
@@ -41,9 +54,13 @@ def start():
4154
)
4255
suite.bind_event('tests', test.create_tests)
4356
suite.start()
57+
#
58+
if suite.cfg.coveralls:
59+
from pulsar.utils.cov import coveralls
60+
coveralls(strip_dirs=strip_dirs,
61+
stream=suite.stream,
62+
repo_token='ZQinNe5XNbzQ44xYGTljP8R89jrQ5xTKB')
4463

4564

4665
if __name__ == '__main__':
47-
print(sys.version)
48-
print('testing with pulsar %s' % pulsar.__version__)
49-
start()
66+
run()

stdnet/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
'''Object data mapper and advanced query manager for non relational databases.'''
1+
'''Object data mapper and advanced query manager for non relational
2+
databases.
3+
'''
24
from .utils.exceptions import *
35
from .utils.version import get_version, stdnet_version
46
from .backends import *
57

68
VERSION = stdnet_version(0, 9, 0, 'alpha', 3)
79

10+
811
__version__ = version = get_version(VERSION)
912
__license__ = "BSD"
1013
__author__ = "Luca Sbardella"
1114
__contact__ = "luca.sbardella@gmail.com"
1215
__homepage__ = "https://github.com/lsbardel/python-stdnet"
13-
CLASSIFIERS = [
14-
'Development Status :: 4 - Beta',
16+
CLASSIFIERS = ['Development Status :: 4 - Beta',
1517
'Environment :: Plugins',
1618
'Environment :: Console',
1719
'Environment :: Web Environment',

stdnet/apps/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'''\
22
Collection of applications which may be relevant or not to the user.
33
They show off the main features of the core library.
4-
'''
4+
'''

stdnet/apps/columnts/__init__.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,40 @@
44
An application which implements a specialised remote
55
:class:`stdnet.odm.Structure` for managing numeric multivariate
66
timeseries_ and perform remote analysis on them. The main classes
7-
for this application are :class:`ColumnTS`, the stand alone data structure, and
8-
the correspondent :class:`ColumnTSField` which can be used as
7+
for this application are :class:`ColumnTS`, the stand alone data structure,
8+
and the correspondent :class:`ColumnTSField` which can be used as
99
a :class:`stdnet.odm.StructureField` on a :class:`stdnet.odm.StdModel`.
1010
11-
11+
1212
The API is straightforward::
1313
1414
from datetime import date
1515
from stdnet.apps.columnts import ColumnTS
16-
16+
1717
ts = ColumnTS(id='test')
1818
ts.add(date(2012,2,21), {'open': 603.87, 'close': 614.00})
19-
19+
2020
It can also be used as a :ref:`datastructure fields <model-field-structure>`.
2121
For example::
2222
2323
from stdnet import odm
2424
from stdnet.apps.columnts import ColumnTSField
25-
25+
2626
class Ticker(odm.StdModel):
2727
code = odm.SymbolField()
2828
data = ColumnTSField()
29-
30-
29+
30+
3131
Statistical Analysis
3232
=================================
3333
3434
istats & stats
3535
~~~~~~~~~~~~~~~~~
3636
3737
These two methods execute statistical analysis on the data stored in one
38-
:class:`ColumnTS`. The :class:`ColumnTS.istats` method performs analysis by selecting
39-
time range by rank, while :class:`ColumnTS.stats` method performs analysis
40-
by selecting ranges by a *start* and an *end* date (or datetime).
38+
:class:`ColumnTS`. The :class:`ColumnTS.istats` method performs analysis by
39+
selecting time range by rank, while :class:`ColumnTS.stats` method performs
40+
analysis by selecting ranges by a *start* and an *end* date (or datetime).
4141
4242
multi
4343
~~~~~~~
@@ -48,9 +48,9 @@ class Ticker(odm.StdModel):
4848
To perform analysis you write lua scripts::
4949
5050
self:range()
51-
51+
5252
ts.evaluate(script)
53-
53+
5454
API
5555
======
5656
@@ -60,7 +60,7 @@ class Ticker(odm.StdModel):
6060
.. autoclass:: ColumnTS
6161
:members:
6262
:member-order: bysource
63-
63+
6464
6565
ColumnTSField
6666
~~~~~~~~~~~~~~
@@ -83,15 +83,15 @@ class Ticker(odm.StdModel):
8383
This composite data-structure looks and feels like a redis zset.
8484
However, the ordered set doesn't actually store the data, it is there to
8585
maintain order and facilitate retrieval by times (scores) and rank.
86-
86+
8787
For a given *field*, the data is stored in a sequence of 9-bytes string
8888
with the initial byte (``byte0``) indicating the type of data::
8989
90-
90+
9191
<byte0><byte1,...,byte8>
92-
93-
92+
93+
9494
.. _timeseries: http://en.wikipedia.org/wiki/Time_series
9595
'''
9696
from . import redis
97-
from .models import *
97+
from .models import *

stdnet/apps/columnts/models.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
class TimeseriesCache(object):
1212
cache = None
13+
1314
def __init__(self):
1415
self.merged_series = None
1516
self.fields = {}
@@ -19,7 +20,7 @@ def __init__(self):
1920
def add(self, timestamp, field, value):
2021
if field not in self.fields:
2122
self.fields[field] = skiplist()
22-
self.fields[field].insert(timestamp,value)
23+
self.fields[field].insert(timestamp, value)
2324

2425
def clear(self):
2526
self.merged_series = None
@@ -36,9 +37,9 @@ def as_dict(times, fields):
3637
names.append(name)
3738
lists.append(value)
3839
for dt, data in zip(times, zip(*lists)):
39-
d[dt] = dict(zip(names,data))
40+
d[dt] = dict(zip(names, data))
4041
return d
41-
42+
4243

4344
class ColumnTS(odm.TS):
4445
'''A specialised :class:`stdnet.odm.TS` structure for numeric
@@ -51,15 +52,15 @@ class ColumnTS(odm.TS):
5152

5253
def front(self, *fields):
5354
'''Return the front pair of the structure'''
54-
v,f = tuple(self.irange(0, 0, fields=fields))
55+
v, f = tuple(self.irange(0, 0, fields=fields))
5556
if v:
56-
return (v[0],dict(((field, f[field][0]) for field in f)))
57+
return (v[0], dict(((field, f[field][0]) for field in f)))
5758

5859
def back(self, *fields):
5960
'''Return the back pair of the structure'''
60-
v,f = tuple(self.irange(-1, -1, fields=fields))
61+
v, f = tuple(self.irange(-1, -1, fields=fields))
6162
if v:
62-
return (v[0],dict(((field, f[field][0]) for field in f)))
63+
return (v[0], dict(((field, f[field][0]) for field in f)))
6364

6465
def info(self, start=None, end=None, fields=None):
6566
'''Provide data information for this :class:`ColumnTS`. If no
@@ -111,7 +112,7 @@ def istats(self, start=0, end=-1, fields=None):
111112

112113
def stats(self, start, end, fields=None):
113114
'''Perform a multivariate statistic calculation of this
114-
:class:`ColumnTS` from a *start* date/datetime to an
115+
:class:`ColumnTS` from a *start* date/datetime to an
115116
*end* date/datetime.
116117
117118
:param start: Start date for analysis.
@@ -158,8 +159,8 @@ def multi_stats(self, start, end, series=None, fields=None, stats=None):
158159
stats = stats or self.default_multi_stats
159160
start = self.pickler.dumps(start)
160161
end = self.pickler.dumps(end)
161-
res = self.backend_structure().multi_stats(
162-
start, end, fields, series, stats)
162+
res = self.backend_structure().multi_stats(start, end, fields,
163+
series, stats)
163164
return on_result(res, self._stats)
164165

165166
def merge(self, *series, **kwargs):
@@ -219,7 +220,7 @@ def check_router(cls, router, *series):
219220
def _merge(self, *series, **kwargs):
220221
fields = kwargs.get('fields') or ()
221222
self.backend_structure().merge(series, fields)
222-
223+
223224
def load_data(self, result):
224225
#Overwrite :meth:`stdnet.odm.PairMixin.load_data` method
225226
loads = self.pickler.loads
@@ -262,6 +263,6 @@ def _add(self, dt, *args):
262263
class ColumnTSField(odm.StructureField):
263264
'''A multivariate timeseries field.'''
264265
type = 'columnts'
266+
265267
def structure_class(self):
266268
return ColumnTS
267-

stdnet/apps/columnts/npts.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class ColumnTS(columnts.ColumnTS):
1818

1919
def front(self, *fields):
2020
'''Return the front pair of the structure'''
21-
ts = self.irange(0, 0, fields = fields)
21+
ts = self.irange(0, 0, fields=fields)
2222
if ts:
23-
return ts.start(),ts[0]
23+
return ts.start(), ts[0]
2424

2525
def back(self, *fields):
2626
'''Return the back pair of the structure'''
27-
ts = self.irange(-1, -1, fields = fields)
27+
ts = self.irange(-1, -1, fields=fields)
2828
if ts:
29-
return ts.end(),ts[0]
29+
return ts.end(), ts[0]
3030

3131
def load_data(self, result):
3232
loads = self.pickler.loads

0 commit comments

Comments
 (0)