summaryrefslogtreecommitdiff
path: root/pkg_resources
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2022-01-23 21:18:02 -0500
committerJason R. Coombs <jaraco@jaraco.com>2022-01-23 21:18:02 -0500
commit42ce1398e1576537966a9dbfbf63e5757dbb95e8 (patch)
treebfd393d8f8f48a6af028b869b3aa17d763c2b4f3 /pkg_resources
parent944861f2e58d4c0755e3aa1e79fbce831318b9d5 (diff)
downloadpython-setuptools-git-42ce1398e1576537966a9dbfbf63e5757dbb95e8.tar.gz
Extract function for dropping comments.
Diffstat (limited to 'pkg_resources')
-rw-r--r--pkg_resources/__init__.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index 0ed1c08f..c8dad54b 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -3092,18 +3092,30 @@ def issue_warning(*args, **kw):
warnings.warn(stacklevel=level + 1, *args, **kw)
+def drop_comment(line):
+ """
+ Drop comments.
+
+ >>> drop_comment('foo # bar')
+ 'foo'
+
+ A hash without a space may be in a URL.
+
+ >>> drop_comment('http://example.com/foo#bar')
+ 'http://example.com/foo#bar'
+ """
+ return line.partition(' #')[0]
+
+
def parse_requirements(strs):
"""Yield ``Requirement`` objects for each specification in `strs`
`strs` must be a string, or a (possibly-nested) iterable thereof.
"""
# create a steppable iterator, so we can handle \-continuations
- lines = iter(yield_lines(strs))
+ lines = iter(map(drop_comment, yield_lines(strs)))
for line in lines:
- # Drop comments -- a hash without a space may be in a URL.
- if ' #' in line:
- line = line[:line.find(' #')]
# If there is a line continuation, drop it, and append the next line.
if line.endswith('\\'):
line = line[:-2].strip()