Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Nov 16, 2024
1 parent 2b0b1d7 commit 6d00278
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion clean
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rm -f .mylog tests/.mylog
# the rest is common to all python directories
rm -f *.pyc *.pyo .test*.sum expected result install.out
rm -rf build *.egg-info dist __pycache__ .coverage .coverage-html htmlcov .eggs
rm -f .*.log
rm -f .*.log .mypy_cache
rm -rf .eggs .pytest_cache .cache dist .build inform.egg.info
rm -rf **/{__pycache__,*.pyc,*.pyo}
rm -rf tests/{htmlcov,.cache,.coverage,.pytest_cache}
Expand Down
8 changes: 4 additions & 4 deletions doc/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end of the line.

To get the prerequisites for this example, run::

> pip3 install --user --upgrade docopt inform shlib
> pip3 install --upgrade docopt inform shlib

.. code-block:: python
Expand Down Expand Up @@ -132,7 +132,7 @@ a subclass of *Error*.

To get the prerequisites for this example, run::

> pip3 install --user --upgrade avendesora docopt inform pathlib pexpect
> pip3 install --upgrade avendesora docopt inform pathlib pexpect

You will also have to update the *SSHkeys* variable below and add the requisite
alias and keyfile attributes to the Avendesora accounts that contain your SSH
Expand Down Expand Up @@ -224,7 +224,7 @@ end of the line.

To get the prerequisites for this example, run::

> pip3 install --user --upgrade docopt inform quantiphy arrow requests
> pip3 install --upgrade docopt inform quantiphy arrow requests

You will also have to tailor the values of the *system*, *api_key* and *user_id*
variables to your account.
Expand Down Expand Up @@ -403,7 +403,7 @@ liabilities that together make up ones networth.

To get the prerequisites for this example, run::

> pip3 install --user --upgrade docopt inform quantiphy arrow requests appdirs
> pip3 install --upgrade docopt inform quantiphy arrow requests appdirs

.. code-block:: python
Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The source code is available from `GitHub <https://github.com/KenKundert/inform>
You can download the repository and install using::

git clone https://github.com/KenKundert/inform.git
pip3 install --user inform
pip3 install inform


Issues
Expand Down
31 changes: 27 additions & 4 deletions inform/inform.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def strip_colors(cls, text):

# __repr {{{3
def __repr__(self):
return f'{self.__class__.__name__}({self.color!r})'
return f'{self.__class__.__name__}({self.color!r}, scheme={self.scheme})'


# LoggingCache class {{{2
Expand Down Expand Up @@ -1344,6 +1344,8 @@ def __format__(self, formatter):
out = always + suffix
return out.replace(self.num, self.render_num(self.count))

def __repr__(self):
return f"{self.__class__.__name__}({self.count})"

# truth {{{2
class truth:
Expand Down Expand Up @@ -1430,17 +1432,23 @@ def __format__(self, formatter):
def __str__(self):
return 'yes' if self.value else 'no'

def __repr__(self):
return f"{self.__class__.__name__}({self!s})"

def __bool__(self):
return bool(self.value)

# full_stop {{{2
def full_stop(sentence, end='.', allow='.?!'):
def full_stop(sentence, end='.', allow='.?!', remove=r'\\'):
"""Add period to end of string if it is needed.
A full stop (a period) is added if there is no terminating punctuation at the
end of the string. The argument is first converted to a string, and then
any white space at the end of the string is removed before looking for
terminal punctuation. The return value is always a string.
terminal punctuation. If the last character is in *allow* then no further
modifications performed. If the last character is in *remove*, it is
removed and no further modifications performed. Otherwise the *end* is
appended. The return value is always a string.
**Examples**::
Expand All @@ -1454,6 +1462,9 @@ def full_stop(sentence, end='.', allow='.?!'):
>>> full_stop('Is the file is out of date?')
'Is the file is out of date?'
>>> full_stop(f"invalid character found: {''}§", remove=r'§')
'invalid character found: '
You can override the allowed and desired endings::
>>> cases = '1, 3 9, 12.'.split()
Expand All @@ -1462,6 +1473,8 @@ def full_stop(sentence, end='.', allow='.?!'):
"""
sentence = str(sentence).rstrip()
if sentence[-1:] in remove:
return sentence[:-1]
try:
return sentence if sentence[-1] in allow else sentence + end
except IndexError:
Expand Down Expand Up @@ -1663,7 +1676,8 @@ class ProgressBar:
width (int):
The maximum width of the bar, the largest factor of 10 that
is less than or equal to this value is used.
is less than or equal to this value is used. If width is less than
or equal to zero, it is added to the current width of the terminal.
informant (informant):
Which informant to use when outputting the progress bar. By
Expand Down Expand Up @@ -1744,6 +1758,9 @@ def __init__(
self, stop, start=0, *,
log=False, prefix=None, width=79, informant=True, markers={}
):
if width <= 0:
width = os.get_terminal_size().columns + width

self.major = width//10
self.width = 10*self.major

Expand Down Expand Up @@ -2729,6 +2746,12 @@ def _report(self, args, kwargs, action):
if action._write_output(self):
cs = self.colorscheme if Color.isTTY(options['file']) else None
self._show_msg(
# should probably not be passing in the color scheme as it
# overrides a scheme explicitly specified in the color
# class. However if I change it it creates numerous errors
# in the tests. I did not have the time to resolve them, so
# I am leaving it for now. This results in an awkward bit
# of code in assimilate/overdue.py.
header_color(header, scheme=cs) if header else header,
header_color(culprit, scheme=cs) if culprit else culprit,
messege_color(message, scheme=cs) if message else message,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ def test_is_mapping():

def test_color():
assert Color('white', scheme='dark')('') == ''
assert repr(Color('white', scheme='dark')) == "Color('white')"
assert repr(Color('white', scheme='dark')) == "Color('white', scheme=dark)"

assert Color('black', scheme='dark')('black') == '\x1b[0;30mblack\x1b[0m'
assert Color('red', scheme='dark')('red') == '\x1b[0;31mred\x1b[0m'
Expand Down
2 changes: 1 addition & 1 deletion tests/test_zdoctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_inform():
# code used in doctests assumes python3.6
return
rv = doctest.testfile('../inform/inform.py', optionflags=doctest.ELLIPSIS)
assert rv.attempted == 156
assert rv.attempted == 157
assert rv.failed == 0

def test_manual():
Expand Down

0 comments on commit 6d00278

Please sign in to comment.