]> TLD Linux GIT Repositories - packages/rpm.git/blob - rpm-pythondeps.patch
0b4a02aef2e79dcedde150e79d814bec47527608
[packages/rpm.git] / rpm-pythondeps.patch
1 diff -urN rpm-4.5.orig/macros.in rpm-4.5/macros.in
2 --- rpm-4.5.orig/macros.in      2019-06-01 18:55:39.553000000 +0200
3 +++ rpm-4.5/macros.in   2019-11-01 12:11:16.312000000 +0100
4 @@ -1404,25 +1404,46 @@
5  #
6  # Path to scripts to autogenerate python package dependencies,
7  #
8 -# Note: Used iff _use_internal_dependency_generator is non-zero. The
9 +# Note: Used if _use_internal_dependency_generator is non-zero. The
10  # helpers are also used by %{_rpmhome}/rpmdeps {--provides|--requires}.
11 -%__python_provides     /usr/bin/env PYVER=%py_ver %{_rpmhome}/pythondeps.sh --provides
12 -%__python_requires     /usr/bin/env PYVER=%py_ver %{_rpmhome}/pythondeps.sh --requires
13 -
14 -# Useful macros for building *.rpm python packages (for python > 1.6).
15 +%__python_provides      %{_rpmhome}/pythoneggs.py --provides
16 +%__python_requires      %{_rpmhome}/pythoneggs.py --requires
17  #
18 -%python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")
19 -%python_sitelib        %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
20 -%python_version        %(%{__python} -c "import sys; print(sys.version[0:3])")
21 +%python_sitearch %(%{__python} -c "import os; from distutils.sysconfig import get_python_lib; lib=get_python_lib(1); print os.path.islink(lib) and os.path.abspath(os.path.join(os.path.dirname(lib),os.readlink(lib))) or lib")
22 +%python_sitelib %(%{__python} -c "import os; from distutils.sysconfig import get_python_lib; lib=get_python_lib(); print os.path.islink(lib) and os.path.abspath(os.path.join(os.path.dirname(lib),os.readlink(lib))) or lib")
23 +%python_version %(%{__python} -c "import sys; print(sys.version[0:3])")
24 +
25 +# python main version
26 +%py_ver                 %(%{__python} -c "import sys; v=sys.version_info[:2]; print '%%d.%%d'%%v" 2>/dev/null || echo PYTHON-NOT-FOUND)
27 +%py_prefix              %(%{__python} -c "import sys; print sys.prefix" 2>/dev/null || echo PYTHON-NOT-FOUND)
28 +%py_platlibdir          %(%{__python} -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib(standard_lib=1,plat_specific=1)' 2>/dev/null || echo PYTHON-LIBDIR-NOT-FOUND)
29 +%py_purelibdir          %(%{__python} -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib(standard_lib=1,plat_specific=0)' 2>/dev/null || echo PYTHON-LIBDIR-NOT-FOUND)
30 +# backward compatibility
31 +%py_libdir              %py_purelibdir
32 +
33 +%py_platsitedir         %(%{__python} -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib(plat_specific=1)' 2>/dev/null || echo PYTHON-LIBDIR-NOT-FOUND)
34 +%py_puresitedir         %(%{__python} -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib()' 2>/dev/null || echo PYTHON-LIBDIR-NOT-FOUND)
35 +%py_sitedir             %py_puresitedir
36 +
37 +%py_dyndir              %{py_platlibdir}/lib-dynload
38 +
39 +%py_incdir              %(%{__python} -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_inc()' 2>/dev/null || echo PYTHON-INCLUDEDIR-NOT-FOUND)
40  
41  %py_compile(O)  \
42 -find %1 -name '*.pyc' -name '*.pyo' -exec rm -f {} \\; \
43 -%{__python} %{?O:-O} -c "import sys, os, compileall; br='%{buildroot}'; compileall.compile_dir(sys.argv[1], ddir=br and (sys.argv[1][len(os.path.abspath(br)):]+'/') or None)" %1 \
44 +find %1 -name '*.pyc' -exec rm -f {} \\; \
45 +%{__python} -c "import sys, os, compileall; br='%{buildroot}'; compileall.compile_dir(sys.argv[1], ddir=br and (sys.argv[1][len(os.path.abspath(br)):]+'/') or None)" %1 \
46 +%{-O: \
47 +find %1 -name '*.pyo' -exec rm -f {} \\; \
48 +%{__python} -O -c "import sys, os, compileall; br='%{buildroot}'; compileall.compile_dir(sys.argv[1], ddir=br and (sys.argv[1][len(os.path.abspath(br)):]+'/') or None)" %1 \
49 +}
50 +
51 +# pure python modules compilation
52 +%py_comp        %{__python} -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('%{buildroot}'):])"
53 +
54 +%py_ocomp       %{__python} -O -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('%{buildroot}'):])"
55  
56  %py_requires(d) \
57 -%define maxver %(%{__python} -c "import sys; a,b=sys.version_info[:2]; print '%%d.%%d'%%(a,b+1)" 2>/dev/null || echo PYTHON-NOT-FOUND) \
58 -BuildRequires: python %{-d:python-devel} \
59 -PreReq: python >= %{python_version}, python < %{maxver}
60 +BuildRequires: %{__python} %{-d:python-devel}
61  
62  #------------------------------------------------------------------------
63  # php(...) configuration.
64 diff -urN rpm-4.5.orig/scripts/Makefile.am rpm-4.5/scripts/Makefile.am
65 --- rpm-4.5.orig/scripts/Makefile.am    2019-06-01 18:55:39.553000000 +0200
66 +++ rpm-4.5/scripts/Makefile.am 2019-11-01 12:03:59.288000000 +0100
67 @@ -12,7 +12,8 @@
68         find-requires.perl freshen.sh gendiff getpo.sh http.req \
69         check-java-closure.sh java.prov.sh java.req.sh \
70         javadeps.sh libtooldeps.sh pkgconfigdeps.sh \
71 -       perldeps.pl perl.prov perl.req pythondeps.sh mimetypedeps.sh \
72 +       perldeps.pl perl.prov perl.req pythondeps.sh pythoneggs.py \
73 +       mimetypedeps.sh \
74         php.prov php.req rpm2cpio \
75         rpmdb_loadcvt rpmdiff rpmdiff.cgi \
76         rpm.daily rpm.log rpm.xinetd \
77 @@ -39,7 +40,8 @@
78         find-provides.perl \
79         find-requires.perl getpo.sh http.req \
80         javadeps.sh libtooldeps.sh pkgconfigdeps.sh \
81 -       perldeps.pl perl.prov perl.req pythondeps.sh mimetypedeps.sh \
82 +       perldeps.pl perl.prov perl.req pythondeps.sh pythoneggs.py \
83 +       mimetypedeps.sh \
84         php.prov php.req \
85         rpmdb_loadcvt \
86         rpm.daily rpm.log rpm.xinetd \
87 diff -urN rpm-4.5.orig/scripts/pythoneggs.py rpm-4.5/scripts/pythoneggs.py
88 --- rpm-4.5.orig/scripts/pythoneggs.py  1970-01-01 01:00:00.000000000 +0100
89 +++ rpm-4.5/scripts/pythoneggs.py       2019-03-09 02:30:08.000000000 +0100
90 @@ -0,0 +1,237 @@
91 +#!/usr/bin/python2
92 +# -*- coding: utf-8 -*-
93 +#
94 +# Copyright 2010 Per Ã˜yvind Karlsen <peroyvind@mandriva.org>
95 +#
96 +# This program is free software. It may be redistributed and/or modified under
97 +# the terms of the LGPL version 2.1 (or later).
98 +#
99 +# RPM5 python (egg) dependency generator.
100 +#
101 +
102 +from getopt import getopt
103 +from os.path import basename, dirname, isdir, sep, splitext
104 +from sys import argv, stdin, version
105 +from pkg_resources import Distribution, FileMetadata, PathMetadata
106 +from distutils.sysconfig import get_python_lib
107 +from subprocess import Popen, PIPE, STDOUT
108 +import os
109 +import platform
110 +import re
111 +
112 +opts, args = getopt(argv[1:], 'hPRSCOEb:',
113 +        ['help', 'provides', 'requires', 'suggests', 'conflicts', 'obsoletes', 'extras','buildroot='])
114 +
115 +Provides = False
116 +Requires = False
117 +Suggests = False
118 +Conflicts = False
119 +Obsoletes = False
120 +Extras = False
121 +buildroot = None
122 +
123 +def make_pldver(raw):
124 +    if re.match(r'^[0-9\.]+$', raw) == None:
125 +       pldver = re.sub(r'([\d\.]+)(.+)', r'\1-0.\2', raw)
126 +    else:
127 +       pldver = raw
128 +    return pldver
129 +
130 +for o, a in opts:
131 +    if o in ('-h', '--help'):
132 +        print '-h, --help\tPrint help'
133 +        print '-P, --provides\tPrint Provides'
134 +        print '-R, --requires\tPrint Requires'
135 +        print '-S, --suggests\tPrint Suggests'
136 +        print '-C, --conflicts\tPrint Conflicts'
137 +        print '-O, --obsoletes\tPrint Obsoletes (unused)'
138 +        print '-E, --extras\tPrint Extras '
139 +        print '-b, --buildroot\tBuildroot for package '
140 +        exit(1)
141 +    elif o in ('-P', '--provides'):
142 +        Provides = True
143 +    elif o in ('-R', '--requires'):
144 +        Requires = True
145 +    elif o in ('-S', '--suggests'):
146 +        Suggests = True
147 +    elif o in ('-C', '--conflicts'):
148 +        Conflicts = True
149 +    elif o in ('-O', '--obsoletes'):
150 +        Obsoletes = True
151 +    elif o in ('-E', '--extras'):
152 +        Extras = True
153 +    elif o in ('-b', '--buildroot'):
154 +        buildroot = a
155 +
156 +def is_exe(fpath):
157 +    return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
158 +
159 +typelib_check = False
160 +
161 +if is_exe("/usr/lib/rpm/gi-find-deps.sh") and is_exe("/usr/bin/g-ir-dep-tool"):
162 +    if not buildroot:
163 +        pass
164 +    else:
165 +        typelib_check = True
166 +
167 +if Requires:
168 +    py_abi = True
169 +else:
170 +    py_abi = False
171 +py_deps = {}
172 +if args:
173 +    files = args
174 +else:
175 +    files = stdin.readlines()
176 +
177 +for f in files:
178 +    f = f.strip()
179 +    lower = f.lower()
180 +    name = 'python(abi)'
181 +    # add dependency based on path, versioned if within versioned python directory
182 +    if py_abi and (lower.endswith('.py') or lower.endswith('.pyc') or lower.endswith('.pyo')):
183 +        if not name in py_deps:
184 +            py_deps[name] = []
185 +        purelib = get_python_lib(standard_lib=1, plat_specific=0).split(version[:3])[0]
186 +        platlib = get_python_lib(standard_lib=1, plat_specific=1).split(version[:3])[0]
187 +        for lib in (purelib, platlib):
188 +            if lib in f:
189 +                spec = ('==',f.split(lib)[1].split(sep)[0])
190 +                if not spec in py_deps[name]:
191 +                    py_deps[name].append(spec)
192 +        # Pipe files to find typelib requires 
193 +        if typelib_check:
194 +            p = Popen(['/usr/lib/rpm/gi-find-deps.sh', '-R',str(buildroot)], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
195 +            (stdoutdata, stderrdata) = p.communicate(input=str(f)+"\n")
196 +            
197 +            if stdoutdata and stdoutdata:
198 +                py_deps[stdoutdata.strip()]= ""
199 +
200 +    # XXX: hack to workaround RPM internal dependency generator not passing directories
201 +    dlower = dirname(lower)
202 +    if dlower.endswith('.egg') or \
203 +            dlower.endswith('.egg-info') or \
204 +            dlower.endswith('.egg-link'):
205 +        lower = dlower
206 +        f = dirname(f)
207 +    # Determine provide, requires, conflicts & suggests based on egg metadata
208 +    if lower.endswith('.egg') or \
209 +            lower.endswith('.egg-info') or \
210 +            lower.endswith('.egg-link'):
211 +        dist_name = basename(f)
212 +        if isdir(f):
213 +            path_item = dirname(f)
214 +            metadata = PathMetadata(path_item, f)
215 +        else:
216 +            path_item = f
217 +            metadata = FileMetadata(f)
218 +        dist = Distribution.from_location(path_item, dist_name, metadata)
219 +        if Provides:
220 +            # If egg metadata says package name is python, we provide python(abi)
221 +            if dist.key == 'python':
222 +                name = 'python(abi)'
223 +                if not name in py_deps:
224 +                    py_deps[name] = []
225 +                py_deps[name].append(('==', dist.py_version))
226 +            if dist.py_version .split(".")[0] == '3':
227 +                name = 'python3egg(%s)' % dist.key
228 +            else:
229 +                name = 'pythonegg(%s)' % dist.key
230 +            if not name in py_deps:
231 +                py_deps[name] = []
232 +            if dist.version:
233 +                spec = ('==', make_pldver(dist.version))
234 +                if not spec in py_deps[name]:
235 +                    py_deps[name].append(spec)
236 +        if Requires or (Suggests and dist.extras):
237 +            name = 'python(abi)'
238 +            # If egg metadata says package name is python, we don't add dependency on python(abi)
239 +            if dist.key == 'python':
240 +                py_abi = False
241 +                if name in py_deps:
242 +                    py_deps.pop(name)
243 +            elif py_abi and dist.py_version:
244 +                if not name in py_deps:
245 +                    py_deps[name] = []
246 +                spec = ('==', dist.py_version)
247 +                if not spec in py_deps[name]:
248 +                    py_deps[name].append(spec)
249 +            # fake python version for dist.requires(), so deps like
250 +            # [:python_version < '3']
251 +            # enum34
252 +            # will be handled correctly
253 +            old_python_version = platform.python_version
254 +            def new_python_version():
255 +                return dist.py_version
256 +            platform.python_version = new_python_version
257 +            deps = dist.requires()
258 +            if Suggests:
259 +                depsextras = dist.requires(extras=dist.extras)
260 +                if not Requires:
261 +                    for dep in reversed(depsextras):
262 +                        if dep in deps:
263 +                            depsextras.remove(dep)
264 +                deps = depsextras
265 +            platform.python_version = old_python_version
266 +            # add requires/suggests based on egg metadata
267 +            for dep in deps:
268 +                if dist.py_version .split(".")[0] == '3':
269 +                    name = 'python3egg(%s)' % dep.key
270 +                else:
271 +                    name = 'pythonegg(%s)' % dep.key
272 +                for spec in dep.specs:
273 +                    if spec[0] != '!=':
274 +                        if not name in py_deps:
275 +                            py_deps[name] = []
276 +                        plddep = (spec[0], make_pldver(spec[1]))
277 +                        if not plddep in py_deps[name]:
278 +                            py_deps[name].append(plddep)
279 +                if not dep.specs:
280 +                    py_deps[name] = []
281 +        # Unused, for automatic sub-package generation based on 'extras' from egg metadata
282 +        # TODO: implement in rpm later, or...?
283 +        if Extras:
284 +            deps = dist.requires()
285 +            extras = dist.extras
286 +            print extras
287 +            for extra in extras:
288 +                print '%%package\textras-%s' % extra
289 +                print 'Summary:\t%s extra for %s python egg' % (extra, dist.key)
290 +                print 'Group:\t\tDevelopment/Python'
291 +                depsextras = dist.requires(extras=[extra])
292 +                for dep in reversed(depsextras):
293 +                    if dep in deps:
294 +                        depsextras.remove(dep)
295 +                deps = depsextras
296 +                for dep in deps:
297 +                    for spec in dep.specs:
298 +                        if spec[0] == '!=':
299 +                            print 'Conflicts:\t%s %s %s' % (dep.key, '==', spec[1])
300 +                        else:
301 +                            print 'Requires:\t%s %s %s' % (dep.key, spec[0], spec[1])
302 +                print '%%description\t%s' % extra
303 +                print '%s extra for %s python egg' % (extra, dist.key)
304 +                print '%%files\t\textras-%s\n' % extra
305 +        if Conflicts:
306 +            # Should we really add conflicts for extras?
307 +            # Creating a meta package per extra with suggests on, which has
308 +            # the requires/conflicts in stead might be a better solution...
309 +            for dep in dist.requires(extras=dist.extras):
310 +                name = dep.key
311 +                for spec in dep.specs:
312 +                    if spec[0] == '!=':
313 +                        if not name in py_deps:
314 +                            py_deps[name] = []
315 +                        spec = ('==', spec[1])
316 +                        if not spec in py_deps[name]:
317 +                            py_deps[name].append(spec)
318 +names = py_deps.keys()
319 +names.sort()
320 +for name in names:
321 +    if py_deps[name]:
322 +        # Print out versioned provides, requires, suggests, conflicts
323 +        for spec in py_deps[name]:
324 +            print '%s %s %s' % (name, spec[0], spec[1])
325 +    else:
326 +        # Print out unversioned provides, requires, suggests, conflicts
327 +        print name