Blame SOURCES/macros.pyproject

7ef706
# This is a directory where wheels are stored and installed from, relative to PWD
7ef706
%_pyproject_wheeldir %{_builddir}%{?buildsubdir:/%{buildsubdir}}/pyproject-wheeldir
7ef706
7ef706
# This is a directory used as TMPDIR, where pip copies sources to and builds from, relative to PWD
7ef706
# For proper debugsource packages, we create TMPDIR within PWD
7ef706
# See https://github.com/pypa/pip/issues/7555#issuecomment-595180864
7ef706
#
7ef706
# This will be used in debugsource package paths (applies to extension modules only)
7ef706
# NB: pytest collects tests from here if not hidden
7ef706
#     https://docs.pytest.org/en/latest/reference.html#confval-norecursedirs
7ef706
%_pyproject_builddir %{_builddir}%{?buildsubdir:/%{buildsubdir}}/.pyproject-builddir
7ef706
7ef706
%pyproject_files %{_builddir}/pyproject-files
7ef706
%_pyproject_modules %{_builddir}/pyproject-modules
7ef706
%_pyproject_ghost_distinfo %{_builddir}/pyproject-ghost-distinfo
7ef706
%_pyproject_record %{_builddir}/pyproject-record
7ef706
7ef706
# Avoid leaking %%{_pyproject_builddir} to pytest collection
7ef706
# https://bugzilla.redhat.com/show_bug.cgi?id=1935212
7ef706
# The value is read and used by the %%pytest and %%tox macros:
7ef706
%_set_pytest_addopts %global __pytest_addopts --ignore=%{_pyproject_builddir}
7ef706
7ef706
%pyproject_wheel() %{expand:\\\
7ef706
%_set_pytest_addopts
7ef706
mkdir -p "%{_pyproject_builddir}"
7ef706
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}" TMPDIR="%{_pyproject_builddir}" \\\
7ef706
%{__python3} -m pip wheel --wheel-dir %{_pyproject_wheeldir} --no-deps --use-pep517 --no-build-isolation --disable-pip-version-check --no-clean --progress-bar off --verbose .
7ef706
}
7ef706
7ef706
7ef706
%pyproject_build_lib %{expand:\\\
7ef706
$(
7ef706
pyproject_build_lib=()
7ef706
if [ -d build/lib.%{python3_platform}-%{python3_version} ]; then
7ef706
  pyproject_build_lib+=( "${PWD}/build/lib.%{python3_platform}-%{python3_version}" )
7ef706
fi
7ef706
if [ -d build/lib ]; then
7ef706
  pyproject_build_lib+=( "${PWD}/build/lib" )
7ef706
fi
7ef706
for directory in $(find "%{_pyproject_builddir}" -type d -wholename "%{_pyproject_builddir}/pip-req-build-*/build/lib.%{python3_platform}-%{python3_version}" 2>/dev/null); do
7ef706
  pyproject_build_lib+=( "${directory}" )
7ef706
done
7ef706
for directory in $(find "%{_pyproject_builddir}" -type d -wholename "%{_pyproject_builddir}/pip-req-build-*/build/lib" 2>/dev/null); do
7ef706
  pyproject_build_lib+=( "${directory}" )
7ef706
done
7ef706
echo $(IFS=:; echo "${pyproject_build_lib[*]}")
7ef706
)}
7ef706
7ef706
7ef706
%pyproject_install() %{expand:\\\
7ef706
specifier=$(ls %{_pyproject_wheeldir}/*.whl | xargs basename --multiple | sed -E 's/([^-]+)-([^-]+)-.+\\\.whl/\\\1==\\\2/')
7ef706
TMPDIR="%{_pyproject_builddir}" %{__python3} -m pip install --root %{buildroot} --no-deps --disable-pip-version-check --progress-bar off --verbose --ignore-installed --no-warn-script-location --no-index --no-cache-dir --find-links %{_pyproject_wheeldir} $specifier
7ef706
if [ -d %{buildroot}%{_bindir} ]; then
7ef706
  %py3_shebang_fix %{buildroot}%{_bindir}/*
7ef706
  rm -rfv %{buildroot}%{_bindir}/__pycache__
7ef706
fi
7ef706
rm -f %{_pyproject_ghost_distinfo}
7ef706
site_dirs=()
7ef706
# Process %%{python3_sitelib} if exists
7ef706
if [ -d %{buildroot}%{python3_sitelib} ]; then
7ef706
  site_dirs+=( "%{python3_sitelib}" )
7ef706
fi
7ef706
# Process %%{python3_sitearch} if exists and does not equal to %%{python3_sitelib}
7ef706
if [ %{buildroot}%{python3_sitearch} != %{buildroot}%{python3_sitelib} ] && [ -d %{buildroot}%{python3_sitearch} ]; then
7ef706
  site_dirs+=( "%{python3_sitearch}" )
7ef706
fi
7ef706
# Process all *.dist-info dirs in sitelib/sitearch
7ef706
for site_dir in ${site_dirs[@]}; do
7ef706
  for distinfo in %{buildroot}$site_dir/*.dist-info; do
7ef706
    echo "%ghost ${distinfo#%{buildroot}}" >> %{_pyproject_ghost_distinfo}
7ef706
    sed -i 's/pip/rpm/' ${distinfo}/INSTALLER
7ef706
    PYTHONPATH=%{_rpmconfigdir}/redhat \\
7ef706
      %{__python3} -B %{_rpmconfigdir}/redhat/pyproject_preprocess_record.py \\
7ef706
      --buildroot %{buildroot} --record ${distinfo}/RECORD --output %{_pyproject_record}
7ef706
    rm -fv ${distinfo}/RECORD
7ef706
    rm -fv ${distinfo}/REQUESTED
7ef706
  done
7ef706
done
7ef706
lines=$(wc -l %{_pyproject_ghost_distinfo} | cut -f1 -d" ")
7ef706
if [ $lines -ne 1 ]; then
7ef706
  echo -e "\\n\\nWARNING: %%%%pyproject_extras_subpkg won't work without explicit -i or -F, found $lines dist-info directories.\\n\\n" >&2
7ef706
  rm %{_pyproject_ghost_distinfo}  # any attempt to use this will fail
7ef706
fi
7ef706
}
7ef706
7ef706
7ef706
# Note: the three times nested questionmarked -i -f -F pattern means: If none of those options was used -- in that case, we inject our own -f
7ef706
%pyproject_extras_subpkg(n:i:f:F) %{expand:%{?python_extras_subpkg:%{python_extras_subpkg%{?!-i:%{?!-f:%{?!-F: -f %{_pyproject_ghost_distinfo}}}} %**}}}
7ef706
7ef706
7ef706
%pyproject_save_files() %{expand:\\\
7ef706
%{__python3} %{_rpmconfigdir}/redhat/pyproject_save_files.py \\
7ef706
  --output-files "%{pyproject_files}" \\
7ef706
  --output-modules "%{_pyproject_modules}" \\
7ef706
  --buildroot "%{buildroot}" \\
7ef706
  --sitelib "%{python3_sitelib}" \\
7ef706
  --sitearch "%{python3_sitearch}" \\
7ef706
  --python-version "%{python3_version}" \\
7ef706
  --pyproject-record "%{_pyproject_record}" \\
7ef706
  --prefix "%{_prefix}" \\
7ef706
  %{*}
7ef706
}
7ef706
7ef706
# -t - Process only top-level modules
7ef706
# -e - Exclude the module names matching given glob, may be used repeatedly
7ef706
%pyproject_check_import(e:t) %{expand:\\\
7ef706
if [ ! -f "%{_pyproject_modules}" ]; then
7ef706
  echo 'ERROR: %%%%pyproject_check_import only works when %%%%pyproject_save_files is used' >&2
7ef706
  exit 1
7ef706
fi
7ef706
%py3_check_import -f "%{_pyproject_modules}" %{?**}
7ef706
}
7ef706
7ef706
7ef706
%default_toxenv py%{python3_version_nodots}
7ef706
%toxenv %{default_toxenv}
7ef706
7ef706
7ef706
%pyproject_buildrequires(rRxtNe:) %{expand:\\\
7ef706
%{-R:%{-r:%{error:The -R and -r options are mutually exclusive}}}
7ef706
%{-N:
7ef706
%{-r:%{error:The -N and -r options are mutually exclusive}}
7ef706
%{-x:%{error:The -N and -x options are mutually exclusive}}
7ef706
%{-e:%{error:The -N and -e options are mutually exclusive}}
7ef706
%{-t:%{error:The -N and -t options are mutually exclusive}}
7ef706
}
7ef706
%{-e:%{expand:%global toxenv %(%{__python3} -s %{_rpmconfigdir}/redhat/pyproject_construct_toxenv.py %{?**})}}
7ef706
echo 'pyproject-rpm-macros'  # we already have this installed, but this way, it's repoqueryable
7ef706
echo 'python%{python3_pkgversion}-devel'
7ef706
echo 'python%{python3_pkgversion}dist(pip) >= 19'
7ef706
echo 'python%{python3_pkgversion}dist(packaging)'
7ef706
%{!-N:if [ -f pyproject.toml ]; then
7ef706
  echo 'python%{python3_pkgversion}dist(toml)'
7ef706
elif [ -f setup.py ]; then
7ef706
  # Note: If the default requirements change, also change them in the script!
7ef706
  echo 'python%{python3_pkgversion}dist(setuptools) >= 40.8'
7ef706
  echo 'python%{python3_pkgversion}dist(wheel)'
7ef706
else
7ef706
  echo 'ERROR: Neither pyproject.toml nor setup.py found, consider using %%%%pyproject_buildrequires -N <requirements-file> if this is not a Python package.' >&2
7ef706
  exit 1
7ef706
fi}
7ef706
# setuptools assumes no pre-existing dist-info
7ef706
rm -rfv *.dist-info/ >&2
7ef706
if [ -f %{__python3} ]; then
7ef706
  RPM_TOXENV="%{toxenv}" HOSTNAME="rpmbuild" %{__python3} -s %{_rpmconfigdir}/redhat/pyproject_buildrequires.py %{?!_python_no_extras_requires:--generate-extras} --python3_pkgversion %{python3_pkgversion} %{?**}
7ef706
fi
7ef706
}
7ef706
7ef706
7ef706
%tox(e:) %{expand:\\\
7ef706
TOX_TESTENV_PASSENV="${TOX_TESTENV_PASSENV:-*}" \\
7ef706
PYTHONDONTWRITEBYTECODE=1 \\
7ef706
PATH="%{buildroot}%{_bindir}:$PATH" \\
7ef706
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}" \\
7ef706
%{?__pytest_addopts:PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} %{__pytest_addopts}"} \\
7ef706
HOSTNAME="rpmbuild" \\
7ef706
%{__python3} -m tox --current-env -q --recreate -e "%{-e:%{-e*}}%{!-e:%{toxenv}}" %{?*}
7ef706
}