Browse Source

Handle no newline at the end of bindep.txt

We've seen people whose editors don't add newlines to files for whatever
reason. Make bindep handle this case since users are running into it.

Note that we could theoretically modify the existing parsley grammar to
accept a missing newline and instead find EOF but adding rules like that
seems to interact with whitespace processing in ways that I don't
understand. Rather than spend a ton of time learning parsley internals I
figure the fix here is simple and easy to understand and limits
potential fallout from changes to the grammar.

Change-Id: I960e579a603d1a4612d859451df1f559e950ac31
changes/39/814839/1
Clark Boylan 7 months ago
parent
commit
c4c2bf1afe
  1. 3
      bindep/depends.py
  2. 6
      bindep/tests/test_depends.py

3
bindep/depends.py

@ -140,6 +140,9 @@ class Depends(object):
:param filename: The string name of the file from which requirements
were loaded.
"""
if not depends_string.endswith('\n'):
# The parsley grammar expects each line to end with a newline
depends_string += '\n'
parser = makeGrammar(grammar, {})(depends_string)
self._rules = parser.rules()
self.filename = filename

6
bindep/tests/test_depends.py

@ -376,6 +376,12 @@ class TestDepends(TestCase):
depends = Depends("")
self.assertEqual([], depends._rules)
def test_no_newline(self):
depends = Depends("foo")
self.assertEqual(
[("foo", [], [])],
depends._rules)
def test_selectors(self):
depends = Depends("foo [!bar baz quux]\n")
self.assertEqual(

Loading…
Cancel
Save