From ae05b167d2800602f5222237ec29780d84a04ea4 Mon Sep 17 00:00:00 2001 From: Jason Tibbitts Date: Oct 02 2015 22:27:40 +0000 Subject: Files left out of the last commit. --- diff --git a/macros.python b/macros.python index f157926..5a84c9b 100644 --- a/macros.python +++ b/macros.python @@ -18,9 +18,8 @@ %with_python3 1 # Given the base package name, return the python module name by stripping a -# "python-" prefix if present. -# XXX We need a way to override this. Maybe just defining %py_modname in the -# spec will work.... +# "python-" prefix if present. If somehow the packagename doesn't match the +# module name, %py_modname can be defined in the spec. %py_modname() %{lua: function starts(str, prefix) return string.sub(str, 1, string.len(prefix)) == prefix @@ -39,12 +38,62 @@ %py_modname_ver() %{expand: %py_modname-%version} -# A macro to both set the main package description and define the description -# to be used by the %py_subpackages macro. For convenience, if multiple lines -# are provided, the first will be removed, which allows the macro to look a bit -# more like the regular %description section but also allow single-line -# descriptions. +# A macro which emulates the syntax of the %description section. Since the +# contents of the description is not available via any macro, there is +# technically no way to do this using the rpm macro language. However, rpm +# always has the spec file open as file descriptor 3, so we can reopen +# /proc/self/fd/3 and parse the spec directly. This is a rather scary hack, +# but the posix.unistd module isn't available so dup isn't there. RPM +# provides no way to directly access the spec from within lua and no other way +# to access the package description. %py_description() %{lua: + -- Get a handle to the spec file + local specfile = io.open("/proc/self/fd/3", "r") + local seenblank = false + local line, desc +\ + -- Read until the %py_description macro invocation + repeat + line = specfile:read() + -- io.stderr:write("S> " .. line .. "\\n") + until line == "%py_description" +\ + -- Now read in until the next line beginning with '%' or two blank lines in a row + line = specfile:read() + while string.sub(line, 1, 1) ~= '%' and not (seenblank and string.len(line) == 0) do + -- io.stderr:write("R> " .. line .. "\\n") + if desc == nil then + desc = line .. "\\n" + else + desc = desc .. line .. "\\n" + end + if string.len(line) == 0 then + seenblank = true + end + line = specfile:read() + end +\ + -- If necessary, remove the extra blank line we read + if seenblank then + desc = desc:sub(1, -2) + end +\ + local macro = string.gsub("_python_description "..desc, "\\n", "\\\\\\n" ) + rpm.define(macro) + print("%description") + -- RPM will continue parsing the spec file and will see the text just after + -- this macro as the contents of the %description section. +\ +--[[ +# Below is a different macro which will less closely emulate the %description +# section. It requires a curly bracket after the '%' on the macro invocation line, as well +# as one after the last line of the description text. It also requires some +# text (even a single space) on the first line after the macro name. +\ +# For convenience, if multiple lines are provided, the first will be removed, +# which allows the macro to look a bit more like the regular %description +# section but also allow single-line descriptions. +\ local desc = rpm.expand("%*") local linecount = 0 \ @@ -54,7 +103,7 @@ linecount = linecount + 1 end \ - -- Perhaps remove teh first line + -- Perhaps remove the first line if linecount > 1 then local pos = string.find(desc, "\\n") desc = string.sub(desc, pos + 1) @@ -63,9 +112,13 @@ -- Strip leading whitespace from the first line in case it sneaks in desc = string.match(desc, "^%s*(.*)$") \ - rpm.define(string.format("_python_description %s", desc)) + local macro = string.gsub("_python_description "..desc, "\\n", "\\\\\\n" ) + io.stderr:write(macro) + rpm.define(macro) print("%description\\n") print(desc) +\ +--]] } %py_prep() %{lua: \ @@ -113,6 +166,8 @@ end\ -- io.stderr:write(py .. "\\n") if tonumber(rpm.expand("0%{?with_" .. py .. "}")) > 0 then expandedargs = rpm.expand(args) +\ + print("pushd .rpm." .. py .. "\\n")\ print(rpm.expand("PYTHONPATH=%(pwd) %{__" .. py .. "}") .. " " .. expandedargs) print("\\n") print("popd" .. "\\n") @@ -167,6 +222,7 @@ end\ local pypkgprefix = string.format("%s-", pypkgname) local pysubpkgname = string.format("%s-%s", pypkgname, name) local newhdr = string.gsub(hdr, "python%d?-", pypkgprefix) + local newdesc = string.gsub(desc, "python%d", pypkgname) \ print(string.format("\\n%%package -n %s\\n", pysubpkgname)) print(newhdr) @@ -177,7 +233,6 @@ end\ print(rpm.expand(string.format("%%{python_provide %s}\\n", pysubpkgname))) print("\\n") print("%description -n " .. pysubpkgname .. "\\n") - newdesc = string.gsub(desc, "python%d", pypkgname) print(newdesc) print("\\n") end diff --git a/test1.spec b/test1.spec index d475369..ee324f5 100644 --- a/test1.spec +++ b/test1.spec @@ -9,7 +9,7 @@ URL: http://cheeseshop.python.org/pypi/simplegeneric Source0: http://pypi.python.org/packages/source/s/%{py_modname}/%{py_modname}-%{version}.zip BuildArch: noarch -BuildRequires: python-devel +BuildRequires: python2-devel BuildRequires: python-setuptools %if 0%{?with_python3} BuildRequires: python3-devel @@ -17,12 +17,12 @@ BuildRequires: python3-setuptools BuildRequires: /usr/bin/2to3 %endif -%{py_description asdfasdfadsf +%py_description The simplegeneric module lets you define simple single-dispatch generic functions, akin to Python's built-in generic functions like len(), iter() and so on. However, instead of using specially-named methods, these generic functions use simple lookup tables, akin to those used by e.g. pickle.dump() -and other generic functions found in the Python standard library.} +and other generic functions found in the Python standard library. %py_subpackages @@ -40,7 +40,7 @@ and other generic functions found in the Python standard library.} %check -%py_test setup.py test %{py_modname} +%py_test setup.py test %files -n python2-%{py_modname}