paragraphs 1.0__0-py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
paragraphs/__init__.py ADDED
@@ -0,0 +1,9 @@
1
+ """Import par into top-level namespace.
2
+
3
+ :author: Shay Hill
4
+ :created: 2023-01-02
5
+ """
6
+
7
+ from paragraphs.main import par
8
+
9
+ __all__ = ["par"]
paragraphs/main.py ADDED
@@ -0,0 +1,48 @@
1
+ """Html-like formatting of multi-line strings.
2
+
3
+ :author: Shay Hill
4
+ :created: 7/8/2019
5
+ """
6
+
7
+ import re
8
+
9
+ # match a newline followed by any number of blank lines
10
+ _RE_PARBREAK = re.compile(r"\n\s*\n")
11
+
12
+
13
+ def par(text: str) -> str:
14
+ r"""Html-like paragraph formatting.
15
+
16
+ :param text: any block of text indented to any level
17
+ :return:
18
+
19
+ * whitespace substrings converted to single spaces
20
+ * leading whitespace removed
21
+ * double newlines ('\n\n') split paragraphs
22
+ * one trailing newline retained (if present)
23
+
24
+ >>> two_paragraphs = '''
25
+ ... Lorem ipsum dolor
26
+ ... sit amet,
27
+ ...
28
+ ... consectetur
29
+ ... adipiscing
30
+ ... elit'''
31
+
32
+ >>> par(two_paragraphs)
33
+ Lorem ipsum dolor sit amet,"
34
+ <blankline>
35
+ consectetur adipiscing elit"
36
+
37
+ >>> par('''retains one trailing newline
38
+ ... ''')
39
+ retains one trailing newline
40
+ <blankline>
41
+
42
+ >>> par('''no trailing newline''')
43
+ no trailing newline
44
+ """
45
+ trail = "\n" if text.rstrip(" \t").endswith("\n") else ""
46
+ paragraphs = _RE_PARBREAK.split(text.strip())
47
+ paragraphs = [" ".join(x.split()) for x in paragraphs]
48
+ return "\n\n".join(paragraphs) + trail
paragraphs/py.typed ADDED
File without changes
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Shay Hill
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,195 @@
1
+ Metadata-Version: 2.1
2
+ Name: paragraphs
3
+ Version: 1.0.0
4
+ Summary: Incorporate long strings painlessly, beautifully into Python code.
5
+ Author-email: Shay Hill <shay_public@hotmail.com>
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE.txt
10
+ Provides-Extra: dev
11
+ Requires-Dist: commitizen ; extra == 'dev'
12
+ Requires-Dist: pre-commit ; extra == 'dev'
13
+ Requires-Dist: pytest ; extra == 'dev'
14
+ Requires-Dist: tox ; extra == 'dev'
15
+
16
+ # paragraphs
17
+
18
+ Incorporate long strings painlessly, beautifully into Python code.
19
+
20
+ ## Examples
21
+
22
+ **Easily edited, `gq`-able, `fill-paragraph`-able, comprehensive error messages.**
23
+ ```python
24
+ from paragraphs import par
25
+
26
+ class SuddenDeathError(Exception):
27
+ def __init__(self, cause: str) -> None:
28
+ self.cause = cause
29
+
30
+ def __str__(self) -> str:
31
+ return par(
32
+ f"""
33
+ Y - e - e - e - es, Lord love you! Why should she die of
34
+ {self.cause}? She come through diphtheria right enough the year
35
+ before. I saw her with my own eyes. Fairly blue with it, she was.
36
+ They all thought she was dead; but my father, he kept ladling gin
37
+ down her throat till she came to so sudden that she bit the bowl
38
+ off the spoon.
39
+
40
+ What call would a woman with that strength in her have to die of
41
+ {self.cause}? What become of her new straw hat that should have
42
+ come to me? Somebody pinched it; and what I say is, them as pinched
43
+ it done her in."""
44
+ )
45
+
46
+ raise SuddenDeathError("influenza")
47
+ ```
48
+
49
+ **Nicely-formatted long string data. Spoilers for some old novels here,
50
+ but these *are* the original titles.**
51
+
52
+ ```python
53
+ author2titles = {
54
+ "Samuel Penhallow": [
55
+ par(
56
+ """
57
+ The history of the wars of New-England with the Eastern Indians;
58
+ or, a narrative of their continued perfidy and cruelty, from the
59
+ 10th of August, 1703, to the peace renewed 13th of July, 1713. And
60
+ from the 25th of July, 1722, to their submission 15th December,
61
+ 1725, which was ratified August 5th, 1726"""
62
+ )
63
+ ],
64
+ "Daniel Defoe": [
65
+ par(
66
+ """
67
+ The Life and Strange Surprizing Adventures of Robinson Crusoe, Of
68
+ York, Mariner: Who lived Eight and Twenty Years, all alone in an
69
+ un-inhabited Island on the Coast of America, near the Mouth of the
70
+ Great River of Oroonoque; Having been cast on Shore by Shipwreck,
71
+ wherein all the Men perished but himself. With An Account how he
72
+ was at last as strangely deliver'd by Pyrates"""
73
+ ),
74
+ par(
75
+ """The Fortunes and Misfortunes of the Famous Moll Flanders Who was
76
+ born in Newgate, and during a life of continu’d Variety for
77
+ Threescore Years, besides her Childhood, was Twelve Years a Whore,
78
+ five times a Wife (whereof once to her brother) Twelve Years a
79
+ Thief, Eight Years a Transported Felon in Virginia, at last grew
80
+ Rich, liv’d Honest and died a Penitent"""
81
+ ),
82
+ ],
83
+ }
84
+ ```
85
+
86
+ ## Installation
87
+ ```bash
88
+ pip install paragraphs
89
+ ```
90
+
91
+ ## Use
92
+
93
+ ```python
94
+ from paragraphs import par
95
+
96
+ PARAGRAPH = par(
97
+ """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
98
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
99
+ veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
100
+ commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
101
+ velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
102
+ cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
103
+ est laborum."""
104
+ )
105
+
106
+ # the above is equivalent to
107
+
108
+ PARAGRAPH = (
109
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod"
110
+ + " tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim"
111
+ + " veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea"
112
+ + " commodo consequat. Duis aute irure dolor in reprehenderit in voluptate"
113
+ + " velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint"
114
+ + " occaecat cupidatat non proident, sunt in culpa qui officia deserunt"
115
+ + " mollit anim id est laborum."
116
+ )
117
+
118
+ ```
119
+
120
+ ## Features
121
+
122
+ Joins lines. Removes indentation and leading whitespace.
123
+
124
+ ```python
125
+ >>> par(
126
+ """Lorem ipsum dolor
127
+ sit amet,"""
128
+ )
129
+
130
+ Lorem ipsum dolor sit amet,
131
+ ```
132
+
133
+ Ignores one leading newline.
134
+
135
+ ```python
136
+ >>> par(
137
+ """
138
+ Lorem ipsum dolor
139
+ sit amet,"""
140
+ )
141
+
142
+ Lorem ipsum dolor sit amet,
143
+ ```
144
+
145
+ Separates paragraphs with double newline (`"\n\n"`).
146
+
147
+ ```python
148
+ >>> par (
149
+ """
150
+ Lorem ipsum dolor
151
+ sit amet,
152
+
153
+ consectetur
154
+ adipiscing
155
+ elit"""
156
+ )
157
+
158
+ Lorem ipsum dolor sit amet,
159
+ <blankline>
160
+ consectetur adipiscing elit
161
+ ```
162
+
163
+ Retains one trailing newline (if present).
164
+
165
+ ```python
166
+ >>> par(
167
+ """retains one trailing newline
168
+ """
169
+ )
170
+
171
+ retains one trailing newline
172
+ <blankline>
173
+
174
+ >>> par("""no trailing newline""")
175
+
176
+ no trailing newline
177
+ ```
178
+
179
+ ## Notes
180
+
181
+ converts all whitespace to " "
182
+
183
+ ```python
184
+ >>> par("""converts\tall\twhitespace\tto\<space>""")
185
+
186
+ converts all whitespace to <space>
187
+ ```
188
+
189
+ compresses consecutive whitespace to " "
190
+
191
+ ```python
192
+ >>> par("""compresses consecutive whitespace""")
193
+
194
+ compresses consecutive whitespace
195
+ ```
@@ -0,0 +1,8 @@
1
+ paragraphs/__init__.py,sha256=jaLhlyJqHzlBxW62xuzdHSFHh4J2UiynMmICOyEPQWQ,146
2
+ paragraphs/main.py,sha256=I05mJCTeeIusZeuYgOWZdjEZaiF0xNx02IITXnpMAxA,1231
3
+ paragraphs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ paragraphs-1.0.0.dist-info/LICENSE.txt,sha256=6azOzWPODyBgzuvezbefyPbicI5bimF1wP0NjVozTB4,1097
5
+ paragraphs-1.0.0.dist-info/METADATA,sha256=WGPVAWO01B6fZ5Rh16BCimgwMxTlBupJyS28JKUQ6J4,5543
6
+ paragraphs-1.0.0.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
7
+ paragraphs-1.0.0.dist-info/top_level.txt,sha256=ZQuQ1qloXPi4_965TXp8hTEmGc9Q75WJnacZB5UIWPA,11
8
+ paragraphs-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (72.1.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ paragraphs