Commit 3469d0cc authored by Ondřej Nový's avatar Ondřej Nový

New upstream version 1.6.0

parent 105c1b8e
......@@ -22,3 +22,4 @@ Jan Balster
Grig Gheorghiu
Bob Ippolito
Christian Tismer
Wim Glenn
1.6.0 (2018-08-27)
==================
- add ``TerminalWriter.width_of_current_line`` (i18n version of
``TerminalWriter.chars_on_current_line``), a read-only property
that tracks how wide the current line is, attempting to take
into account international characters in the calculation.
1.5.4 (2018-06-27)
==================
......
Metadata-Version: 1.2
Name: py
Version: 1.5.4
Version: 1.6.0
Summary: library with cross-python path, ini-parsing, io, code, log facilities
Home-page: http://py.readthedocs.io/
Author: holger krekel, Ronny Pfannschmidt, Benjamin Peterson and others
......@@ -9,7 +9,7 @@ License: MIT license
Description: .. image:: https://img.shields.io/pypi/v/py.svg
:target: https://pypi.org/project/py
.. image:: https://anaconda.org/conda-forge/py/badges/version.svg
.. image:: https://img.shields.io/conda/vn/conda-forge/py.svg
:target: https://anaconda.org/conda-forge/py
.. image:: https://img.shields.io/pypi/pyversions/pytest.svg
......@@ -62,6 +62,7 @@ Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
.. image:: https://img.shields.io/pypi/v/py.svg
:target: https://pypi.org/project/py
.. image:: https://anaconda.org/conda-forge/py/badges/version.svg
.. image:: https://img.shields.io/conda/vn/conda-forge/py.svg
:target: https://anaconda.org/conda-forge/py
.. image:: https://img.shields.io/pypi/pyversions/pytest.svg
......
......@@ -13,14 +13,20 @@ environment:
- TOXENV: "py36-pytest29"
- TOXENV: "py36-pytest30"
- TOXENV: "py36-pytest31"
- TOXENV: "py37-pytest30"
- TOXENV: "py37-pytest31"
install:
- echo Installed Pythons
- dir c:\Python*
- C:\Python36\python -m pip install --upgrade --pre tox
- C:\Python37\python -m pip install --upgrade --pre tox
build: false # Not a C# project, build stuff at the test step instead.
test_script:
- C:\Python36\python -m tox
- C:\Python37\python -m tox
# We don't deploy anything on tags with AppVeyor, we use Travis instead, so we
# might as well save resources
skip_tags: true
import py
import timeit
class Listdir:
numiter = 100000
......@@ -70,6 +68,6 @@ if __name__ == "__main__":
for i in xrange(cls.numiter):
inst.run()
elapsed = time.time() - now
print "%s: %d loops took %.2f seconds, per call %.6f" %(
print("%s: %d loops took %.2f seconds, per call %.6f" %(
cls.__name__,
cls.numiter, elapsed, elapsed / cls.numiter)
cls.numiter, elapsed, elapsed / cls.numiter))
......@@ -8,6 +8,6 @@ doc = html.html(
html.body(
[html.p(p) for p in paras]))
print unicode(doc).encode('latin1')
print(unicode(doc).encode('latin1'))
......@@ -20,4 +20,4 @@ doc = my.html(
)
)
print doc.unicode(indent=2)
print(doc.unicode(indent=2))
......@@ -12,6 +12,6 @@ doc = ns.books(
ns.title("Java for Python programmers"),),
publisher="N.N",
)
print doc.unicode(indent=2).encode('utf8')
print(doc.unicode(indent=2).encode('utf8'))
......@@ -7,7 +7,7 @@ installation info in a nutshell
**PyPI name**: py_
**Pythons**: CPython 2.7, 3.4, 3.5, 3.6, PyPy-5.4
**Pythons**: CPython 2.7, 3.4, 3.5, 3.6, 3.7, PyPy-5.4
**Operating systems**: Linux, Windows, OSX, Unix
......
Metadata-Version: 1.2
Name: py
Version: 1.5.4
Version: 1.6.0
Summary: library with cross-python path, ini-parsing, io, code, log facilities
Home-page: http://py.readthedocs.io/
Author: holger krekel, Ronny Pfannschmidt, Benjamin Peterson and others
......@@ -9,7 +9,7 @@ License: MIT license
Description: .. image:: https://img.shields.io/pypi/v/py.svg
:target: https://pypi.org/project/py
.. image:: https://anaconda.org/conda-forge/py/badges/version.svg
.. image:: https://img.shields.io/conda/vn/conda-forge/py.svg
:target: https://anaconda.org/conda-forge/py
.. image:: https://img.shields.io/pypi/pyversions/pytest.svg
......@@ -62,6 +62,7 @@ Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
......@@ -115,6 +115,7 @@ testing/io_/__init__.py
testing/io_/test_capture.py
testing/io_/test_saferepr.py
testing/io_/test_terminalwriter.py
testing/io_/test_terminalwriter_linewidth.py
testing/log/__init__.py
testing/log/test_log.py
testing/log/test_warning.py
......
......@@ -5,7 +5,7 @@ Helper functions for writing to terminals and files.
"""
import sys, os
import sys, os, unicodedata
import py
py3k = sys.version_info[0] >= 3
from py.builtin import text, bytes
......@@ -53,6 +53,21 @@ def get_terminal_width():
terminal_width = get_terminal_width()
char_width = {
'A': 1, # "Ambiguous"
'F': 2, # Fullwidth
'H': 1, # Halfwidth
'N': 1, # Neutral
'Na': 1, # Narrow
'W': 2, # Wide
}
def get_line_width(text):
text = unicodedata.normalize('NFC', text)
return sum(char_width.get(unicodedata.east_asian_width(c), 1) for c in text)
# XXX unify with _escaped func below
def ansi_print(text, esc, file=None, newline=True, flush=False):
if file is None:
......@@ -140,6 +155,7 @@ class TerminalWriter(object):
self.hasmarkup = should_do_markup(file)
self._lastlen = 0
self._chars_on_current_line = 0
self._width_of_current_line = 0
@property
def fullwidth(self):
......@@ -164,6 +180,16 @@ class TerminalWriter(object):
"""
return self._chars_on_current_line
@property
def width_of_current_line(self):
"""Return an estimate of the width so far in the current line.
.. versionadded:: 1.6.0
:rtype: int
"""
return self._width_of_current_line
def _escaped(self, text, esc):
if esc and self.hasmarkup:
text = (''.join(['\x1b[%sm' % cod for cod in esc]) +
......@@ -223,12 +249,17 @@ class TerminalWriter(object):
markupmsg = msg
write_out(self._file, markupmsg)
def _update_chars_on_current_line(self, text):
fields = text.rsplit('\n', 1)
if '\n' in text:
self._chars_on_current_line = len(fields[-1])
def _update_chars_on_current_line(self, text_or_bytes):
newline = b'\n' if isinstance(text_or_bytes, bytes) else '\n'
current_line = text_or_bytes.rsplit(newline, 1)[-1]
if isinstance(current_line, bytes):
current_line = current_line.decode('utf-8', errors='replace')
if newline in text_or_bytes:
self._chars_on_current_line = len(current_line)
self._width_of_current_line = get_line_width(current_line)
else:
self._chars_on_current_line += len(fields[-1])
self._chars_on_current_line += len(current_line)
self._width_of_current_line += get_line_width(current_line)
def line(self, s='', **kw):
self.write(s, **kw)
......
# coding: utf-8
# file generated by setuptools_scm
# don't change, don't track in version control
version = '1.5.4'
version = '1.6.0'
......@@ -30,6 +30,7 @@ def main():
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
......
# coding: utf-8
from __future__ import unicode_literals
from py._io.terminalwriter import TerminalWriter
def test_terminal_writer_line_width_init():
tw = TerminalWriter()
assert tw.chars_on_current_line == 0
assert tw.width_of_current_line == 0
def test_terminal_writer_line_width_update():
tw = TerminalWriter()
tw.write('hello world')
assert tw.chars_on_current_line == 11
assert tw.width_of_current_line == 11
def test_terminal_writer_line_width_update_with_newline():
tw = TerminalWriter()
tw.write('hello\nworld')
assert tw.chars_on_current_line == 5
assert tw.width_of_current_line == 5
def test_terminal_writer_line_width_update_with_wide_text():
tw = TerminalWriter()
tw.write('乇乂ㄒ尺卂 ㄒ卄丨匚匚')
assert tw.chars_on_current_line == 11
assert tw.width_of_current_line == 21 # 5*2 + 1 + 5*2
def test_terminal_writer_line_width_update_with_wide_bytes():
tw = TerminalWriter()
tw.write('乇乂ㄒ尺卂 ㄒ卄丨匚匚'.encode('utf-8'))
assert tw.chars_on_current_line == 11
assert tw.width_of_current_line == 21
def test_terminal_writer_line_width_composed():
tw = TerminalWriter()
text = 'café food'
assert len(text) == 9
tw.write(text)
assert tw.chars_on_current_line == 9
assert tw.width_of_current_line == 9
def test_terminal_writer_line_width_combining():
tw = TerminalWriter()
text = 'café food'
assert len(text) == 10
tw.write(text)
assert tw.chars_on_current_line == 10
assert tw.width_of_current_line == 9
[tox]
envlist=py{27,34,35,36}-pytest{29,30,31}
# Skip py37-pytest29 as such a combination does not work (#192)
envlist=py{27,34,35,36}-pytest{29,30,31},py37-pytest{30,31}
[testenv]
changedir=testing
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment