Blame SOURCES/macros.python

51cf4a
# unversioned macros: used with user defined __python, no longer part of rpm >= 4.15
51cf4a
# __python is defined to error by default in the srpm macros
6f4bc5
# nb: $RPM_BUILD_ROOT is not set when the macros are expanded (at spec parse time)
6f4bc5
#     so we set it manually (to empty string), making our Python prefer the correct install scheme location
6f4bc5
%python_sitelib %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_path('purelib'))")
6f4bc5
%python_sitearch %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_path('platlib'))")
6f4bc5
%python_version %(RPM_BUILD_ROOT= %{__python} -Esc "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))")
6f4bc5
%python_version_nodots %(RPM_BUILD_ROOT= %{__python} -Esc "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")
6f4bc5
%python_platform %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_platform())")
6f4bc5
%python_platform_triplet %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_config_var('MULTIARCH'))")
6f4bc5
%python_ext_suffix %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
51cf4a
51cf4a
%py_setup setup.py
51cf4a
%py_shbang_opts -s
51cf4a
%py_shbang_opts_nodash %(opts=%{py_shbang_opts}; echo ${opts#-})
51cf4a
%py_shebang_flags %(opts=%{py_shbang_opts}; echo ${opts#-})
51cf4a
%py_shebang_fix %{expand:\\\
51cf4a
  if [ -f /usr/bin/pathfix%{python_version}.py ]; then
51cf4a
    pathfix=/usr/bin/pathfix%{python_version}.py
51cf4a
  else
51cf4a
    # older versions of Python don't have it and must BR /usr/bin/pathfix.py from python3-devel explicitly
51cf4a
    pathfix=/usr/bin/pathfix.py
51cf4a
  fi
51cf4a
  if [ -z "%{?py_shebang_flags}" ]; then
51cf4a
    shebang_flags="-k"
51cf4a
  else
51cf4a
    shebang_flags="-ka%{py_shebang_flags}"
51cf4a
  fi
51cf4a
  $pathfix -pni %{__python} $shebang_flags}
51cf4a
51cf4a
# Use the slashes after expand so that the command starts on the same line as
51cf4a
# the macro
51cf4a
%py_build() %{expand:\\\
51cf4a
  CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
51cf4a
  %{__python} %{py_setup} %{?py_setup_args} build --executable="%{__python} %{py_shbang_opts}" %{?*}
51cf4a
}
51cf4a
51cf4a
%py_build_egg() %{expand:\\\
51cf4a
  CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
51cf4a
  %{__python} %{py_setup} %{?py_setup_args} bdist_egg %{?*}
51cf4a
}
51cf4a
51cf4a
%py_build_wheel() %{expand:\\\
51cf4a
  CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
51cf4a
  %{__python} %{py_setup} %{?py_setup_args} bdist_wheel %{?*}
51cf4a
}
51cf4a
51cf4a
%py_install() %{expand:\\\
51cf4a
  CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
51cf4a
  %{__python} %{py_setup} %{?py_setup_args} install -O1 --skip-build --root %{buildroot} %{?*}
51cf4a
  rm -rfv %{buildroot}%{_bindir}/__pycache__
51cf4a
}
51cf4a
51cf4a
%py_install_egg() %{expand:\\\
51cf4a
  mkdir -p %{buildroot}%{python_sitelib}
51cf4a
  %{__python} -m easy_install -m --prefix %{buildroot}%{_prefix} -Z dist/*-py%{python_version}.egg %{?*}
51cf4a
  rm -rfv %{buildroot}%{_bindir}/__pycache__
51cf4a
}
51cf4a
51cf4a
%py_install_wheel() %{expand:\\\
51cf4a
  %{__python} -m pip install -I dist/%{1} --root %{buildroot} --no-deps --no-index --no-warn-script-location
51cf4a
  rm -rfv %{buildroot}%{_bindir}/__pycache__
51cf4a
  for distinfo in %{buildroot}%{python_sitelib}/*.dist-info %{buildroot}%{python_sitearch}/*.dist-info; do
51cf4a
    if [ -f ${distinfo}/direct_url.json ]; then
51cf4a
      rm -fv ${distinfo}/direct_url.json
51cf4a
      sed -i '/direct_url.json/d' ${distinfo}/RECORD
51cf4a
    fi
51cf4a
  done
51cf4a
}
51cf4a
51cf4a
# With $PATH and $PYTHONPATH set to the %%buildroot,
6f4bc5
# try to import the Python module(s) given as command-line args or read from file (-f).
6f4bc5
# Respect the custom values of %%py_shebang_flags or set nothing if it's undefined.
6f4bc5
# Filter and check import on only top-level modules using -t flag.
6f4bc5
# Exclude unwanted modules by passing their globs to -e option.
51cf4a
# Useful as a smoke test in %%check when running tests is not feasible.
6f4bc5
# Use spaces or commas as separators if providing list directly.
6f4bc5
# Use newlines as separators if providing list in a file.
6f4bc5
%py_check_import(e:tf:) %{expand:\\\
51cf4a
  PATH="%{buildroot}%{_bindir}:$PATH"\\\
51cf4a
  PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python_sitearch}:%{buildroot}%{python_sitelib}}"\\\
6f4bc5
  _PYTHONSITE="%{buildroot}%{python_sitearch}:%{buildroot}%{python_sitelib}"\\\
51cf4a
  PYTHONDONTWRITEBYTECODE=1\\\
6f4bc5
  %{lua:
6f4bc5
  local command = "%{__python} "
6f4bc5
  if rpm.expand("%{?py_shebang_flags}") ~= "" then
6f4bc5
    command = command .. "-%{py_shebang_flags}"
6f4bc5
  end
6f4bc5
  command = command .. " %{_rpmconfigdir}/redhat/import_all_modules.py "
6f4bc5
  -- handle multiline arguments correctly, see https://bugzilla.redhat.com/2018809
6f4bc5
  local args=rpm.expand('%{?**}'):gsub("[%s\\\\]*%s+", " ")
6f4bc5
  print(command .. args)
6f4bc5
  }
51cf4a
}
51cf4a
51cf4a
%python_provide() %{lua:
51cf4a
  local python = require "fedora.srpm.python"
51cf4a
  function string.starts(String,Start)
51cf4a
    return string.sub(String,1,string.len(Start))==Start
51cf4a
  end
51cf4a
  local package = rpm.expand("%{?1}")
51cf4a
  local vr = rpm.expand("%{?epoch:%{epoch}:}%{version}-%{release}")
51cf4a
  local provides = python.python_altprovides(package, vr)
51cf4a
  local default_python3_pkgversion = rpm.expand("%{__default_python3_pkgversion}")
51cf4a
  if (string.starts(package, "python3-")) then
51cf4a
    for i, provide in ipairs(provides) do
51cf4a
      print("\\nProvides: " .. provide)
51cf4a
    end
51cf4a
    --Obsoleting the previous default python package (if it doesn't have isa)
51cf4a
    if (string.sub(package, "-1") ~= ")") then
51cf4a
      print("\\nObsoletes: python-")
51cf4a
      print(string.sub(package,9,string.len(package)))
51cf4a
      print(" < " .. vr)
51cf4a
    end
51cf4a
  elseif (string.starts(package, "python" .. default_python3_pkgversion .. "-")) then
51cf4a
    for i, provide in ipairs(provides) do
51cf4a
      print("\\nProvides: " .. provide)
51cf4a
    end
51cf4a
    --Obsoleting the previous default python package (if it doesn't have isa)
51cf4a
    if (string.sub(package, "-1") ~= ")") then
51cf4a
      print("\\nObsoletes: python-")
51cf4a
      print(string.sub(package,8+string.len(default_python3_pkgversion),string.len(package)))
51cf4a
      print(" < " .. vr)
51cf4a
    end
51cf4a
  elseif (string.starts(package, "python")) then
51cf4a
    --No unversioned provides as other python3 cases are not the default
51cf4a
  elseif (string.starts(package, "pypy")) then
51cf4a
    --No unversioned provides as pypy is not default either
51cf4a
  else
51cf4a
    print("%python_provide: ERROR: ")
51cf4a
    print(package)
51cf4a
    print(" not recognized.")
51cf4a
  end
51cf4a
}
51cf4a
51cf4a
%python_disable_dependency_generator() \
51cf4a
%undefine __pythondist_requires \
51cf4a
%{nil}