Blame SOURCES/macros.pyproject

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