mirror of
https://github.com/KevinMidboe/tableprint.git
synced 2026-02-14 05:19:25 +00:00
Renamed DEFAULT_STYLES to styles
This commit is contained in:
30
.travis.yml
30
.travis.yml
@@ -1,27 +1,27 @@
|
|||||||
cache: apt
|
|
||||||
sudo: false
|
|
||||||
language: python
|
language: python
|
||||||
python:
|
python:
|
||||||
- "2.7"
|
- "2.7"
|
||||||
- "3.4"
|
- "3.4"
|
||||||
- "3.5"
|
- "3.5"
|
||||||
addons:
|
install:
|
||||||
apt:
|
- sudo apt-get update
|
||||||
packages:
|
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
|
||||||
- libatlas-dev
|
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
|
||||||
- libatlas-base-dev
|
else
|
||||||
- liblapack-dev
|
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
|
||||||
- gfortran
|
fi
|
||||||
before_install:
|
|
||||||
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
|
|
||||||
- bash miniconda.sh -b -p $HOME/miniconda
|
- bash miniconda.sh -b -p $HOME/miniconda
|
||||||
- export PATH="$HOME/miniconda/bin:$PATH"
|
- export PATH="$HOME/miniconda/bin:$PATH"
|
||||||
- conda update --yes conda
|
- hash -r
|
||||||
install:
|
- conda config --set always_yes yes --set changeps1 no
|
||||||
- conda install --yes pip numpy
|
- conda update -q conda
|
||||||
|
# Useful for debugging any issues with conda
|
||||||
|
- conda info -a
|
||||||
|
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION pip numpy
|
||||||
|
- source activate test-environment
|
||||||
- travis_retry pip install -r requirements-dev.txt
|
- travis_retry pip install -r requirements-dev.txt
|
||||||
- travis_retry python setup.py install
|
- travis_retry python setup.py install
|
||||||
script:
|
script:
|
||||||
- nosetests --with-coverage --cover-package=tableprint --logging-level=INFO
|
- py.test
|
||||||
after_success:
|
after_success:
|
||||||
- coveralls
|
- coveralls
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Tableprint
|
Tableprint
|
||||||
|
|
||||||
@@ -18,13 +17,14 @@ import sys
|
|||||||
import re
|
import re
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
__all__ = ['table', 'header', 'row', 'hr', 'top', 'bottom', 'banner', 'dataframe', 'humantime']
|
__all__ = ('table', 'header', 'row', 'hr', 'top', 'bottom',
|
||||||
__version__ = '0.5.0'
|
'banner', 'dataframe', 'humantime', 'styles')
|
||||||
|
__version__ = '0.5.1'
|
||||||
|
|
||||||
# set up table styles
|
# set up table styles
|
||||||
LineStyle = namedtuple('LineStyle', ('begin', 'hline', 'sep', 'end'))
|
LineStyle = namedtuple('LineStyle', ('begin', 'hline', 'sep', 'end'))
|
||||||
TableStyle = namedtuple('TableStyle', ('top', 'below_header', 'bottom', 'row'))
|
TableStyle = namedtuple('TableStyle', ('top', 'below_header', 'bottom', 'row'))
|
||||||
DEFAULT_STYLES = {
|
styles = {
|
||||||
'grid': TableStyle(
|
'grid': TableStyle(
|
||||||
top=LineStyle('+', '-', '+', '+'),
|
top=LineStyle('+', '-', '+', '+'),
|
||||||
below_header=LineStyle('+', '-', '+', '+'),
|
below_header=LineStyle('+', '-', '+', '+'),
|
||||||
@@ -91,7 +91,7 @@ def table(data, headers=None, format_spec=FMT, width=WIDTH, style=STYLE, out=sys
|
|||||||
A file handle or object that has write() and flush() methods (Default: sys.stdout)
|
A file handle or object that has write() and flush() methods (Default: sys.stdout)
|
||||||
"""
|
"""
|
||||||
ncols = len(data[0]) if headers is None else len(headers)
|
ncols = len(data[0]) if headers is None else len(headers)
|
||||||
tablestyle = DEFAULT_STYLES[style]
|
tablestyle = styles[style]
|
||||||
|
|
||||||
# Initialize with a hr or the header
|
# Initialize with a hr or the header
|
||||||
tablestr = [hr(ncols, width, tablestyle.top)] \
|
tablestr = [hr(ncols, width, tablestyle.top)] \
|
||||||
@@ -121,14 +121,14 @@ def header(headers, width=WIDTH, style=STYLE, add_hr=True):
|
|||||||
The width of each column (Default: 11)
|
The width of each column (Default: 11)
|
||||||
|
|
||||||
style : string or tuple, optional
|
style : string or tuple, optional
|
||||||
A formatting style (see DEFAULT_STYLES)
|
A formatting style (see styles)
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
headerstr : string
|
headerstr : string
|
||||||
A string consisting of the full header row to print
|
A string consisting of the full header row to print
|
||||||
"""
|
"""
|
||||||
tablestyle = DEFAULT_STYLES[style]
|
tablestyle = styles[style]
|
||||||
|
|
||||||
# string formatter
|
# string formatter
|
||||||
data = map(lambda x: ('{:^%d}' % width).format(x), headers)
|
data = map(lambda x: ('{:^%d}' % width).format(x), headers)
|
||||||
@@ -166,7 +166,7 @@ def row(values, width=WIDTH, format_spec=FMT, style=STYLE):
|
|||||||
rowstr : string
|
rowstr : string
|
||||||
A string consisting of the full row of data to print
|
A string consisting of the full row of data to print
|
||||||
"""
|
"""
|
||||||
tablestyle = DEFAULT_STYLES[style]
|
tablestyle = styles[style]
|
||||||
|
|
||||||
assert isinstance(format_spec, string_types) | (type(format_spec) is list), \
|
assert isinstance(format_spec, string_types) | (type(format_spec) is list), \
|
||||||
"format_spec must be a string or list of strings"
|
"format_spec must be a string or list of strings"
|
||||||
@@ -196,7 +196,7 @@ def row(values, width=WIDTH, format_spec=FMT, style=STYLE):
|
|||||||
return _format_line(data, tablestyle.row)
|
return _format_line(data, tablestyle.row)
|
||||||
|
|
||||||
|
|
||||||
def hr(n, width=WIDTH, linestyle=LineStyle('|', '-', '+', '|')):
|
def hr(n, width=WIDTH, linestyle=LineStyle('', '─', '─', '')):
|
||||||
"""Returns a formatted string used as a border between table rows
|
"""Returns a formatted string used as a border between table rows
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@@ -209,7 +209,7 @@ def hr(n, width=WIDTH, linestyle=LineStyle('|', '-', '+', '|')):
|
|||||||
|
|
||||||
linestyle : tuple
|
linestyle : tuple
|
||||||
A LineStyle namedtuple containing the characters for (begin, hr, sep, end).
|
A LineStyle namedtuple containing the characters for (begin, hr, sep, end).
|
||||||
(Default: ('|', '-', '+', '|'))
|
(Default: ('', '─', '─', ''))
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
@@ -222,12 +222,12 @@ def hr(n, width=WIDTH, linestyle=LineStyle('|', '-', '+', '|')):
|
|||||||
|
|
||||||
def top(n, width=WIDTH, style=STYLE):
|
def top(n, width=WIDTH, style=STYLE):
|
||||||
"""Prints the top row of a table"""
|
"""Prints the top row of a table"""
|
||||||
return hr(n, width, linestyle=DEFAULT_STYLES[style].top)
|
return hr(n, width, linestyle=styles[style].top)
|
||||||
|
|
||||||
|
|
||||||
def bottom(n, width=WIDTH, style=STYLE):
|
def bottom(n, width=WIDTH, style=STYLE):
|
||||||
"""Prints the top row of a table"""
|
"""Prints the top row of a table"""
|
||||||
return hr(n, width, linestyle=DEFAULT_STYLES[style].bottom)
|
return hr(n, width, linestyle=styles[style].bottom)
|
||||||
|
|
||||||
|
|
||||||
def banner(message, width=30, style='banner', out=sys.stdout):
|
def banner(message, width=30, style='banner', out=sys.stdout):
|
||||||
@@ -239,7 +239,7 @@ def banner(message, width=30, style='banner', out=sys.stdout):
|
|||||||
The message to print in the banner
|
The message to print in the banner
|
||||||
|
|
||||||
width : int
|
width : int
|
||||||
The width of each column (Default: 11)
|
The minimum width of the banner (Default: 30)
|
||||||
|
|
||||||
style : string
|
style : string
|
||||||
A line formatting style (Default: 'banner')
|
A line formatting style (Default: 'banner')
|
||||||
|
|||||||
Reference in New Issue
Block a user