Blame SOURCES/macros.python3.11

ec2891
%__python3 /usr/bin/python3.11
ec2891
%python3_pkgversion 3.11
ec2891
ec2891
# The following are macros from macros.python3 in Fedora that are newer/different than those in the python3-rpm-macros package in RHEL.
ec2891
# These macros overwrite/supercede some of the macros in the python3-rpm-macros package in RHEL.
ec2891
ec2891
# nb: $RPM_BUILD_ROOT is not set when the macros are expanded (at spec parse time)
ec2891
#     so we set it manually (to empty string), making our Python prefer the correct install scheme location
ec2891
# platbase/base is explicitly set to %%{_prefix} to support custom values, such as /app for flatpaks
ec2891
%python3_sitelib %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_path('purelib', vars={'platbase': '%{_prefix}', 'base': '%{_prefix}'}))")
ec2891
%python3_sitearch %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_path('platlib', vars={'platbase': '%{_prefix}', 'base': '%{_prefix}'}))")
ec2891
%python3_version %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))")
ec2891
%python3_version_nodots %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")
ec2891
%python3_platform %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_platform())")
ec2891
%python3_platform_triplet %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('MULTIARCH'))")
ec2891
%python3_ext_suffix %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
ec2891
%python3_cache_tag %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; print(sys.implementation.cache_tag)")
ec2891
ec2891
%_py3_shebang_s s
ec2891
%_py3_shebang_P %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; print('P' if hasattr(sys.flags, 'safe_path') else '')")
ec2891
%py3_shbang_opts -%{?_py3_shebang_s}%{?_py3_shebang_P}
ec2891
ec2891
%py3_install() %{expand:\\\
ec2891
  CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
ec2891
  %{__python3} %{py_setup} %{?py_setup_args} install -O1 --skip-build --root %{buildroot} --prefix %{_prefix} %{?*}
ec2891
  rm -rfv %{buildroot}%{_bindir}/__pycache__
ec2891
}
ec2891
ec2891
%py3_install_egg() %{expand:\\\
ec2891
  mkdir -p %{buildroot}%{python3_sitelib}
ec2891
  %{__python3} -m easy_install -m --prefix %{buildroot}%{_prefix} -Z dist/*-py%{python3_version}.egg %{?*}
ec2891
  rm -rfv %{buildroot}%{_bindir}/__pycache__
ec2891
}
ec2891
ec2891
%py3_install_wheel() %{expand:\\\
ec2891
  %{__python3} -m pip install -I dist/%{1} --root %{buildroot} --prefix %{_prefix} --no-deps --no-index --no-warn-script-location
ec2891
  rm -rfv %{buildroot}%{_bindir}/__pycache__
ec2891
  for distinfo in %{buildroot}%{python3_sitelib}/*.dist-info %{buildroot}%{python3_sitearch}/*.dist-info; do
ec2891
    if [ -f ${distinfo}/direct_url.json ]; then
ec2891
      rm -fv ${distinfo}/direct_url.json
ec2891
      sed -i '/direct_url.json/d' ${distinfo}/RECORD
ec2891
    fi
ec2891
  done
ec2891
}
ec2891
ec2891
# With $PATH and $PYTHONPATH set to the %%buildroot,
ec2891
# try to import the Python 3 module(s) given as command-line args or read from file (-f).
ec2891
# Respect the custom values of %%py3_shebang_flags or set nothing if it's undefined.
ec2891
# Filter and check import on only top-level modules using -t flag.
ec2891
# Exclude unwanted modules by passing their globs to -e option.
ec2891
# Useful as a smoke test in %%check when running tests is not feasible.
ec2891
# Use spaces or commas as separators if providing list directly.
ec2891
# Use newlines as separators if providing list in a file.
ec2891
%py3_check_import(e:tf:) %{expand:\\\
ec2891
  PATH="%{buildroot}%{_bindir}:$PATH"\\\
ec2891
  PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
ec2891
  _PYTHONSITE="%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}"\\\
ec2891
  PYTHONDONTWRITEBYTECODE=1\\\
ec2891
  %{lua:
ec2891
  local command = "%{__python3} "
ec2891
  if rpm.expand("%{?py3_shebang_flags}") ~= "" then
ec2891
    command = command .. "-%{py3_shebang_flags}"
ec2891
  end
ec2891
  command = command .. " %{_rpmconfigdir}/redhat/import_all_modules.py "
ec2891
  -- handle multiline arguments correctly, see https://bugzilla.redhat.com/2018809
ec2891
  local args=rpm.expand('%{?**}'):gsub("[%s\\\\]*%s+", " ")
ec2891
  print(command .. args)
ec2891
  }
ec2891
}
ec2891
ec2891
%pytest %{expand:\\\
ec2891
  CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
ec2891
  PATH="%{buildroot}%{_bindir}:$PATH"\\\
ec2891
  PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
ec2891
  PYTHONDONTWRITEBYTECODE=1\\\
ec2891
  %{?__pytest_addopts:PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} %{__pytest_addopts}"}\\\
ec2891
  %__pytest}