Skip to content

Commit e2f3d6f

Browse files
authored
Merge pull request #11 from nschloe/strip-fix
Strip fix
2 parents 6296057 + 0b9d0b1 commit e2f3d6f

File tree

7 files changed

+28
-22
lines changed

7 files changed

+28
-22
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2018-2019 Nico Schlömer
3+
Copyright (c) 2018-2020 Nico Schlömer
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ codecov:
44
disable_default_path_fixes: true
55
fixes:
66
- ".*/dist-packages/::"
7+
- ".*/site-packages/::"

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
version=about["__version__"],
1414
packages=find_packages(),
1515
url="https://github.com/nschloe/tablign",
16+
project_urls={
17+
"Code": "https://github.com/nschloe/tablign",
18+
"Issue tracker": "https://github.com/nschloe/tablign/issues",
19+
},
1620
author=about["__author__"],
1721
author_email=about["__author_email__"],
1822
install_requires=[],
23+
python_requires=">=3.6",
1924
description="Align columns in ASCII tables",
2025
long_description=open("README.md").read(),
2126
long_description_content_type="text/markdown",

tablign/__about__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
__version__ = "0.2.1"
1+
__version__ = "0.2.2"
22
__author__ = "Nico Schlömer"
33
__author_email__ = "[email protected]"
4-
__copyright__ = "Copyright (c) 2018-2019, {} <{}>".format(__author__, __author_email__)
4+
__copyright__ = f"Copyright (c) 2018-2020, {__author__} <{__author_email__}>"
55
__website__ = "https://github.com/nschloe/tablign"
66
__license__ = "License :: OSI Approved :: MIT License"
77
__status__ = "Development Status :: 4 - Beta"

tablign/main.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,13 @@ def tablign(string, align_char=".", delimiter=None):
6868
# transpose back
6969
data = list(map(list, zip(*cols)))
7070

71-
sep = " {} ".format(delimiter) if delimiter else " "
71+
sep = f" {delimiter} " if delimiter else " "
7272

73-
# Only strip trailing whitespace if the delimiter is None.
74-
strp = str.rstrip if delimiter is None else str.strip
73+
first_col_empty = all(s == "" for s in cols[0])
74+
last_col_empty = all(s == "" for s in cols[-1])
7575

76-
return "\n".join([strp(sep.join(row)) for row in data])
76+
# If the delimiter is None, only strip trailing whitespace
77+
lstrp = str.lstrip if first_col_empty and delimiter is not None else lambda x: x
78+
rstrp = str.rstrip if last_col_empty and delimiter is not None else lambda x: x
79+
80+
return "\n".join([rstrp(lstrp(sep.join(row))) for row in data])

test/test_cli.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
import tempfile
42

53
import tablign
@@ -17,4 +15,3 @@ def test_cli():
1715
ref = """A 1.34 -214.1\nCCCC 55.534 1131.1"""
1816
with open(outfile, "r") as f:
1917
assert ref == f.read()
20-
return

test/test_tablign.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
import pytest
42

53
import tablign
@@ -9,7 +7,6 @@ def test_plain():
97
data = """A 1.34 -214.1\nCCCC 55.534 1131.1"""
108
ref = """A 1.34 -214.1\nCCCC 55.534 1131.1"""
119
assert tablign.tablign(data) == ref
12-
return
1310

1411

1512
@pytest.mark.parametrize("sep_char", [","])
@@ -22,30 +19,32 @@ def test_column_seps(sep_char):
2219
CCCC {} 55.534 {} 1131.1""".format(
2320
*(4 * sep_char)
2421
)
25-
2622
assert tablign.tablign(data) == ref
27-
return
2823

2924

3025
def test_empty_cell():
31-
data = """| A | B |\n||C|"""
32-
ref = """| A | B |\n| | C |"""
26+
data = "| A | B |\n||C|"
27+
ref = "| A | B |\n| | C |"
28+
print("repr", repr(tablign.tablign(data)))
3329
assert tablign.tablign(data) == ref
34-
return
3530

3631

3732
def test_different_column_lengths():
38-
data = """| A | B |\n|C|"""
39-
ref = """| A | B |\n| C | |"""
33+
data = "| A | B |\n|C|"
34+
ref = "| A | B |\n| C | |"
4035
assert tablign.tablign(data) == ref
41-
return
4236

4337

4438
def test_csv():
4539
data = """A,B,\nCCCC,,"""
4640
ref = """A , B ,\nCCCC , ,"""
4741
assert tablign.tablign(data) == ref
48-
return
42+
43+
44+
def test_first_column_missing():
45+
data = "A,B,Z\n ,C,Z"
46+
ref = "A , B , Z\n , C , Z"
47+
assert tablign.tablign(data) == ref
4948

5049

5150
if __name__ == "__main__":

0 commit comments

Comments
 (0)