8d3d1dd
%python3_sitelib %(%{__python3} -Ic "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
8d3d1dd
%python3_sitearch %(%{__python3} -Ic "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")
84ed1ab
%python3_version %(%{__python3} -Ic "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))")
84ed1ab
%python3_version_nodots %(%{__python3} -Ic "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")
1ea9947
%python3_platform %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_platform())")
06987f5
%python3_platform_triplet %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('MULTIARCH'))")
06987f5
%python3_ext_suffix %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
Orion Poplawski ec28c77
%py3dir %{_builddir}/python3-%{name}-%{version}-%{release}
Orion Poplawski ec28c77
Orion Poplawski ec28c77
%py3_shbang_opts -s
e9f07b7
%py3_shbang_opts_nodash %(opts=%{py3_shbang_opts}; echo ${opts#-})
7237192
%py3_shebang_flags %(opts=%{py3_shbang_opts}; echo ${opts#-})
1979a78
%py3_shebang_fix %{expand:\\\
1979a78
  if [ -f /usr/bin/pathfix%{python3_version}.py ]; then
1979a78
    pathfix=/usr/bin/pathfix%{python3_version}.py
1979a78
  else
1979a78
    # older versions of Python don't have it and must BR /usr/bin/pathfix.py from python3-devel explicitly
1979a78
    pathfix=/usr/bin/pathfix.py
1979a78
  fi
e5429a7
  if [ -z "%{?py3_shebang_flags}" ]; then
e5429a7
    shebang_flags="-k"
e5429a7
  else
e5429a7
    shebang_flags="-ka%{py3_shebang_flags}"
e5429a7
  fi
e5429a7
  $pathfix -pni %{__python3} $shebang_flags}
Orion Poplawski ec28c77
Orion Poplawski 5ca1f52
# Use the slashes after expand so that the command starts on the same line as
Orion Poplawski 5ca1f52
# the macro
Orion Poplawski 5ca1f52
%py3_build() %{expand:\\\
4904408
  CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
4904408
  %{__python3} %{py_setup} %{?py_setup_args} build --executable="%{__python3} %{py3_shbang_opts}" %{?*}
Orion Poplawski ec28c77
}
Orion Poplawski ec28c77
Orion Poplawski 5ca1f52
%py3_build_egg() %{expand:\\\
4904408
  CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
4904408
  %{__python3} %{py_setup} %{?py_setup_args} bdist_egg %{?*}
Orion Poplawski e7af332
}
Orion Poplawski e7af332
Orion Poplawski 5ca1f52
%py3_build_wheel() %{expand:\\\
4904408
  CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
4904408
  %{__python3} %{py_setup} %{?py_setup_args} bdist_wheel %{?*}
Orion Poplawski f798c43
}
Orion Poplawski f798c43
Orion Poplawski 5ca1f52
%py3_install() %{expand:\\\
4904408
  CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
4904408
  %{__python3} %{py_setup} %{?py_setup_args} install -O1 --skip-build --root %{buildroot} %{?*}
69b1b30
  rm -rfv %{buildroot}%{_bindir}/__pycache__
Orion Poplawski ec28c77
}
Orion Poplawski f798c43
Orion Poplawski 5ca1f52
%py3_install_egg() %{expand:\\\
Orion Poplawski f798c43
  mkdir -p %{buildroot}%{python3_sitelib}
69b1b30
  %{__python3} -m easy_install -m --prefix %{buildroot}%{_prefix} -Z dist/*-py%{python3_version}.egg %{?*}
2314fd9
  rm -rfv %{buildroot}%{_bindir}/__pycache__
Orion Poplawski f798c43
}
Orion Poplawski e7af332
Orion Poplawski 5ca1f52
%py3_install_wheel() %{expand:\\\
06ee391
  %{__python3} -m pip install -I dist/%{1} --root %{buildroot} --no-deps --no-index --no-warn-script-location
2314fd9
  rm -rfv %{buildroot}%{_bindir}/__pycache__
daf7d32
  for distinfo in %{buildroot}%{python3_sitelib}/*.dist-info %{buildroot}%{python3_sitearch}/*.dist-info; do
daf7d32
    if [ -f ${distinfo}/direct_url.json ]; then
daf7d32
      rm -fv ${distinfo}/direct_url.json
daf7d32
      sed -i '/direct_url.json/d' ${distinfo}/RECORD
daf7d32
    fi
daf7d32
  done
Orion Poplawski a73eb24
}
6c63a5b
ca6e522
# With $PATH and $PYTHONPATH set to the %%buildroot,
41f5962
# try to import the Python 3 module(s) given as command-line args or read from file (-f).
75a3c6b
# Respect the custom values of %%py3_shebang_flags or set nothing if it's undefined.
41f5962
# Filter and check import on only top-level modules using -t flag.
41f5962
# Exclude unwanted modules by passing their globs to -e option.
ca6e522
# Useful as a smoke test in %%check when running tests is not feasible.
41f5962
# Use spaces or commas as separators if providing list directly.
41f5962
# Use newlines as separators if providing list in a file.
41f5962
%py3_check_import(e:tf:) %{expand:\\\
ca6e522
  PATH="%{buildroot}%{_bindir}:$PATH"\\\
ca6e522
  PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
ddc1b5c
  _PYTHONSITE="%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}"\\\
ca6e522
  PYTHONDONTWRITEBYTECODE=1\\\
208372b
  %{lua:
75a3c6b
  local command = "%{__python3} "
75a3c6b
  if rpm.expand("%{?py3_shebang_flags}") ~= "" then
75a3c6b
    command = command .. "-%{py3_shebang_flags}"
75a3c6b
  end
75a3c6b
  command = command .. " %{_rpmconfigdir}/redhat/import_all_modules.py "
208372b
  -- handle multiline arguments correctly, see https://bugzilla.redhat.com/2018809
75a3c6b
  local args=rpm.expand('%{?**}'):gsub("[%s\\\\]*%s+", " ")
75a3c6b
  print(command .. args)
75a3c6b
  }
75a3c6b
}
ca6e522
6c63a5b
# This only supports Python 3.5+ and will never work with Python 2.
6c63a5b
# Hence, it has no Python version in the name.
6c63a5b
%pycached() %{lua:
985a805
  path = rpm.expand("%{?*}")
6c63a5b
  if (string.sub(path, "-3") ~= ".py") then
6c63a5b
    rpm.expand("%{error:%%pycached can only be used with paths explicitly ending with .py}")
6c63a5b
  else
6c63a5b
    print(path)
6c63a5b
    pyminor = path:match("/python3.(%d+)/") or "*"
6c63a5b
    dirname = path:match("(.*/)")
6c63a5b
    modulename = path:match(".*/([^/]+).py")
6c63a5b
    print("\\n" .. dirname .. "__pycache__/" .. modulename .. ".cpython-3" .. pyminor .. "{,.opt-?}.pyc")
6c63a5b
  end
6c63a5b
}
0d3f1e6
0d3f1e6
# This is intended for Python 3 only, hence also no Python version in the name.
0253654
%__pytest /usr/bin/pytest%(test %{python3_pkgversion} == 3 || echo -%{python3_version})
0d3f1e6
%pytest %{expand:\\\
0d3f1e6
  CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
0d3f1e6
  PATH="%{buildroot}%{_bindir}:$PATH"\\\
0d3f1e6
  PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
0d3f1e6
  PYTHONDONTWRITEBYTECODE=1\\\
c6f5b94
  %{?__pytest_addopts:PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} %{__pytest_addopts}"}\\\
0d3f1e6
  %__pytest}