diff options
author | Mike Gilbert <floppym@gentoo.org> | 2024-07-18 11:57:51 -0400 |
---|---|---|
committer | Mike Gilbert <floppym@gentoo.org> | 2024-07-18 11:57:51 -0400 |
commit | 8d06d85786d65f354a2d8a73c33958a4b7175200 (patch) | |
tree | e80783bcaff34fa3335d121c2179a7569fa13fd3 /dev-build/meson-format-array | |
parent | dev-python/setuptools-70.3.0: restore Prefix keywords (diff) | |
download | gentoo-8d06d85786d65f354a2d8a73c33958a4b7175200.tar.gz gentoo-8d06d85786d65f354a2d8a73c33958a4b7175200.tar.bz2 gentoo-8d06d85786d65f354a2d8a73c33958a4b7175200.zip |
dev-build/meson-format-array: add some doctests
Signed-off-by: Mike Gilbert <floppym@gentoo.org>
Diffstat (limited to 'dev-build/meson-format-array')
-rw-r--r-- | dev-build/meson-format-array/files/meson-format-array.py (renamed from dev-build/meson-format-array/files/meson-format-array) | 21 | ||||
-rw-r--r-- | dev-build/meson-format-array/meson-format-array-0.ebuild | 11 |
2 files changed, 28 insertions, 4 deletions
diff --git a/dev-build/meson-format-array/files/meson-format-array b/dev-build/meson-format-array/files/meson-format-array.py index d2bf49ba8e59..84a490cf29eb 100644 --- a/dev-build/meson-format-array/files/meson-format-array +++ b/dev-build/meson-format-array/files/meson-format-array.py @@ -6,10 +6,22 @@ import itertools import shlex import sys + def quote(s): + """ Surround a value with quotes, escape embedded quotes. + >>> quote("foo'bar") + "'foo\\\\'bar'" + """ + return "'" + s.replace("\\", "\\\\").replace("'", "\\'") + "'" -def main(args): + +def format_array(args): + """ Format shell-compatible expressions as a meson array. + >>> format_array(['-O2 -pipe -DFOO="bar baz"']) + "['-O2', '-pipe', '-DFOO=bar baz']" + """ + # Split each argument according to shell rules args = (shlex.split(x) for x in args) @@ -20,7 +32,12 @@ def main(args): args = (quote(x) for x in args) # Format the result - print("[" + ", ".join(args) + "]") + return "[" + ", ".join(args) + "]" + + +def main(args): + print(format_array(args)) + if __name__ == "__main__": main(sys.argv[1:]) diff --git a/dev-build/meson-format-array/meson-format-array-0.ebuild b/dev-build/meson-format-array/meson-format-array-0.ebuild index d9e12ab903f2..018d99e38bd9 100644 --- a/dev-build/meson-format-array/meson-format-array-0.ebuild +++ b/dev-build/meson-format-array/meson-format-array-0.ebuild @@ -4,7 +4,7 @@ EAPI=8 PYTHON_COMPAT=( python3_{10..13} ) -inherit python-r1 +inherit edo python-r1 DESCRIPTION="Format shell expressions into a meson array" HOMEPAGE="https://wiki.gentoo.org/wiki/No_homepage" @@ -17,6 +17,13 @@ REQUIRED_USE="${PYTHON_REQUIRED_USE}" RDEPEND="${PYTHON_DEPS}" S="${WORKDIR}" +src_test() { + run_doctest() { + edo ${EPYTHON} -B -m doctest "${FILESDIR}/meson-format-array.py" + } + python_foreach_impl run_doctest +} + src_install() { - python_foreach_impl python_doscript "${FILESDIR}"/meson-format-array + python_foreach_impl python_newscript "${FILESDIR}"/meson-format-array.py meson-format-array } |