Skip to content

Commit

Permalink
👹 Feed the hobgoblins (delint).
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Feb 8, 2024
1 parent 3278b43 commit 66e3ea2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
3 changes: 3 additions & 0 deletions pip_run/compat/py310.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Compatibility for Python 3.10 and earlier.
"""

__all__ = ['tomllib']


try:
import tomllib # type: ignore
except ImportError: # pragma: no cover
Expand Down
10 changes: 7 additions & 3 deletions pip_run/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from .compat.py310 import tomllib


ValidRequirementString = compose(str, packaging.requirements.Requirement)


Expand Down Expand Up @@ -93,10 +92,15 @@ def read_toml(self):
...
ValueError: Multiple script blocks found
"""
TOML_BLOCK_REGEX = r'(?m)^# /// (?P<type>[a-zA-Z0-9-]+)$\s(?P<content>(^#(| .*)$\s)*)^# ///$'
TOML_BLOCK_REGEX = (
r'(?m)^# /// (?P<type>[a-zA-Z0-9-]+)$\s(?P<content>(^#(| .*)$\s)*)^# ///$'
)
name = 'script'
matches = list(
filter(lambda m: m.group('type') == name, re.finditer(TOML_BLOCK_REGEX, self.script))
filter(
lambda m: m.group('type') == name,
re.finditer(TOML_BLOCK_REGEX, self.script),
)
)
if len(matches) > 1:
raise ValueError(f'Multiple {name} blocks found')
Expand Down
20 changes: 10 additions & 10 deletions tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,36 @@ def test_pkg_imported(tmp_path, shebang, extension, dash):
class TestSourceDepsReader:
def test_reads_files_with_attribute_assignment(self):
script = textwrap.dedent(
'''
"""
__requires__=['foo']
x.a = 'bar'
'''
"""
)
assert scripts.DepsReader(script).read() == ['foo']

def test_reads_files_with_multiple_assignment(self):
script = textwrap.dedent(
'''
"""
__requires__=['foo']
x, a = [a, x]
'''
"""
)
assert scripts.DepsReader(script).read() == ['foo']

def test_single_dep(self):
script = textwrap.dedent(
'''
"""
__requires__='foo'
'''
"""
)
assert scripts.DepsReader(script).read() == ['foo']

def test_index_url(self):
script = textwrap.dedent(
'''
"""
__requires__ = ['foo']
__index_url__ = 'https://my.private.index/'
'''
"""
)
reqs = scripts.DepsReader(script).read()
assert reqs.index_url == 'https://my.private.index/'
Expand All @@ -89,12 +89,12 @@ def test_fstrings_allowed(self):
with f-strings on all Pythons.
"""
script = DALS(
'''
"""
# coding: future_fstrings
__requires__ = 'foo'
f'boo'
f'coo'
'''
"""
)
reqs = scripts.DepsReader(script).read()
assert reqs == ['foo']
Expand Down

0 comments on commit 66e3ea2

Please sign in to comment.