Skip to content

Commit

Permalink
Deprecated support for non-sequence __requires__.
Browse files Browse the repository at this point in the history
Closes #109
  • Loading branch information
jaraco committed Jul 13, 2024
1 parent f8e1290 commit 6b9549e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions newsfragments/109.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecated support for non-sequence __requires__.
21 changes: 16 additions & 5 deletions pip_run/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,27 @@ def read_python(self):
r"""
>>> DepsReader("__requires__=['foo']").read()
['foo']
>>> DepsReader(r"__requires__='foo\nbar\n#baz'").read()
['foo', 'bar']
"""
raw_reqs = suppress(ValueError)(self._read)('__requires__') or []
reqs_items = jaraco.text.yield_lines(raw_reqs)
deps = Dependencies.load(reqs_items)
reqs = suppress(ValueError)(self._read)('__requires__') or []
deps = Dependencies.load(self._compat_process(reqs))
with contextlib.suppress(ValueError):
deps.index_url = self._read('__index_url__')
return deps

def _compat_process(self, reqs):
"""
Deprecated support for __requires__:str
"""
processed = list(jaraco.text.yield_lines(reqs))
if reqs == processed:
return reqs
warnings.warn(
"Support for string processing in __requires__ is deprecated",
DeprecationWarning,
stacklevel=1,
)
return processed

def _read(self, var_name):
"""
Read a variable from self.script by parsing the AST.
Expand Down
5 changes: 3 additions & 2 deletions tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def test_single_dep(self):
__requires__='foo'
"""
)
assert scripts.DepsReader(script).read() == ['foo']
with pytest.deprecated_call():
assert scripts.DepsReader(script).read() == ['foo']

def test_index_url(self):
script = textwrap.dedent(
Expand All @@ -100,7 +101,7 @@ def test_fstrings_allowed(self):
script = DALS(
"""
# coding: future_fstrings
__requires__ = 'foo'
__requires__ = ['foo']
f'boo'
f'coo'
"""
Expand Down

0 comments on commit 6b9549e

Please sign in to comment.