Skip to content

Commit

Permalink
Merge pull request #75 from bnavigator/subpackages_only
Browse files Browse the repository at this point in the history
Introduce python_subpackages_only
  • Loading branch information
mcepl authored Nov 12, 2020
2 parents cec67c2 + 3cbbfb5 commit 1f71d50
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<flavor>-modname`.

### Build Set

The default build set is listed in the __`%pythons`__ macro. Every entry in `%pythons` generates a
Expand Down Expand Up @@ -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 `<flavor>-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:
Expand Down Expand Up @@ -204,7 +212,6 @@ is still required.
appropriate environmental variables very similar to `%pytest` and `%pytest_arch`.



#### Alternative-related, general:

* __`%prepare_alternative [-t <targetfile> ] <name>`__ replaces `<targetfile>` with a symlink to
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -279,8 +287,11 @@ well as `py3` variants, are recognized for Fedora compatibility.
`<flavor>-modname`.

* __`%files %{python_files foo}`__ expands the `%files` section for all generated flavor subpackages
of `<flavor>-modname-foo`

of `<flavor>-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
Expand Down
48 changes: 42 additions & 6 deletions macros.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1f71d50

Please sign in to comment.