public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/pyproject-rpm-macros] f43: getopt: Add %__pyproject_optflag_{short} macros for option forwarding
@ 2026-07-10 10:50
0 siblings, 0 replies; only message in thread
From: @ 2026-07-10 10:50 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : rpms/pyproject-rpm-macros
Branch : f43
Commit : 9108ee5b7490e417cfa902a4d7fb4f505108d55f
Author : Miro Hrončok <miro@hroncok.cz>
Date : 2026-07-09T12:19:57+02:00
Stats : +56/-9 in 3 file(s)
URL : https://src.fedoraproject.org/rpms/pyproject-rpm-macros/c/9108ee5b7490e417cfa902a4d7fb4f505108d55f?branch=f43
Log:
getopt: Add %__pyproject_optflag_{short} macros for option forwarding
Defines a ready-to-forward form alongside %__pyproject_opt_{short}:
"-X" for flags, "-X value" for value options. This replaces the verbose
%{?__pyproject_opt_X:-X %{__pyproject_opt_X}} pattern with %{?__pyproject_optflag_X}.
Assisted-By: Claude Opus 4.6
---
diff --git a/macros.pyproject b/macros.pyproject
index ce3065d..cb36d2e 100644
--- a/macros.pyproject
+++ b/macros.pyproject
@@ -174,8 +174,8 @@ fi
%{expand:\\\
%{expr:v"0%{?rpmversion}" >= v"4.18.90" ? "RPM_FILES_ESCAPE=4.19" : "RPM_FILES_ESCAPE=4.18" } \\
%{__python3} %{_rpmconfigdir}/redhat/pyproject_save_files.py \\
- --output-files "%{pyproject_files %{?__pyproject_opt_D:-D %{__pyproject_opt_D}}}" \\
- --output-modules "%{_pyproject_modules %{?__pyproject_opt_D:-D %{__pyproject_opt_D}}}" \\
+ --output-files "%{pyproject_files %{?__pyproject_optflag_D}}" \\
+ --output-modules "%{_pyproject_modules %{?__pyproject_optflag_D}}" \\
--buildroot "%{buildroot}" \\
--sitelib "%{python3_sitelib}" \\
--sitearch "%{python3_sitearch}" \\
@@ -192,7 +192,7 @@ fi
{short="t", long="top-level-only"},
})}\
%{expand:\\\
-if [ ! -f "%{_pyproject_modules %{?__pyproject_opt_D:-D %{__pyproject_opt_D}}}" ]; then
+if [ ! -f "%{_pyproject_modules %{?__pyproject_optflag_D}}" ]; then
_modules_glob=( %{_pyproject_modules_base}-* )
if [ -e "${_modules_glob[0]}" ]; then
_available=$(printf '%%s\n' "${_modules_glob[@]}" | sed 's|.*-pyproject-modules-||' | tr '\n' ' ')
@@ -203,7 +203,7 @@ if [ ! -f "%{_pyproject_modules %{?__pyproject_opt_D:-D %{__pyproject_opt_D}}}"
fi
exit 1
fi
-%py3_check_import -f "%{_pyproject_modules %{?__pyproject_opt_D:-D %{__pyproject_opt_D}}}" %{?__pyproject_opt_e:-e %{__pyproject_opt_e}} %{?__pyproject_opt_t:-t} %{?__pyproject_positional_args}
+%py3_check_import -f "%{_pyproject_modules %{?__pyproject_optflag_D}}" %{?__pyproject_optflag_e} %{?__pyproject_optflag_t} %{?__pyproject_positional_args}
}
@@ -213,7 +213,7 @@ fi
{short="D", long="dist-name", value=true},
{short="t", long="top-level-only"},
})}\
-if [ -z "$(cat %{_pyproject_modules %{?__pyproject_opt_D:-D %{__pyproject_opt_D}}})" ]; then\
+if [ -z "$(cat %{_pyproject_modules %{?__pyproject_optflag_D}})" ]; then\
echo "No modules to check found, exiting check"\
else\
%pyproject_check_import %{?**}\
diff --git a/pyproject_getopt.lua b/pyproject_getopt.lua
index 26ff7e9..861cb25 100644
--- a/pyproject_getopt.lua
+++ b/pyproject_getopt.lua
@@ -211,6 +211,7 @@ end
local function cleanup_macros(opt_spec)
for _, spec in ipairs(opt_spec) do
rpm.undefine("__pyproject_opt_" .. spec.short)
+ rpm.undefine("__pyproject_optflag_" .. spec.short)
end
end
@@ -241,18 +242,22 @@ local function quote_values(values)
return parts
end
--- Define %__pyproject_opt_{short} for each found option.
--- Flags get %{nil} (defined but empty), value options get each individual
--- value joined by separator.
+-- Define %__pyproject_opt_{short} and %__pyproject_optflag_{short} for each found option.
+-- opt: Flags get %{nil} (defined but empty), value options get each individual
+-- value joined by separator.
+-- optflag: Ready-to-forward form: "-X" for flags, "-X value" for value options.
-- See the quote_value function about how values are quoted.
local function define_macros(found, opt_spec)
for _, spec in ipairs(opt_spec) do
if found[spec.short] then
if spec.value then
local parts = quote_values(found[spec.short])
- rpm.define("__pyproject_opt_" .. spec.short .. " " .. table.concat(parts, spec.separator))
+ local value = table.concat(parts, spec.separator)
+ rpm.define("__pyproject_opt_" .. spec.short .. " " .. value)
+ rpm.define("__pyproject_optflag_" .. spec.short .. " -" .. spec.short .. " " .. value)
else
rpm.define("__pyproject_opt_" .. spec.short .. " %{nil}")
+ rpm.define("__pyproject_optflag_" .. spec.short .. " -" .. spec.short)
end
end
end
diff --git a/test_pyproject_getopt.lua b/test_pyproject_getopt.lua
index efe700a..dcd1742 100644
--- a/test_pyproject_getopt.lua
+++ b/test_pyproject_getopt.lua
@@ -27,6 +27,21 @@ local function assert_value(name, expected)
)
end
+local function assert_optflag(name, expected)
+ local actual = rpm.expand("%{?__pyproject_optflag_" .. name .. "}")
+ assert(
+ actual == expected,
+ "expected __pyproject_optflag_" .. name .. "=" .. expected .. ", got " .. actual
+ )
+end
+
+local function assert_optflag_undefined(name)
+ assert(
+ rpm.expand("%{undefined __pyproject_optflag_" .. name .. "}") == "1",
+ "expected __pyproject_optflag_" .. name .. " to be undefined"
+ )
+end
+
local function assert_positional(expected)
local actual = rpm.expand("%{?__pyproject_positional_args}")
assert(
@@ -406,6 +421,33 @@ function M.test_repeated_long_without_separator_errors()
end
+-- Optflag macros
+
+function M.test_optflag_for_flag()
+ pg.getopt(SAVE_FILES_SPEC, nil, {"-l"}, "test")
+ assert_optflag("l", "-l")
+ assert_optflag_undefined("M")
+end
+
+function M.test_optflag_for_value()
+ pg.getopt(WHEEL_SPEC, nil, {"-d", "foo"}, "test")
+ assert_optflag("d", "-d foo")
+end
+
+function M.test_optflag_for_repeated_value()
+ pg.getopt(CHECK_IMPORT_SPEC, nil, {"--exclude", "a", "--exclude", "b"}, "test")
+ assert_optflag("e", "-e a -e b")
+end
+
+function M.test_optflag_cleanup_between_calls()
+ pg.getopt(WHEEL_SPEC, nil, {"-d", "foo"}, "test")
+ assert_optflag("d", "-d foo")
+ pg.getopt(WHEEL_SPEC, nil, {"-C", "bar"}, "test")
+ assert_optflag_undefined("d")
+ assert_optflag("C", "-C bar")
+end
+
+
-- Raw error functions (without pcall) for Python-side stderr checking.
-- These are not discovered by list() since they don't start with test_.
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-10 10:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-10 10:50 [rpms/pyproject-rpm-macros] f43: getopt: Add %__pyproject_optflag_{short} macros for option forwarding
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox