Skip to content

Commit

Permalink
Drop python 2.7 support (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
tammoippen authored Dec 1, 2022
1 parent 8bb6e0e commit 2d91a7b
Show file tree
Hide file tree
Showing 19 changed files with 898 additions and 192 deletions.
34 changes: 16 additions & 18 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['pypy-2.7', 2.7, 3.6, 'pypy-3.7', 3.7, 'pypy-3.8', 3.8, 3.9] #, '3.10']
python-version: [3.7, 'pypy-3.8', 3.8, 'pypy-3.9', 3.9, '3.10', '3.11']
include:
- os: ubuntu-latest
path: ~/.cache/pip
Expand All @@ -23,34 +23,33 @@ jobs:
- os: windows-latest
path: ~\AppData\Local\pip\Cache
exclude:
- os: macos-latest
python-version: 'pypy-2.7'
- os: macos-latest
python-version: 'pypy-3.7'
- os: macos-latest
python-version: 'pypy-3.8'
- os: windows-latest
python-version: 'pypy-2.7'
- os: windows-latest
python-version: 'pypy-3.7'
- os: macos-latest
python-version: 'pypy-3.9'
- os: windows-latest
python-version: 'pypy-3.8'
- os: windows-latest
python-version: 'pypy-3.9'
defaults:
run:
shell: bash

runs-on: ${{ matrix.os }}
env:
PYTHONIOENCODING: UTF-8
steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set Up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache Install
id: restore-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
${{ matrix.path }}
Expand All @@ -60,21 +59,20 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.1.12
version: 1.2.2
virtualenvs-create: false
- run: poetry config experimental.new-installer false

- name: Install
run: make install
run: poetry install

- name: Style
if: ${{ ! startsWith(matrix.python-version, 'pypy-') }}
run: make style
run: poetry run flake8 tests/ plotille/ examples/

- name: Tests
run: make tests
run: poetry run pytest -s -vvv

- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3
with:
flags: unittests
name: coverage-${{ matrix.os }}-${{ matrix.python-version }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/Publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set Up Python 3.7
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.7

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.1.12
version: 1.2.2

- name: Build
run: poetry build -vvv -f sdist

- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ __pycache__/
dist/
README.rst
.pytest_cache/
poetry.lock
Pipfile.lock
cov_html/
coverage.xml
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: style tests
.PHONY: style tests install

style:
poetry run flake8 tests/ plotille/ examples/
Expand All @@ -8,4 +8,3 @@ tests:

install:
poetry install
poetry run pip install -r tests/requirements.txt
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
[![CI](https://github.com/tammoippen/plotille/actions/workflows/CI.yml/badge.svg)](https://github.com/tammoippen/plotille/actions/workflows/CI.yml)
[![codecov](https://codecov.io/gh/tammoippen/plotille/branch/master/graph/badge.svg?token=OGWI832JNM)](https://codecov.io/gh/tammoippen/plotille)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/tammoippen/plotille.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/tammoippen/plotille/context:python)
[![Tested CPython Versions](https://img.shields.io/badge/cpython-2.7%2C%203.6%2C%203.7%2C%203.8%2C%203.9-brightgreen.svg)](https://img.shields.io/badge/cpython-2.7%2C%203.6%2C%203.7%2C%203.8%2C%203.8-brightgreen.svg)
[![Tested PyPy Versions](https://img.shields.io/badge/pypy-2.7--7.3%2C%203.7--7.3%2C%203.8--7.3-brightgreen.svg)](https://img.shields.io/badge/pypy-2.7--7.3%2C%203.7--7.3%2C%203.8--7.3-brightgreen.svg)
[![Tested CPython Versions](https://img.shields.io/badge/cpython-3.7%2C%203.8%2C%203.9%2C%203.10%2C%203.11-brightgreen.svg)](https://img.shields.io/badge/cpython-3.7%2C%203.8%2C%203.9%2C%203.10%2C%203.11-brightgreen.svg)
[![Tested PyPy Versions](https://img.shields.io/badge/pypy-3.8%2C%203.9-brightgreen.svg)](https://img.shields.io/badge/pypy-3.8%2C%203.9-brightgreen.svg)
[![PyPi version](https://img.shields.io/pypi/v/plotille.svg)](https://pypi.python.org/pypi/plotille)
[![Downloads](https://pepy.tech/badge/plotille/month)](https://pepy.tech/project/plotille)
[![PyPi license](https://img.shields.io/pypi/l/plotille.svg)](https://pypi.python.org/pypi/plotille)

Plots, scatter plots, histograms and heatmaps in the terminal using braille dots, and foreground and background colors - with (almost) no dependancies. Make complex figures using the Figure class or make fast and simple plots using graphing function - similar to a very small sibling to matplotlib. Or use the canvas to plot dots, lines and images yourself.
Plots, scatter plots, histograms and heatmaps in the terminal using braille dots, and foreground and background colors - with no dependancies. Make complex figures using the Figure class or make fast and simple plots using graphing function - similar to a very small sibling to matplotlib. Or use the canvas to plot dots, lines and images yourself.

Install:

Expand All @@ -30,6 +30,8 @@ Basic support for timeseries plotting is provided with release 3.2: for any `X`

Support for heatmaps using background colors for figures and displaying images binary with braille, or in color with background colors using the canvas - provided with release 4.0

If you are still using python 2.7, please use plotille v4 or before. With v5 I am dropping support for python 2.7, as the effort to maintain the discontinued version is too much.

## Documentation

```python
Expand Down
4 changes: 1 addition & 3 deletions plotille/_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

import os

import six

from ._colors import rgb2byte
from ._dots import Dots
from ._util import roundeven
Expand Down Expand Up @@ -374,5 +372,5 @@ def plot(self, linesep=os.linesep):
unicode: The canvas as a string.
"""

return linesep.join(''.join(map(six.text_type, row))
return linesep.join(''.join(map(str, row))
for row in reversed(self._canvas))
16 changes: 7 additions & 9 deletions plotille/_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import os
import sys

import six


def color(text, fg=None, bg=None, mode='names', no_color=False, full_reset=True): # noqa: C901 complex (12)
"""Surround `text` with control characters for coloring
Expand Down Expand Up @@ -109,9 +107,9 @@ def color(text, fg=None, bg=None, mode='names', no_color=False, full_reset=True)
elif mode == 'byte':
start = _byte(fg, bg)
elif mode == 'rgb':
if isinstance(fg, six.string_types):
if isinstance(fg, str):
fg = _hex2rgb(fg)
if isinstance(bg, six.string_types):
if isinstance(bg, str):
bg = _hex2rgb(bg)

start = _rgb(fg, bg)
Expand Down Expand Up @@ -215,17 +213,17 @@ def _byte(fg, bg):

fg_ = ''
if fg is not None:
fg_ = '38;5;' + six.text_type(fg)
fg_ = '38;5;' + str(fg)
bg_ = ''
if bg is not None:
bg_ = '48;5;' + six.text_type(bg)
bg_ = '48;5;' + str(bg)

return _join_codes(fg_, bg_)


def _hex2rgb(h):
"""Transform rgb hex representation into rgb tuple of ints representation"""
assert isinstance(h, six.string_types)
assert isinstance(h, str)
if h.lower().startswith('0x'):
h = h[2:]
if len(h) == 3:
Expand All @@ -248,10 +246,10 @@ def _rgb(fg, bg):

fg_ = ''
if fg is not None:
fg_ = '38;2;' + ';'.join(map(six.text_type, fg))
fg_ = '38;2;' + ';'.join(map(str, fg))
bg_ = ''
if bg is not None:
bg_ = '48;2;' + ';'.join(map(six.text_type, bg))
bg_ = '48;2;' + ';'.join(map(str, bg))

return _join_codes(fg_, bg_)

Expand Down
10 changes: 4 additions & 6 deletions plotille/_dots.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import six

from ._colors import color

# I plot upside down, hence the different order
Expand Down Expand Up @@ -99,7 +97,7 @@ def marker(self):

@marker.setter
def marker(self, value):
assert value is None or isinstance(value, six.string_types)
assert value is None or isinstance(value, str)
assert value is None or len(value) == 1
self._marker = value

Expand All @@ -113,7 +111,7 @@ def __str__(self):
if self.marker:
res = self.marker
else:
res = six.unichr(0x2800 + self._dots)
res = chr(0x2800 + self._dots)

return color(res, fg=self.fg, bg=self.bg, **self.color_kwargs)

Expand Down Expand Up @@ -161,7 +159,7 @@ def braille_from(dots):

code = 0x2800 + int(''.join(bin_code), 2)

return six.unichr(code)
return chr(code)


def dots_from(braille):
Expand All @@ -178,7 +176,7 @@ def dots_from(braille):
"""
assert 0x2800 <= ord(braille) <= 0x28ff

code = six.text_type(bin(ord(braille) - 0x2800))[2:].rjust(8, '0')
code = str(bin(ord(braille) - 0x2800))[2:].rjust(8, '0')

dots = []
for i, c in enumerate(code):
Expand Down
2 changes: 0 additions & 2 deletions plotille/_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
from itertools import cycle
import os

from six.moves import zip

from ._canvas import Canvas
from ._colors import color, rgb2byte
from ._figure_data import Heat, Histogram, Plot, Span, Text
Expand Down
7 changes: 2 additions & 5 deletions plotille/_figure_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import six
from six.moves import zip

from . import _cmaps
from ._util import hist

Expand Down Expand Up @@ -186,15 +183,15 @@ def __init__(self, X, cmap=None):
for RGB data.
"""
assert len(X)
assert cmap is None or isinstance(cmap, six.string_types) or isinstance(cmap, _cmaps.Colormap)
assert cmap is None or isinstance(cmap, (str, _cmaps.Colormap))
len_first = len(X[0])
assert all(len(x) == len_first for x in X)
self._X = X

if cmap is None:
cmap = 'viridis'

if isinstance(cmap, six.string_types):
if isinstance(cmap, str):
cmap = _cmaps.cmaps[cmap]()
self.cmap = cmap

Expand Down
18 changes: 7 additions & 11 deletions plotille/_input_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
from datetime import date, datetime, time, timedelta
import math

import six

from ._util import roundeven, timestamp


Expand All @@ -37,18 +35,16 @@ def __init__(self):
self.formatters = OrderedDict()

self.formatters[float] = _num_formatter
for int_type in six.integer_types:
self.formatters[int_type] = _num_formatter
self.formatters[int] = _num_formatter

self.formatters[date] = _date_formatter
self.formatters[datetime] = _datetime_formatter

self.formatters[six.text_type] = _text_formatter
self.formatters[str] = _text_formatter

self.converters = OrderedDict()
self.converters[float] = _convert_numbers
for int_type in six.integer_types:
self.converters[int_type] = _convert_numbers
self.converters[int] = _convert_numbers

self.converters[date] = _convert_date
self.converters[datetime] = _convert_datetime
Expand Down Expand Up @@ -132,13 +128,13 @@ def _datetime_formatter(val, chars, delta, left=False):


def _num_formatter(val, chars, delta, left=False):
if not (isinstance(val, six.integer_types) or isinstance(val, float)):
if not isinstance(val, (int, float)):
raise ValueError('Only accepting numeric (int/long/float) types, not "{}" of type: {}'.format(val, type(val)))

if abs(val - roundeven(val)) < 1e-8: # about float (f32) machine precision
val = int(roundeven(val))

if isinstance(val, six.integer_types):
if isinstance(val, int):
return _int_formatter(val, chars, left)
elif isinstance(val, float):
return _float_formatter(val, chars, left)
Expand Down Expand Up @@ -174,7 +170,7 @@ def _float_formatter(val, chars, left=False):


def _int_formatter(val, chars, left=False):
assert isinstance(val, six.integer_types)
assert isinstance(val, int)
if val != 0:
sign = 1 if val < 0 else 0
digits = math.ceil(math.log10(abs(val)))
Expand Down Expand Up @@ -204,7 +200,7 @@ def _text_formatter(val, chars, delta, left=False):


def _convert_numbers(v):
assert isinstance(v, float) or isinstance(v, six.integer_types)
assert isinstance(v, float) or isinstance(v, int)
return float(v)


Expand Down
8 changes: 1 addition & 7 deletions plotille/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
def roundeven(x):
"""Round to next even integer number in case of `X.5`
In Python3 this is the same as `round(x, 0)`, but since Python2 rounds up
in that case and I want consistent behaviour, here is the roundeven function.
Parameters:
x: float The number to round.
Expand All @@ -44,10 +41,7 @@ def roundeven(x):
"""
if math.isinf(x) or math.isnan(x):
return x # same behaviour as in python2
x_r = round(x)
if abs(x_r - x) == 0.5:
return int(2.0 * round(x / 2))
return x_r
return round(x)


def _numpy_to_native(x):
Expand Down
Loading

0 comments on commit 2d91a7b

Please sign in to comment.