diff --git a/macros.python b/macros.python index f0d431d..4248204 100644 --- a/macros.python +++ b/macros.python @@ -11,9 +11,45 @@ %python_ext_suffix %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))") %py_setup setup.py + +# This is the "201x-era" macro, we also use it to define the default %py_shbang_opts -s -%py_shbang_opts_nodash %(opts=%{py_shbang_opts}; echo ${opts#-}) -%py_shebang_flags %(opts=%{py_shbang_opts}; echo ${opts#-}) + +# This is a convenient helper that strips the leading dash from %%py_shbang_opts +%py_shbang_opts_nodash %{lua:print((rpm.expand('%?py_shbang_opts'):gsub('^%-', '')))} + +# Finally, this is the value everybody should actually use, with _add and _remove helpers +%py_shebang_flags %{lua: +-- py_shebang_flags is also a Lua global, so we can conveniently manipulate it repeatedly +-- in the beginning however, it is not set, so we need to do it +if py_shebang_flags == nil then + py_shebang_flags = rpm.expand('%?py_shbang_opts_nodash') +end +print(py_shebang_flags) +} + +%py_shebang_flags_add() %{lua: +if py_shebang_flags == nil then + py_shebang_flags = rpm.expand('%?py_shbang_opts_nodash') +end +for flag in rpm.expand('%?*'):gmatch('%a') do + index, _ = py_shebang_flags:find(flag) + if index == nil then + py_shebang_flags = py_shebang_flags .. flag + end +end +} + +%py_shebang_flags_remove() %{lua: +if py_shebang_flags == nil then + py_shebang_flags = rpm.expand('%?py_shbang_opts_nodash') +end +for flag in rpm.expand('%?*'):gmatch('%a') do + py_shebang_flags, _ = py_shebang_flags:gsub(flag, '') +end +} + + %py_shebang_fix %{expand:\\\ if [ -f /usr/bin/pathfix%{python_version}.py ]; then pathfix=/usr/bin/pathfix%{python_version}.py diff --git a/macros.python3 b/macros.python3 index 0ccafd9..756541b 100644 --- a/macros.python3 +++ b/macros.python3 @@ -9,9 +9,44 @@ %python3_ext_suffix %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))") %py3dir %{_builddir}/python3-%{name}-%{version}-%{release} +# This is the "201x-era" macro, we also use it to define the default %py3_shbang_opts -s -%py3_shbang_opts_nodash %(opts=%{py3_shbang_opts}; echo ${opts#-}) -%py3_shebang_flags %(opts=%{py3_shbang_opts}; echo ${opts#-}) + +# This is a convenient helper that strips the leading dash from %%py3_shbang_opts +%py3_shbang_opts_nodash %{lua:print((rpm.expand('%?py3_shbang_opts'):gsub('^%-', '')))} + +# Finally, this is the value everybody should actually use, with _add and _remove helpers +%py3_shebang_flags %{lua: +-- py3_shebang_flags is also a Lua global, so we can conveniently manipulate it repeatedly +-- in the beginning however, it is not set, so we need to do it +if py3_shebang_flags == nil then + py3_shebang_flags = rpm.expand('%?py3_shbang_opts_nodash') +end +print(py3_shebang_flags) +} + +%py3_shebang_flags_add() %{lua: +if py3_shebang_flags == nil then + py3_shebang_flags = rpm.expand('%?py3_shbang_opts_nodash') +end +for flag in rpm.expand('%?*'):gmatch('%a') do + index, _ = py3_shebang_flags:find(flag) + if index == nil then + py3_shebang_flags = py3_shebang_flags .. flag + end +end +} + +%py3_shebang_flags_remove() %{lua: +if py3_shebang_flags == nil then + py3_shebang_flags = rpm.expand('%?py3_shbang_opts_nodash') +end +for flag in rpm.expand('%?*'):gmatch('%a') do + py3_shebang_flags, _ = py3_shebang_flags:gsub(flag, '') +end +} + + %py3_shebang_fix %{expand:\\\ if [ -f /usr/bin/pathfix%{python3_version}.py ]; then pathfix=/usr/bin/pathfix%{python3_version}.py