diff --git a/README.md b/README.md index d2719d2..0cb414b 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,10 @@ particular flavor, and autogenerate subpackages for all the other flavors. Alternately, it is to take package `python-modname` and generate subpackages for all flavors, leaving the top-level package empty. +Additionally it is possible for non-Python packages which define a subpackage +`%package -n python-modname` and corresponding `%description -n python-modname` etc., +to autogenerate all desired flavor subpackages `-modname`. + ### Build Set The default build set is listed in the __`%pythons`__ macro. Every entry in `%pythons` generates a @@ -107,6 +111,10 @@ expansion of `$python_` inside the `%python_expand` macro. * __`%python_subpackages`__ expands to the autogenerated subpackages. This should go at the end of the main headers section. +* __`%python_subpackage_only`__. Undefined by default. If you want to generate `-modname` +subpackages for a non-python main package, make sure to `%define python_subpackage_only 1` before +`%python_subpackages` and use `-n %{python_flavor}-modname` for section headers. + * __`%python_enable_dependency_generator`__ expands to a define to enable automatic requires generation of Python module dependencies using egg-info/dist-info metadata. This should go above the `%python_subpackages` macro, preferably closer to the top of the spec. Intended usage: @@ -204,7 +212,6 @@ is still required. appropriate environmental variables very similar to `%pytest` and `%pytest_arch`. - #### Alternative-related, general: * __`%prepare_alternative [-t ] `__ replaces `` with a symlink to @@ -243,6 +250,7 @@ the first one applies for `uninstall_alternative`. Each of these has a flavor-specific spelling: `%python2_alternative` etc. + #### Flavor-specific macros In addition, the following flavor-specific macros are known and supported by the configuration: @@ -279,8 +287,11 @@ well as `py3` variants, are recognized for Fedora compatibility. `-modname`. * __`%files %{python_files foo}`__ expands the `%files` section for all generated flavor subpackages - of `-modname-foo` - + of `-modname-foo`. + +For subpackages of non-python packages with `%python_subpackage_only`and + `%package -n %{python_flavor}-modname`, also use `%files %{python_files modname}`. + Always use the flavor-agnostic macro versions `%python_*` inside `%python_files` marked `%files` sections. See also the Filelists section of the diff --git a/macros.lua b/macros.lua index d140208..d0cad53 100644 --- a/macros.lua +++ b/macros.lua @@ -52,6 +52,12 @@ function _python_scan_spec() flavor = spec_name_prefix end + subpackage_only = rpm.expand("0%{?python_subpackage_only}") ~= "0" + if subpackage_only then + is_called_python = false + modname = "" + end + -- find the spec file specpath = rpm.expand("%_specfile") @@ -280,7 +286,7 @@ function python_subpackages() "pre", "post", "preun", "postun", "pretrans", "posttrans"} -- before we start, print Provides: python2-modname - if is_called_python and old_python2 then + if is_called_python and old_python2 and not subpackage_only then print(rpm.expand("Provides: python2-" .. modname .. " = %{?epoch:%{epoch}:}%{version}-%{release}\n")) end @@ -306,9 +312,15 @@ function python_subpackages() rpm.define("python_flavor " .. python) - local section_function = process_package_line - print(section_headline("package", current_flavor, nil)) - print_obsoletes(modname) + local section_function + + if subpackage_only then + section_function = ignore_line + else + section_function = process_package_line + print(section_headline("package", current_flavor, nil)) + print_obsoletes(modname) + end while true do -- collect lines until braces match. it's what rpm does, kind of. @@ -330,8 +342,27 @@ function python_subpackages() if KNOWN_SECTIONS[newsection] then -- enter new section - if param and param:startswith("-n") then - -- ignore named section + local submodname + local subparam + local ignore_section = false + if subpackage_only then + ignore_section = true + if param then + if newsection == "files" then + submodname, subparam = param:match("%%{python_files%s+(%S+)%s*(.*)}") + else + submodname, subparam = param:match("^%-n%s+%%{python_flavor}%-(%S+)%s*(.*)$") + end + if submodname then + modname = submodname + param = subparam + ignore_section = false + end + end + elseif (param and param:startswith("-n")) then + ignore_section = true + end + if ignore_section then section_function = ignore_line elseif newsection == "package" then print(section_headline("package", current_flavor, param)) @@ -426,6 +457,11 @@ function python_files() local param = "" if tonumber(nparams) > 0 then param = rpm.expand("%1") end + if subpackage_only then + modname = param + param = "" + end + print("-n " .. package_name(flavor, modname, param)) if not _python_subpackages_emitted then