- Hardcode the default Python 3 version in the SRPM macros - Provide python38-foo for python3-foo and the other way around (future RHEL compatibility) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1812087 $ rpm --eval '%python_provide python38-setuptools' Provides: python-setuptools = %{version}-%{release} Provides: python3-setuptools = %{version}-%{release} Obsoletes: python-setuptools < %{version}-%{release} $ rpm --eval '%python_provide python3-setuptools' Provides: python-setuptools = %{version}-%{release} Provides: python38-setuptools = %{version}-%{release} Obsoletes: python-setuptools < %{version}-%{release} $ rpm --eval '%python_provide python39-setuptools' $ rpm --define 'python3_pkgversion 39' --eval '%python_provide python%{python3_pkgversion}-setuptools' To make the implementation of %python_provide easier, any names starting with "python" or "pypy" are recognized as valid arguments. Previously, this was an ERROR: $ rpm --eval '%python_provide pythonista' %python_provide: ERROR: pythonista not recognized. Now it is a no-op. The behavior was never documented and the change is backwards compatible for working spec files.
		
			
				
	
	
		
			140 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			140 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| # Define the Python interpreter paths in the SRPM macros so that
 | |
| # - they can be used in Build/Requires
 | |
| # - they can be used in non-Python packages where requiring pythonX-devel would
 | |
| #   be an overkill
 | |
| 
 | |
| # use the underscored macros to redefine the behavior of %%python3_version etc.
 | |
| %__python2 /usr/bin/python2
 | |
| %__python3 /usr/bin/python3
 | |
| 
 | |
| # use the non-underscored macros to refer to Python in spec, etc.
 | |
| %python2 %__python2
 | |
| %python3 %__python3
 | |
| 
 | |
| # For backwards compatibility only
 | |
| # See the comments in https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/22
 | |
| %__python /usr/bin/python
 | |
| 
 | |
| # Users can use %%python only if they redefined %%__python (e.g. to %%__python3)
 | |
| %python() %{lua:\
 | |
|     __python = rpm.expand("%__python")\
 | |
|     if __python == "/usr/bin/python" then\
 | |
|         rpm.expand("%{error:Cannot use %%python if %%__python wasn't redefined to something other than /usr/bin/python.}")\
 | |
|     else\
 | |
|         print(__python)\
 | |
|     end\
 | |
| }
 | |
| 
 | |
| # This specifies what packages are equal to the python3-... packages, in python_provide macro
 | |
| # E.g. in Fedora 32, python38-foo will provide python3-foo and vice versa
 | |
| %__default_python3_version 3.8
 | |
| %__default_python3_pkgversion %(echo %__default_python3_version | sed 's/\\.//')
 | |
| 
 | |
| # python3_pkgversion specifies the version of Python 3 in the distro.  It can be
 | |
| # a specific version (e.g. 34 in Fedora EPEL7)
 | |
| %python3_pkgversion 3
 | |
| 
 | |
| # Set to /bin/true to avoid %ifdefs and %{? in specfiles
 | |
| %__python3_other /bin/true
 | |
| %py3_other_build /bin/true
 | |
| %py3_other_install /bin/true
 | |
| 
 | |
| 
 | |
| 
 | |
| # === Macros for Build/Requires tags using Python dist tags ===
 | |
| # - https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages
 | |
| # - These macros need to be in macros.python-srpm, because BuildRequires tags
 | |
| #   get rendered as runtime requires into the metadata of SRPMs.
 | |
| 
 | |
| # Converts Python dist name to a canonical format
 | |
| %py_dist_name() %{lua:\
 | |
|         name = rpm.expand("%{?1:%{1}}");\
 | |
|         canonical = string.gsub(string.lower(name), "[^%w%.]+", "-");\
 | |
|         print(canonical);\
 | |
| }
 | |
| 
 | |
| # Creates Python 2 dist tag(s) after converting names to canonical format
 | |
| #   Needs to first put all arguments into a list, because invoking a different
 | |
| #   macro (%py_dist_name) overwrites them
 | |
| %py2_dist() %{lua:\
 | |
|         args = {}\
 | |
|         arg = 1\
 | |
|         while (true) do\
 | |
|                 name = rpm.expand("%{?" .. arg .. ":%{" .. arg .. "}}");\
 | |
|                 if (name == nil or name == '') then\
 | |
|                         break\
 | |
|                 end\
 | |
|                 args[arg] = name\
 | |
|                 arg = arg + 1\
 | |
|         end\
 | |
|         for arg, name in ipairs(args) do\
 | |
|                 canonical = rpm.expand("%py_dist_name " .. name);\
 | |
|                 print("python2dist(" .. canonical .. ") ");\
 | |
|         end\
 | |
| }
 | |
| 
 | |
| # Creates Python 3 dist tag(s) after converting names to canonical format
 | |
| #   Needs to first put all arguments into a list, because invoking a different
 | |
| #   macro (%py_dist_name) overwrites them
 | |
| %py3_dist() %{lua:\
 | |
|         args = {}\
 | |
|         arg = 1\
 | |
|         while (true) do\
 | |
|                 name = rpm.expand("%{?" .. arg .. ":%{" .. arg .. "}}");\
 | |
|                 if (name == nil or name == '') then\
 | |
|                         break\
 | |
|                 end\
 | |
|                 args[arg] = name\
 | |
|                 arg = arg + 1\
 | |
|         end\
 | |
|         for arg, name in ipairs(args) do\
 | |
|                 canonical = rpm.expand("%py_dist_name " .. name);\
 | |
|                 print("python3dist(" .. canonical .. ") ");\
 | |
|         end\
 | |
| }
 | |
| 
 | |
| # Macro to replace overly complicated references to PyPI source files.
 | |
| # Expands to the pythonhosted URL for a package
 | |
| # Accepts zero to three arguments:
 | |
| # 1:  The PyPI project name, defaulting to %srcname if it is defined, then
 | |
| #     %pypi_name if it is defined, then just %name.
 | |
| # 2:  The PYPI version, defaulting to %version.
 | |
| # 3:  The file extension, defaulting to "tar.gz".  (A period will be added
 | |
| #     automatically.)
 | |
| # Requires %__pypi_url and %__pypi_default_extension to be defined.
 | |
| %__pypi_url https://files.pythonhosted.org/packages/source/
 | |
| %__pypi_default_extension tar.gz
 | |
| 
 | |
| %pypi_source() %{lua:
 | |
|     local src = rpm.expand('%1')
 | |
|     local ver = rpm.expand('%2')
 | |
|     local ext = rpm.expand('%3')
 | |
|     local url = rpm.expand('%__pypi_url')
 | |
| \
 | |
|     -- If no first argument, try %srcname, then %pypi_name, then %name
 | |
|     -- Note that rpm leaves macros unchanged if they are not defined.
 | |
|     if src == '%1' then
 | |
|         src = rpm.expand('%srcname')
 | |
|     end
 | |
|     if src == '%srcname' then
 | |
|         src = rpm.expand('%pypi_name')
 | |
|     end
 | |
|     if src == '%pypi_name' then
 | |
|         src = rpm.expand('%name')
 | |
|     end
 | |
| \
 | |
|     -- If no second argument, use %version
 | |
|     if ver == '%2' then
 | |
|         ver = rpm.expand('%version')
 | |
|     end
 | |
| \
 | |
|     -- If no third argument, use the preset default extension
 | |
|     if ext == '%3' then
 | |
|         ext = rpm.expand('%__pypi_default_extension')
 | |
|     end
 | |
| \
 | |
|     local first = string.sub(src, 1, 1)
 | |
| \
 | |
|     print(url .. first .. '/' .. src .. '/' .. src .. '-' .. ver .. '.' .. ext)
 | |
| }
 |