commit: 0aa4549d6046dc0708877780037fbd625b35ac91
Author: Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Sun Nov 30 21:55:14 2025 +0000
Commit: Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Sun Nov 30 22:34:56 2025 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=0aa4549d
refactor(bash): unexport the parser, deprecate the iter_* naming
Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
src/snakeoil/bash.py | 20 ++++++++------------
tests/test_bash.py | 30 +++++++++++-------------------
2 files changed, 19 insertions(+), 31 deletions(-)
diff --git a/src/snakeoil/bash.py b/src/snakeoil/bash.py
index c20c96e..7437f95 100644
--- a/src/snakeoil/bash.py
+++ b/src/snakeoil/bash.py
@@ -10,6 +10,8 @@ libtool .la files that are bash compatible, but
non-executable.
from shlex import shlex
+from snakeoil.deprecation import deprecated
+
from .delayed import regexp
from .fileutils import readlines
from .log import logger
@@ -26,12 +28,16 @@ __all__ = (
"read_bash",
"read_dict",
"read_bash_dict",
- "bash_parser",
"BashParseError",
)
-def iter_read_bash(
+iter_read_bash = deprecated(
+ "snakeoil.bash.iter_read_bash has been renamed to read_bash"
+)(lambda *a, **kw: read_bash(*a, **kw))
+
+
+def read_bash(
bash_source, allow_inline_comments=True, allow_line_cont=False,
enum_line=False
):
"""Iterate over a file honoring bash commenting rules and line
continuations.
@@ -80,16 +86,6 @@ def iter_read_bash(
yield s
-def read_bash(*args, **kwargs):
- """Read a file honoring bash commenting rules.
-
- See :py:func:`iter_read_bash` for parameter details.
-
- Returns a list of lines w/ comments stripped out.
- """
- return list(iter_read_bash(*args, **kwargs))
-
-
def read_bash_dict(bash_source, vars_dict=None, sourcing_command=None):
"""Read bash source, yielding a dict of vars.
diff --git a/tests/test_bash.py b/tests/test_bash.py
index 8c40d8e..cd97fad 100644
--- a/tests/test_bash.py
+++ b/tests/test_bash.py
@@ -1,9 +1,9 @@
from io import StringIO
import pytest
+
from snakeoil.bash import (
BashParseError,
- iter_read_bash,
read_bash,
read_bash_dict,
read_dict,
@@ -11,19 +11,17 @@ from snakeoil.bash import (
class TestBashCommentStripping:
- def test_iter_read_bash(self):
- output = iter_read_bash(
+ def test_read_bash(self):
+ output = read_bash(
StringIO("\n# hi I am a comment\nI am not \n asdf # inline
comment\n")
)
assert list(output) == ["I am not", "asdf"]
- output = iter_read_bash(
- StringIO("inline # comment "), allow_inline_comments=False
- )
+ output = read_bash(StringIO("inline # comment "),
allow_inline_comments=False)
assert list(output) == ["inline # comment"]
- def test_iter_read_bash_line_cont(self):
- output = iter_read_bash(
+ def test_read_bash_line_cont(self):
+ output = read_bash(
StringIO(
"\n"
"# hi I am a comment\\\n"
@@ -36,7 +34,7 @@ class TestBashCommentStripping:
assert list(output) == ["I am not a comment", "asdf"]
# continuation into inline comment
- output = iter_read_bash(
+ output = read_bash(
StringIO(
"\n# hi I am a comment\nI am \\\nnot a \\\ncomment # inline
comment\n"
),
@@ -45,14 +43,14 @@ class TestBashCommentStripping:
assert list(output) == ["I am not a comment"]
# ends with continuation
- output = iter_read_bash(
+ output = read_bash(
StringIO("\n# hi I am a comment\nI am \\\n\\\nnot a
\\\ncomment\\\n\\\n"),
allow_line_cont=True,
)
assert list(output) == ["I am not a comment"]
# embedded comment prefix via continued lines
- output = iter_read_bash(
+ output = read_bash(
StringIO(
"\\\n"
"# comment\\\n"
@@ -69,19 +67,13 @@ class TestBashCommentStripping:
# Line continuations have to end with \<newline> without any backslash
# before the pattern.
- output = iter_read_bash(
- StringIO("I am \\ \nnot a comment"), allow_line_cont=True
- )
+ output = read_bash(StringIO("I am \\ \nnot a comment"),
allow_line_cont=True)
assert list(output) == ["I am \\", "not a comment"]
- output = iter_read_bash(
+ output = read_bash(
StringIO("\\\nI am \\\\\nnot a comment"), allow_line_cont=True
)
assert list(output) == ["I am \\\\", "not a comment"]
- def test_read_bash(self):
- output = read_bash(StringIO("\n# hi I am a comment\nI am not\n"))
- assert output == ["I am not"]
-
class TestReadDictConfig:
def test_read_dict(self):