@@ -199,7 +199,7 @@ Recommendations
199
199
===============
200
200
201
201
This section is non-normative and simply describes "good practices" when using
202
- metadata blocks.
202
+ dependency blocks.
203
203
204
204
While it is permitted for tools to do minimal validation of requirements, in
205
205
practice they should do as much "sanity check" validation as possible, even if
@@ -234,23 +234,27 @@ reference implementation can be included here.
234
234
def read_dependency_block (filename ):
235
235
# Use the tokenize module to handle any encoding declaration.
236
236
with tokenize.open(filename) as f:
237
+ # Skip lines until we reach a dependency block (OR EOF).
237
238
for line in f:
238
239
if re.match(DEPENDENCY_BLOCK_MARKER , line):
239
- for line in f:
240
- if not line.startswith(" #" ):
241
- break
242
- # Remove comments. An inline comment is introduced by
243
- # a hash, which must be preceded and followed by a
244
- # space. The initial hash will be skipped as it has
245
- # no space before it.
246
- line = line.split(" # " , maxsplit = 1 )[0 ]
247
- line = line[1 :].strip()
248
- if not line:
249
- break
250
- # Try to convert to a requirement. This will raise
251
- # an error if the line is not a PEP 508 requirement
252
- yield Requirement(line)
253
240
break
241
+ # Read dependency lines until we hit a line that doesn't
242
+ # start with #, or we are at EOF.
243
+ for line in f:
244
+ if not line.startswith(" #" ):
245
+ break
246
+ # Remove comments. An inline comment is introduced by
247
+ # a hash, which must be preceded and followed by a
248
+ # space.
249
+ line = line[1 :].split(" # " , maxsplit = 1 )[0 ]
250
+ line = line.strip()
251
+ # Ignore empty lines
252
+ if not line:
253
+ continue
254
+ # Try to convert to a requirement. This will raise
255
+ # an error if the line is not a PEP 508 requirement
256
+ yield Requirement(line)
257
+
254
258
255
259
A format similar to the one proposed here is already supported `in pipx
256
260
<https://github.com/pypa/pipx/pull/916> `__ and in `pip-run
@@ -366,7 +370,7 @@ no real benefit.
366
370
367
371
So the question is essentially, "why not use TOML?"
368
372
369
- The key idea behind the "metadata block" format is to define something that
373
+ The key idea behind the "dependency block" format is to define something that
370
374
reads naturally as a comment in the script. Dependency data is useful both for
371
375
tools and for the human reader, so having a human readable format is beneficial.
372
376
On the other hand, TOML of necessity has a syntax of its own, which distracts
0 commit comments