Skip to content

Commit

Permalink
Release 0.2.0 (#48)
Browse files Browse the repository at this point in the history
Change Log
==========
- Deprecate Python 2.7 (This is dead)
- Deprecate Python 3.4 (No longer supported by colorama)
- Add test support for Python 3.8
- Rework of columnify with tests
- Start using [HTML Color Names](https://www.w3schools.com/colors/colors_names.asp)
- Add support for hex codes for color definitions
- Some refactoring of modules/files
- Reduce API footprint (only export a small number of useful functions)
- Minor documentation updates
  • Loading branch information
mrz1988 committed Feb 21, 2021
1 parent c2449e9 commit 7359ced
Show file tree
Hide file tree
Showing 41 changed files with 733 additions and 776 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ exclude_lines =
ignore_errors = True
omit =
test/*
lilies/base.py
lilies/objects/base.py
lilies/__main__.py
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
ignore = E203, E741, W503
max-line-length = 79
max-complexity = 18
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ lilies.egg-info/*
MANIFEST
.python-version
.coverage
dist/*
34 changes: 15 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
sudo: false
language: python
cache: pip
python:
- 3.5
- 3.6
- 3.7
- 3.8

matrix:
include:
- python: 2.7
env: TOXENV=py27
- python: 3.4
env: TOXENV=py34
- python: 3.5
env: TOXENV=py35
- python: 3.6
env: TOXENV=py36
- python: 3.7
env: TOXENV=py37,codecov
dist: xenial # required for Python 3.7 (travis-ci/travis-ci#9069)
sudo: required # required for Python 3.7 (travis-ci/travis-ci#9069)
before_install:
- python --version
- pip install -U pip

install:
- pip install -r requirements-test.txt

before_script:
# Run flake8 tests only on Python 2.7 and 3.7...
# Run flake8 tests only on Python 3.7...
# 1) stop the build if there are Python syntax errors or undefined names
# 2) exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
- if [[ $TRAVIS_PYTHON_VERSION == *.7 ]]; then
flake8 --config tox.ini lilies;
- if [[ $TRAVIS_PYTHON_VERSION == 3.7 ]]; then
flake8 ./lilies;
fi

script:
- tox
- pytest -v --cov=lilies

after_success:
- codecov # submit coverage
58 changes: 29 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# Lilies

[![Build Status](https://travis-ci.org/mrz1988/lilies.svg?branch=master)](https://travis-ci.org/mrz1988/lilies)
[![Code Coverage](https://codecov.io/gh/mrz1988/lilies/branch/master/graphs/badge.svg)](https://codecov.io/gh/mrz1988/lilies/branch/master)

Lilies is currently in alpha. Parts of the API are highly subject to change. A fresh README is in the works.

Lilies is a cross-platform, colored CLI text-formatting tool for python. It provides lots of text coloring and formatting tools, bridged across almost any console. This includes older Windows support powered by popular coloring library [colorama](https://pypi.org/project/colorama/). Lilies will attempt to reproduce the original colors as close as possible, regardless of the current terminal's capabilities.

Lilies is supported on python 2.7, 3.4, 3.5, 3.6, and 3.7. It probably works in some other releases, too. No promises.

![Sup, world?](https://raw.githubusercontent.com/mrz1988/lilies/master/screenshots/screenshot01.png)

## Why not use alternatives?
There are [many options](https://stackoverflow.com/questions/287871/how-to-print-colored-text-in-terminal-in-python) to help you build colored text in terminal output. Many developers prefer to directly add their own ANSI sequences. Since this isn't great for complex things, [termcolor](https://pypi.org/project/termcolor/) provides a convenient abstraction. However, termcolor does not work on windows, and doesn't respect compatibility of other terminals. Formatting text once it has already been colored is also hard, since the `len()` function will include ANSI characters.

Lilies provides more powerful string tools, 2D text manipulation, and comfort that your coloring will respect the wishes of others' terminals.

## Getting started
Install us via [pip](https://pypi.org/project/lilies/)!
```
pip install lilies
```

## Contributing
You can find information about contributing [here](https://github.com/mrz1988/lilies/blob/master/docs/contributing.rst)

## License
[MIT](https://github.com/mrz1988/lilies/blob/master/LICENSE)
# Lilies

[![Build Status](https://travis-ci.org/mrz1988/lilies.svg?branch=master)](https://travis-ci.org/mrz1988/lilies)
[![Code Coverage](https://codecov.io/gh/mrz1988/lilies/branch/master/graphs/badge.svg)](https://codecov.io/gh/mrz1988/lilies/branch/master)

Lilies is currently in alpha. Parts of the API are highly subject to change. A fresh README is in the works.

Lilies is a cross-platform, colored CLI text-formatting tool for python. It provides lots of text coloring and formatting tools, bridged across almost any console. This includes older Windows support powered by popular coloring library [colorama](https://pypi.org/project/colorama/). Lilies will attempt to reproduce the original colors as close as possible, regardless of the current terminal's capabilities.

Lilies is supported on python 3.5, 3.6, 3.7, and 3.8.

![Sup, world?](https://raw.githubusercontent.com/mrz1988/lilies/master/screenshots/screenshot01.png)

## Why not use alternatives?
There are [many options](https://stackoverflow.com/questions/287871/how-to-print-colored-text-in-terminal-in-python) to help you build colored text in terminal output. Many developers prefer to directly add their own ANSI sequences. Since this isn't great for complex things, [termcolor](https://pypi.org/project/termcolor/) provides a convenient abstraction. However, termcolor does not work on windows, and doesn't respect compatibility of other terminals. Formatting text once it has already been colored is also hard, since the `len()` function will include ANSI characters.

Lilies provides more powerful string tools, 2D text manipulation, and comfort that your coloring will respect the wishes of others' terminals.

## Getting started
Install us via [pip](https://pypi.org/project/lilies/)!
```
pip install lilies
```

## Contributing
You can find information about contributing [here](https://github.com/mrz1988/lilies/blob/master/docs/contributing.rst)

## License
[MIT](https://github.com/mrz1988/lilies/blob/master/LICENSE)
5 changes: 0 additions & 5 deletions bootkill-macos.sh

This file was deleted.

11 changes: 0 additions & 11 deletions bootstrap-macos.sh

This file was deleted.

29 changes: 3 additions & 26 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,19 @@ In your pull request description, please describe what you did, why it's useful
Development setup (MacOS)
*************************

If you are using a modern installation of MacOS, good news, this should be fairly easy for you:
Dev setup requires an installation of python 3.5+, and pip. Depending on your local setup:

.. code-block:: bash
$ git clone https://github.com/mrz1988/lilies.git
$ cd lilies
$ sh bootstrap-macos.sh
This will take quite a while, so it might be good to go grab a coffee. It installs several virtualenv python versions, and configures the lilies directory to prefer execution on python-3.7. This will not pollute any of your other python installs. It then installs all dev testing prerequisites, and runs lilies tests on all related environments.

If for whatever reason, you need to tear it down again:

.. code-block:: bash
$ sh bootkill-macos.sh
**Note:** It's important to run the shell scripts from the lilies root directory, or you may have issues. If you messed this up, you might be able to fix it by going back to the root directory and running the kill script, before re-running the bootstrap script.
$ pip install -r requirements-dev.txt
***************************
About the dev environment
***************************

Lilies development uses `tox <https://github.com/tox-dev/tox>`_ to run unit tests on numerous python environments via `pyenv <https://github.com/pyenv/pyenv>`_. If you are not running on MacOS, you will need to follow the breadcrumbs yourself. Some important tools that can help you:

`pyenv-win <https://github.com/pyenv-win/pyenv-win>`_ for Windows development
`pyenv-installer <https://github.com/pyenv/pyenv-installer>`_ to help install in other Unix-like environments
`tox-pyenv <https://pypi.org/project/tox-pyenv/>`_ will bridge tox to your pyenv setups
Lilies development uses `tox <https://github.com/tox-dev/tox>`_ to run unit tests on numerous python environments.

*****************
Running the tests
Expand Down Expand Up @@ -79,12 +65,3 @@ This should also allow you to do things like run a partial set of tests via ``-k

.. code-block:: bash
$ pytest -k <partial_test_name>
**Via lilies itself:**
Failing all other things, lilies is set up to run its tests from wherever it is installed. This is great for checking pre-installed lilies libraries for functionality:

.. code-block:: bash
$ python -m lilies -t
The above command will run all tests for lilies. You can also play around with ``--help`` to see other ways to execute the tests from the command line in this way.
15 changes: 3 additions & 12 deletions lilies/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from .grow import grow
from .cli_utils import columnify, sortify, bordered
from .base_utils import isstringish, islilyblock, wilt
from .api import columnify, bordered, grow, sortify
from .base_utils import wilt
from .manage import lilies_init
from .lilystring import LilyString
from .lilyblock import LilyBlock, block
from . import compiler

__version__ = "0.1.5"
__version__ = "0.2.0"

version = VERSION = __version__

Expand All @@ -22,14 +19,8 @@ def print_test():
# helpers
"grow",
"wilt",
"block",
"isstringish",
"islilyblock",
# layouts
"columnify",
"sortify",
"bordered",
# classes
"LilyString",
"LilyBlock",
]
4 changes: 1 addition & 3 deletions lilies/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##########################################################################
# Lilies
# By: Matt Zychowski (copyright 2014-2019)
# By: Matt Zychowski (copyright 2014-2021)
#
# A library wrapped around colorama for using colored strings in the terminal
# window. Provides advanced manipulation of colored strings, including
Expand All @@ -10,7 +10,6 @@

from __future__ import print_function
from builtins import str
from builtins import input
from . import grow, __version__


Expand All @@ -23,4 +22,3 @@
print()
print("=" * 50)
print()
input("Press [ENTER] to run tests.")
6 changes: 6 additions & 0 deletions lilies/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .borders import bordered
from .columnify import columnify
from .grow import grow
from .sortify import sortify

__all__ = ["bordered", "columnify", "grow", "sortify"]
27 changes: 27 additions & 0 deletions lilies/borders.py → lilies/api/borders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from builtins import map

from .grow import grow
from ..objects.lilyblock import block


NONE = 0
Expand Down Expand Up @@ -58,3 +62,26 @@ def _frombounds(bounds):
def border_char(vectors, style="thin"):
style_int = STYLE_MAP[style]
return _frombounds(_getbounds(vectors, style_int))


def bordered(s, bordercolor="", borderstyle="thin"):
blc = block(s)
horiz_char = border_char("lr", borderstyle)
horiz = horiz_char * blc.width()
horiz = grow(horiz, bordercolor)
top = block(horiz)
partial = top.append(blc).append(horiz)
top_left = _brderchar("br", bordercolor, borderstyle)
top_right = _brderchar("bl", bordercolor, borderstyle)
bot_left = _brderchar("tr", bordercolor, borderstyle)
bot_right = _brderchar("tl", bordercolor, borderstyle)
vert = _brderchar("tb", bordercolor, borderstyle)
vert = [vert] * blc.height()
l_vert = block([top_left] + vert + [bot_left])
r_vert = block([top_right] + vert + [bot_right])
return l_vert + partial + r_vert


def _brderchar(vector, color, style):
ch = border_char(vector, style)
return grow(ch, color)
105 changes: 105 additions & 0 deletions lilies/api/columnify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from .grow import grow
from .sortify import sortify
from ..objects.lilyblock import block


class ColumnBuilder:
def __init__(
self, column_count=0, total_width=80, justify="left", min_spacing=3
):
self.column_count = column_count
self.total_width = total_width
self.justify = justify
self.min_spacing = min_spacing

def make_columns(self, iterable, sort=True, horizontal=False):
if not iterable:
return block("")

iterable = [grow(item) for item in iterable]
column_count = self._get_column_count(iterable)
entries_per_column, remainder = divmod(len(iterable), column_count)
if remainder > 0:
entries_per_column += 1

if sort:
iterable = sortify(iterable)
iterable = self._resize_all(iterable, column_count)

if horizontal:
rows = self._make_rows_horizontally(
iterable, column_count, entries_per_column
)
else:
rows = self._make_rows_vertically(
iterable, column_count, entries_per_column
)

return self._merge_rows_to_lilyblock(rows)

def _make_rows_horizontally(
self, iterable, column_count, entries_per_column
):
rows = []
for i in range(entries_per_column):
start = column_count * i
stop = start + column_count
rows.append(iterable[start:stop])
return rows

def _make_rows_vertically(
self, iterable, column_count, entries_per_column
):
rows = []
for i in range(entries_per_column):
rows.append(iterable[i::entries_per_column])
return rows

def _get_column_count(self, iterable):
if self.column_count != 0:
return self.column_count

longest_item_size = max([len(item) for item in iterable])
columns = self.total_width // (longest_item_size + self.min_spacing)

# If we have fewer items than columns, we aren't going to
# fill all of the columns.
if len(iterable) < columns:
columns = len(iterable)
if columns == 0:
return 1
return columns

def _resize_all(self, iterable, column_count):
total_spacing = self.min_spacing * (column_count - 1)
usable_width = self.total_width - total_spacing
max_cell_size = usable_width // column_count
max_item_size = max([len(item) for item in iterable])
item_size = min([max_cell_size, max_item_size])
return [
s.resize(item_size, self.justify, add_elipsis=True, fillchar=" ")
for s in iterable
]

def _merge_rows_to_lilyblock(self, rows):
space = grow(" " * self.min_spacing)
rows = [space.join(row) for row in rows]
return block(rows)


def columnify(
iterable,
columns=0,
width=80,
justify="left",
sort=True,
min_spacing=3,
horizontal=False,
):
builder = ColumnBuilder(
column_count=columns,
total_width=width,
justify=justify,
min_spacing=min_spacing,
)
return builder.make_columns(iterable, sort=sort, horizontal=horizontal)

0 comments on commit 7359ced

Please sign in to comment.