|
|
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 |
%python3_sitelib %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_path('purelib'))")
|
|
|
6f4bc5 |
%python3_sitearch %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_path('platlib'))")
|
|
|
6f4bc5 |
%python3_version %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))")
|
|
|
6f4bc5 |
%python3_version_nodots %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")
|
|
|
6f4bc5 |
%python3_platform %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_platform())")
|
|
|
6f4bc5 |
%python3_platform_triplet %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('MULTIARCH'))")
|
|
|
6f4bc5 |
%python3_ext_suffix %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
|
|
|
51cf4a |
%py3dir %{_builddir}/python3-%{name}-%{version}-%{release}
|
|
|
51cf4a |
|
|
|
51cf4a |
%py3_shbang_opts -s
|
|
|
51cf4a |
%py3_shbang_opts_nodash %(opts=%{py3_shbang_opts}; echo ${opts#-})
|
|
|
51cf4a |
%py3_shebang_flags %(opts=%{py3_shbang_opts}; echo ${opts#-})
|
|
|
51cf4a |
%py3_shebang_fix %{expand:\\\
|
|
|
51cf4a |
if [ -f /usr/bin/pathfix%{python3_version}.py ]; then
|
|
|
51cf4a |
pathfix=/usr/bin/pathfix%{python3_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 "%{?py3_shebang_flags}" ]; then
|
|
|
51cf4a |
shebang_flags="-k"
|
|
|
51cf4a |
else
|
|
|
51cf4a |
shebang_flags="-ka%{py3_shebang_flags}"
|
|
|
51cf4a |
fi
|
|
|
51cf4a |
$pathfix -pni %{__python3} $shebang_flags}
|
|
|
51cf4a |
|
|
|
51cf4a |
# Use the slashes after expand so that the command starts on the same line as
|
|
|
51cf4a |
# the macro
|
|
|
51cf4a |
%py3_build() %{expand:\\\
|
|
|
51cf4a |
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
|
|
|
51cf4a |
%{__python3} %{py_setup} %{?py_setup_args} build --executable="%{__python3} %{py3_shbang_opts}" %{?*}
|
|
|
51cf4a |
}
|
|
|
51cf4a |
|
|
|
51cf4a |
%py3_build_egg() %{expand:\\\
|
|
|
51cf4a |
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
|
|
|
51cf4a |
%{__python3} %{py_setup} %{?py_setup_args} bdist_egg %{?*}
|
|
|
51cf4a |
}
|
|
|
51cf4a |
|
|
|
51cf4a |
%py3_build_wheel() %{expand:\\\
|
|
|
51cf4a |
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
|
|
|
51cf4a |
%{__python3} %{py_setup} %{?py_setup_args} bdist_wheel %{?*}
|
|
|
51cf4a |
}
|
|
|
51cf4a |
|
|
|
51cf4a |
%py3_install() %{expand:\\\
|
|
|
51cf4a |
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
|
|
|
51cf4a |
%{__python3} %{py_setup} %{?py_setup_args} install -O1 --skip-build --root %{buildroot} %{?*}
|
|
|
51cf4a |
rm -rfv %{buildroot}%{_bindir}/__pycache__
|
|
|
51cf4a |
}
|
|
|
51cf4a |
|
|
|
51cf4a |
%py3_install_egg() %{expand:\\\
|
|
|
51cf4a |
mkdir -p %{buildroot}%{python3_sitelib}
|
|
|
51cf4a |
%{__python3} -m easy_install -m --prefix %{buildroot}%{_prefix} -Z dist/*-py%{python3_version}.egg %{?*}
|
|
|
51cf4a |
rm -rfv %{buildroot}%{_bindir}/__pycache__
|
|
|
51cf4a |
}
|
|
|
51cf4a |
|
|
|
51cf4a |
%py3_install_wheel() %{expand:\\\
|
|
|
51cf4a |
%{__python3} -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}%{python3_sitelib}/*.dist-info %{buildroot}%{python3_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 3 module(s) given as command-line args or read from file (-f).
|
|
|
6f4bc5 |
# Respect the custom values of %%py3_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 |
%py3_check_import(e:tf:) %{expand:\\\
|
|
|
51cf4a |
PATH="%{buildroot}%{_bindir}:$PATH"\\\
|
|
|
51cf4a |
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
|
|
|
6f4bc5 |
_PYTHONSITE="%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}"\\\
|
|
|
51cf4a |
PYTHONDONTWRITEBYTECODE=1\\\
|
|
|
6f4bc5 |
%{lua:
|
|
|
6f4bc5 |
local command = "%{__python3} "
|
|
|
6f4bc5 |
if rpm.expand("%{?py3_shebang_flags}") ~= "" then
|
|
|
6f4bc5 |
command = command .. "-%{py3_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 |
# This only supports Python 3.5+ and will never work with Python 2.
|
|
|
51cf4a |
# Hence, it has no Python version in the name.
|
|
|
51cf4a |
%pycached() %{lua:
|
|
|
51cf4a |
path = rpm.expand("%{?*}")
|
|
|
51cf4a |
if (string.sub(path, "-3") ~= ".py") then
|
|
|
51cf4a |
rpm.expand("%{error:%%pycached can only be used with paths explicitly ending with .py}")
|
|
|
51cf4a |
else
|
|
|
51cf4a |
print(path)
|
|
|
51cf4a |
pyminor = path:match("/python3.(%d+)/") or "*"
|
|
|
51cf4a |
dirname = path:match("(.*/)")
|
|
|
51cf4a |
modulename = path:match(".*/([^/]+).py")
|
|
|
51cf4a |
print("\\n" .. dirname .. "__pycache__/" .. modulename .. ".cpython-3" .. pyminor .. "{,.opt-?}.pyc")
|
|
|
51cf4a |
end
|
|
|
51cf4a |
}
|
|
|
51cf4a |
|
|
|
51cf4a |
# This is intended for Python 3 only, hence also no Python version in the name.
|
|
|
51cf4a |
%__pytest /usr/bin/pytest%(test %{python3_pkgversion} == 3 || echo -%{python3_version})
|
|
|
51cf4a |
%pytest %{expand:\\\
|
|
|
51cf4a |
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
|
|
|
51cf4a |
PATH="%{buildroot}%{_bindir}:$PATH"\\\
|
|
|
51cf4a |
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
|
|
|
51cf4a |
PYTHONDONTWRITEBYTECODE=1\\\
|
|
|
51cf4a |
%{?__pytest_addopts:PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} %{__pytest_addopts}"}\\\
|
|
|
51cf4a |
%__pytest}
|