Skip to content

Commit 4c71772

Browse files
committed
Use textwrap.dedent + .strip() for all messages
Closes #10987
1 parent 2047a57 commit 4c71772

File tree

7 files changed

+291
-127
lines changed

7 files changed

+291
-127
lines changed

readthedocs/config/notifications.py

+79-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Notifications related to Read the Docs YAML config file."""
2+
import textwrap
23

34
from django.utils.translation import gettext_noop as _
45

@@ -13,190 +14,226 @@
1314
id=ConfigError.GENERIC,
1415
header=_("There was an unexpected problem in your config file"),
1516
body=_(
16-
"""
17+
textwrap.dedent(
18+
"""
1719
There was an unexpected problem in your config file.
1820
Make sure the encoding is correct.
1921
"""
22+
).strip(),
2023
),
2124
type=ERROR,
2225
),
2326
Message(
2427
id=ConfigError.DEFAULT_PATH_NOT_FOUND,
2528
header=_("Config file not found at default path"),
2629
body=_(
27-
"""
30+
textwrap.dedent(
31+
"""
2832
No default configuration file found at repository's root.
2933
"""
34+
).strip(),
3035
),
3136
type=ERROR,
3237
),
3338
Message(
3439
id=ConfigError.CONFIG_PATH_NOT_FOUND,
3540
header=_("Configuration file not found"),
3641
body=_(
37-
"""
42+
textwrap.dedent(
43+
"""
3844
Configuration file not found in <code>{directory}</code>.
3945
"""
46+
).strip(),
4047
),
4148
type=ERROR,
4249
),
4350
Message(
4451
id=ConfigError.KEY_NOT_SUPPORTED_IN_VERSION,
4552
header=_("Configuration key not supported in this version"),
4653
body=_(
47-
"""
54+
textwrap.dedent(
55+
"""
4856
The <code>{key}</code> configuration option is not supported in this version.
4957
"""
58+
).strip(),
5059
),
5160
type=ERROR,
5261
),
5362
Message(
5463
id=ConfigError.PYTHON_SYSTEM_PACKAGES_REMOVED,
5564
header=_("Invalid configuration key"),
5665
body=_(
57-
"""
66+
textwrap.dedent(
67+
"""
5868
The configuration key <code>python.system_packages</code> has been deprecated and removed.
5969
Refer to https://blog.readthedocs.com/drop-support-system-packages/ to read more
6070
about this change and how to upgrade your config file."
6171
"""
72+
).strip(),
6273
),
6374
type=ERROR,
6475
),
6576
Message(
6677
id=ConfigError.PYTHON_USE_SYSTEM_SITE_PACKAGES_REMOVED,
6778
header=_("Invalid configuration key"),
6879
body=_(
69-
"""
80+
textwrap.dedent(
81+
"""
7082
The configuration key <code>python.use_system_site_packages</code> has been deprecated and removed.
7183
Refer to https://blog.readthedocs.com/drop-support-system-packages/ to read more
7284
about this change and how to upgrade your config file."
7385
"""
86+
).strip(),
7487
),
7588
type=ERROR,
7689
),
7790
Message(
7891
id=ConfigError.INVALID_VERSION,
7992
header=_("Invalid configuration version"),
8093
body=_(
81-
"""
94+
textwrap.dedent(
95+
"""
8296
Invalid version of the configuration file.
8397
"""
98+
).strip(),
8499
),
85100
type=ERROR,
86101
),
87102
Message(
88103
id=ConfigError.GENERIC_INVALID_CONFIG_KEY,
89104
header=_("Invalid configuration option"),
90105
body=_(
91-
"""
106+
textwrap.dedent(
107+
"""
92108
Invalid configuration option: <code>{key}</code>.
93109
94110
Read the Docs configuration file: <code>{source_file}</code>.
95111
96112
<code>{error_message}</code>
97113
"""
114+
).strip(),
98115
),
99116
type=ERROR,
100117
),
101118
Message(
102119
id=ConfigError.NOT_BUILD_TOOLS_OR_COMMANDS,
103120
header=_("Invalid configuration option: <code>build</code>"),
104121
body=_(
105-
"""
122+
textwrap.dedent(
123+
"""
106124
At least one item should be provided in "tools" or "commands".
107125
"""
126+
).strip(),
108127
),
109128
type=ERROR,
110129
),
111130
Message(
112131
id=ConfigError.BUILD_JOBS_AND_COMMANDS,
113132
header=_("Invalid configuration option"),
114133
body=_(
115-
"""
134+
textwrap.dedent(
135+
"""
116136
The keys <code>build.jobs</code> and <code>build.commands</code> can't be used together.
117137
"""
138+
).strip(),
118139
),
119140
type=ERROR,
120141
),
121142
Message(
122143
id=ConfigError.APT_INVALID_PACKAGE_NAME_PREFIX,
123144
header=_("Invalid APT package name"),
124145
body=_(
125-
"""
146+
textwrap.dedent(
147+
"""
126148
The name of the packages (e.g. <code>{package}</code>) can't start with <code>{prefix}</code>
127149
"""
150+
).strip(),
128151
),
129152
type=ERROR,
130153
),
131154
Message(
132155
id=ConfigError.APT_INVALID_PACKAGE_NAME,
133156
header=_("Invalid APT package name"),
134157
body=_(
135-
"""
158+
textwrap.dedent(
159+
"""
136160
The name of the package <code>{pacakge}</name> is invalid.
137161
"""
162+
).strip(),
138163
),
139164
type=ERROR,
140165
),
141166
Message(
142167
id=ConfigError.USE_PIP_FOR_EXTRA_REQUIREMENTS,
143168
header=_("Invalid Python install method"),
144169
body=_(
145-
"""
170+
textwrap.dedent(
171+
"""
146172
You need to install your project with pip to use <code>extra_requirements</code>.
147173
"""
174+
).strip(),
148175
),
149176
type=ERROR,
150177
),
151178
Message(
152179
id=ConfigError.PIP_PATH_OR_REQUIREMENT_REQUIRED,
153180
header=_("Invalid configuration key"),
154181
body=_(
155-
"""
182+
textwrap.dedent(
183+
"""
156184
<code>path</code> or <code>requirements</code> key is required for <code>python.install</code>.
157185
"""
186+
).strip(),
158187
),
159188
type=ERROR,
160189
),
161190
Message(
162191
id=ConfigError.SPHINX_MKDOCS_CONFIG_TOGETHER,
163192
header=_("Invalid configuration key"),
164193
body=_(
165-
"""
194+
textwrap.dedent(
195+
"""
166196
You can not have <code>sphinx</code> and <code>mkdocs</code> keys at the same time.
167197
"""
198+
).strip(),
168199
),
169200
type=ERROR,
170201
),
171202
Message(
172203
id=ConfigError.SUBMODULES_INCLUDE_EXCLUDE_TOGETHER,
173204
header=_("Invalid configuration key"),
174205
body=_(
175-
"""
206+
textwrap.dedent(
207+
"""
176208
You can not have <code>exclude</code> and <code>include</code> submodules at the same time.
177209
"""
210+
).strip(),
178211
),
179212
type=ERROR,
180213
),
181214
Message(
182215
id=ConfigError.INVALID_KEY_NAME,
183216
header=_("Invalid configuration key: {key}"),
184217
body=_(
185-
"""
218+
textwrap.dedent(
219+
"""
186220
Make sure the key name <code>{key}</code> is correct.
187221
"""
222+
).strip(),
188223
),
189224
type=ERROR,
190225
),
191226
Message(
192227
id=ConfigError.SYNTAX_INVALID,
193228
header=_("Invalid syntax in configuration file"),
194229
body=_(
195-
"""
230+
textwrap.dedent(
231+
"""
196232
Error while parsing <code>{filename}</code>.
197233
198234
{error_message}
199235
"""
236+
).strip(),
200237
),
201238
type=ERROR,
202239
),
@@ -209,87 +246,103 @@
209246
id=ConfigValidationError.INVALID_BOOL,
210247
header=_("Config file validation error"),
211248
body=_(
212-
"""
249+
textwrap.dedent(
250+
"""
213251
Config validation error in <code>{key}</code>.
214252
Expected one of (0, 1, true, false), got <code>{value}</code>.
215253
"""
254+
).strip(),
216255
),
217256
type=ERROR,
218257
),
219258
Message(
220259
id=ConfigValidationError.INVALID_CHOICE,
221260
header=_("Config file validation error"),
222261
body=_(
223-
"""
262+
textwrap.dedent(
263+
"""
224264
Config validation error in <code>{key}</code>.
225265
Expected one of ({choices}), got <code>{value}</code>.
226266
"""
267+
).strip(),
227268
),
228269
type=ERROR,
229270
),
230271
Message(
231272
id=ConfigValidationError.INVALID_DICT,
232273
header=_("Config file validation error"),
233274
body=_(
234-
"""
275+
textwrap.dedent(
276+
"""
235277
Config validation error in <code>{key}</code>.
236278
Expected a dictionary, got <code>{value}</code>.
237279
"""
280+
).strip(),
238281
),
239282
type=ERROR,
240283
),
241284
Message(
242285
id=ConfigValidationError.INVALID_PATH,
243286
header=_("Config file validation error"),
244287
body=_(
245-
"""
288+
textwrap.dedent(
289+
"""
246290
Config validation error in <code>{key}</code>.
247291
The path <code>{value}</code> does not exist.
248292
"""
293+
).strip(),
249294
),
250295
type=ERROR,
251296
),
252297
Message(
253298
id=ConfigValidationError.INVALID_PATH_PATTERN,
254299
header=_("Config file validation error"),
255300
body=_(
256-
"""
301+
textwrap.dedent(
302+
"""
257303
Config validation error in <code>{key}</code>.
258304
The path <code>{value}</code> is not a valid path pattern.
259305
"""
306+
).strip(),
260307
),
261308
type=ERROR,
262309
),
263310
Message(
264311
id=ConfigValidationError.INVALID_STRING,
265312
header=_("Config file validation error"),
266313
body=_(
267-
"""
314+
textwrap.dedent(
315+
"""
268316
Config validation error in <code>{key}</code>.
269317
Expected a string, got <code>{value}</code>.
270318
"""
319+
).strip(),
271320
),
272321
type=ERROR,
273322
),
274323
Message(
275324
id=ConfigValidationError.INVALID_LIST,
276325
header=_("Config file validation error"),
277326
body=_(
278-
"""
327+
textwrap.dedent(
328+
"""
279329
Config validation error in <code>{key}</code>.
280330
Expected a list, got <code>{value}</code>.
281331
"""
332+
).strip(),
282333
),
283334
type=ERROR,
284335
),
285336
Message(
286337
id=ConfigValidationError.VALUE_NOT_FOUND,
287338
header=_("Config file validation error"),
288339
body=_(
289-
"""
340+
textwrap.dedent(
341+
"""
290342
Config validation error in <code>{key}</code>.
291343
Value <code>{value}</code> not found.
292344
"""
345+
).strip(),
293346
),
294347
type=ERROR,
295348
),

readthedocs/core/notifications.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Read the Docs notifications."""
22

3+
import textwrap
4+
35
from django.utils.translation import gettext_lazy as _
46

57
from readthedocs.notifications.constants import WARNING
@@ -11,10 +13,12 @@
1113
id=MESSAGE_EMAIL_VALIDATION_PENDING,
1214
header=_("Email address not verified"),
1315
body=_(
14-
"""
16+
textwrap.dedent(
17+
"""
1518
Your primary email address is not verified.
1619
Please <a href="{account_email_url}">verify it here</a>.
1720
"""
21+
).strip(),
1822
),
1923
type=WARNING,
2024
),

0 commit comments

Comments
 (0)