Skip to content

Commit 9331fad

Browse files
authored
🚸 Handle non-Unicode terminals (#5)
2 parents 0e4f7c9 + e93bba2 commit 9331fad

File tree

8 files changed

+60
-14
lines changed

8 files changed

+60
-14
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
=========
22
Changelog
33
=========
4+
`Version 0.3.1 <https://github.com/FCP-INDI/cpac/releases/tag/v0.3.1>`_
5+
=======================================================================
6+
* 🚸 Print without emoji if terminal can't handle extended Unicode set
7+
* 📚 Add PyPI badge to README
8+
49
`Version 0.3.0 <https://github.com/FCP-INDI/cpac/releases/tag/v0.3.0>`_
510
=======================================================================
611
* 📛 Rename project from `shnizzedy/cpac-python-package <https://github.com/shnizzedy/cpac-python-package>`_ to `FCP-INDI/cpac <https://github.com/FCP-INDI/cpac>`_

README.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
========================================================================
2-
C-PAC Python Package |build-status| |github-version| |upload| |coverage|
3-
========================================================================
1+
========================================================================================
2+
C-PAC Python Package |build-status| |github-version| |upload| |pypi-version| |coverage|
3+
========================================================================================
44

55

66
A Python package that wraps `C-PAC <http://fcp-indi.github.io>`_, enabling users to install cpac with `pip <https://pip.pypa.io>`_ and run from the command line.
@@ -98,6 +98,9 @@ Usage
9898
9999
.. END USAGE
100100
101+
.. |pypi-version| image:: https://badge.fury.io/py/cpac.svg
102+
:target: https://pypi.org/project/cpac/
103+
:alt: PyPI version
101104
.. |github-version| image:: https://img.shields.io/github/tag/FCP-INDI/cpac.svg
102105
:target: https://github.com/FCP-INDI/cpac/releases
103106
:alt: GitHub version
@@ -108,5 +111,6 @@ Usage
108111
:target: https://coveralls.io/github/FCP-INDI/cpac
109112
:alt: coverage badge
110113
.. |upload| image:: https://github.com/FCP-INDI/cpac/workflows/Upload%20Python%20Package/badge.svg
111-
:target: https://pypi.org/project/cpac-py/
112-
:alt: upload Python package
114+
:target: https://pypi.org/project/cpac/
115+
:alt: upload Python package to PyPI
116+

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
# General information about the project.
8484
project = u'cpac'
85-
copyright = u'2019, anibalsolon'
85+
copyright = u'2019, anibalsolon; 2020 C-PAC Team'
8686

8787
# The version info for the project you're documenting, acts as replacement for
8888
# |version| and |release|, also used in various other places throughout the

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ classifiers =
2323
Operating System :: OS Independent
2424
Programming Language :: Python :: 3
2525
Topic :: Scientific/Engineering :: Bio-Informatics
26-
version = 0.3.0
26+
version = 0.3.1
2727

2828
[options]
2929
zip_safe = False

src/cpac/backends/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Docker(Backend):
99
def __init__(self, **kwargs):
1010
self.platform = Platform_Meta('Docker', '🐳')
11-
print(f"Loading {self.platform.symbol} {self.platform.name}")
11+
self._print_loading_with_symbol(self.platform.name)
1212
self.client = docker.from_env()
1313
try:
1414
self.client.ping()

src/cpac/backends/platform.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ def _load_logging(self):
6666
) for j in self.bindings['volumes'][i]
6767
])
6868
t.columns = ['local', self.platform.name, 'mode']
69-
print(" ".join([
70-
f"Loading {self.platform.symbol}",
71-
self.image,
72-
"with these directory bindings:"
73-
]))
69+
self._print_loading_with_symbol(
70+
" ".join([
71+
self.image,
72+
"with these directory bindings:"
73+
])
74+
)
7475
print(textwrap.indent(
7576
tabulate(t.applymap(
7677
lambda x: (
@@ -93,6 +94,14 @@ def _prep_binding(self, binding_path_local, binding_path_remote):
9394
os.path.abspath(binding_path_remote)
9495
)
9596

97+
def _print_loading_with_symbol(self, message, prefix='Loading'):
98+
if prefix is not None:
99+
print(prefix, end=' ')
100+
try:
101+
print(' '.join([self.platform.symbol, message]))
102+
except UnicodeEncodeError:
103+
print(message)
104+
96105
def _set_bindings(self, **kwargs):
97106
tag = kwargs.get('tag', None)
98107
tag = tag if isinstance(tag, str) else None

src/cpac/backends/singularity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, **kwargs):
1818
if kwargs.get("working_dir") is not None:
1919
pwd = kwargs["working_dir"]
2020
os.chdir(pwd)
21-
print(f"Loading {self.platform.symbol} {self.platform.name}")
21+
self._print_loading_with_symbol(self.platform.name)
2222
if image and isinstance(image, str) and os.path.exists(image):
2323
self.image = image
2424
elif tag and isinstance(tag, str): # pragma: no cover

tests/test_cpac.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pytest
2+
3+
from contextlib import redirect_stdout
4+
from cpac.backends import Backends
5+
from io import StringIO, TextIOWrapper, BytesIO
6+
7+
8+
@pytest.mark.parametrize('platform', ['docker', 'singularity'])
9+
def test_loading_message(platform):
10+
redirect_out = StringIO()
11+
with redirect_stdout(redirect_out):
12+
loaded = Backends(platform)
13+
with_symbol = ' '.join([
14+
'Loading',
15+
loaded.platform.symbol,
16+
loaded.platform.name
17+
])
18+
assert with_symbol in redirect_out.getvalue()
19+
20+
redirect_out = TextIOWrapper(
21+
BytesIO(), encoding='latin-1', errors='strict', write_through=True)
22+
with redirect_stdout(redirect_out):
23+
loaded = Backends(platform)
24+
without_symbol = ' '.join([
25+
'Loading',
26+
loaded.platform.name
27+
])
28+
assert without_symbol in redirect_out.buffer.getvalue().decode()

0 commit comments

Comments
 (0)