-
Notifications
You must be signed in to change notification settings - Fork 183
/
build-with-pip.file
165 lines (149 loc) · 5.43 KB
/
build-with-pip.file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#File: with-with-pip
#pip_name: pip package name default is package name without starting py3
#PipDownloadSourceType: Only override the download source type e.g. none, all etc. Default is all
#PipDownloadOptions: override pip download sources options. Default is --no-deps%%20--no-binary%%3D:%%PipDownloadSourceType:
#PipBuildOptions: Override pip install options
#pkgsource: Override default source name e.g. source.tar.gz
#source0: Override default source
#Pip<Pre|Post><Section>: Extra macros to run extra commands for various sections e.g
#PipPostBuild to relocate hardcoded pyton paths
#define PipPostBuild perl -p -i -e "s|^#!.*python|#!/usr/bin/env python|" %{i}/bin/*
#PipPackageNameCommand to get the exact package name
#PipDepsMatch Command to find out pypi package dependencies
#PipDepsCommand to get package dependencies
#PipInstallCommand Command to install the package
#PipNoWheelDep: If set then do not add py3-wheel deps
## INITENV +PATH PYTHON3PATH %{i}/${PYTHON3_LIB_SITE_PACKAGES}
%if "%{?pip_package_pack_command:set}" != "set"
%define pip_package_pack_command tar -czf ${pip_package_srcfile} ${pip_package_dirname}
%endif
%if "%{?pip_package_unpack_command:set}" != "set"
%define pip_package_unpack_command tar -xzf ${pip_package_srcfile}
%endif
%if "%{?pip_name:set}" != "set"
%define pip_name %(echo %n | cut -f2-10 -d-)
%endif
%if "%{?PipDownloadSourceType:set}" != "set"
%define PipDownloadSourceType all
%endif
%if "%{?PipDownloadOptions:set}" != "set"
%define PipDownloadOptions --no-deps%%20--no-binary%%3D:%{PipDownloadSourceType}:
%endif
%if "%{?PipBuildOptions:set}" != "set"
%define PipBuildOptions %{nil}
%endif
%if "%{?pkgsource:set}" != "set"
%define pkgsource source.tar.gz
%endif
%if "%{?PipInstallOptions:set}" != "set"
%define PipInstallOptions %{nil}
%endif
%if "%{?PipDepsPost:set}" != "set"
%define PipDepsPost %{nil}
%endif
%if "%{?PipPackageNameCommand:set}" != "set"
%define PipPackageNameCommand pip3 show %{pip_name} --disable-pip-version-check | grep '^Name:' | sed 's|^Name: *||;s| ||g'
%endif
%if "%{?PipDepsMatch:set}" != "set"
%define PipDepsMatch grep "^${PKG_NAME} *%{realversion} *requires " | sed 's|,.*||;s|.* |py3-|'
%endif
%if "%{?PipDepsCommand:set}" != "set"
%define PipDepsCommand pip3 check --disable-pip-version-check | %{PipDepsMatch} %{PipDepsPost} | tr '\\n' ' '
%endif
%if "%{?PipInstallCommand:set}" != "set"
%define PipInstallCommand pip3 install --no-clean --no-deps --no-index --no-build-isolation --no-cache-dir --disable-pip-version-check --user -v %{PipInstallOptions} %{PipBuildOptions} $PIPFILE
%endif
%define pip pip3&package_dependency=py3-pip
Requires: python3 py3-pip py3-setuptools
%if "%{n}" != "py3-wheel"
%if "%{?PipNoWheelDep:set}" != "set"
BuildRequires: py3-wheel
%endif
%endif
%if "%{?source0:set}" != "set"
%define source0 pip://%{pip_name}/%{realversion}?pip_options=%{PipDownloadOptions}&pip=%{pip}&output=/%{pkgsource}
%else
%define source_file %(echo '%{source0}' | sed 's|.*/||')
%endif
Source: %source0
%prep
%build
mkdir -p %{i}
%{?PipPrePrep:%PipPrePrep}
%if "%{?source_file:set}" != "set"
tar xfz %{_sourcedir}/%{pkgsource}
%else
cp %{_sourcedir}/%{source_file} %{source_file}
echo %{source_file} > files.list
%endif
%{?PipPostPrep:%PipPostPrep}
%{?PipPreBuild:%PipPreBuild}
%if "%{?NoAutoPatch:set}" != "set"
if [ "%{?patches:%patches}%{?patchsrc:1}%{?patchsrc0:1}%{?patchsrc1:1}%{?patchsrc2:1}%{?patchsrc3:1}%{?patchsrc4:1}" != "" ] ; then
rm -rf cmsdist-patch-%{n} ; mkdir cmsdist-patch-%{n}
pushd cmsdist-patch-%{n}
pip_package_srcfile=../$(cat ../files.list)
%{pip_package_unpack_command}
pip_package_dirname=$(ls -d *)
pushd ${pip_package_dirname}
for pch in %{?patches:%patches} ; do
patch -p1 < ${pch}
done
%{?patchsrc:%patchsrc}
%{?patchsrc0:%patchsrc0}
%{?patchsrc1:%patchsrc1}
%{?patchsrc2:%patchsrc2}
%{?patchsrc3:%patchsrc3}
%{?patchsrc4:%patchsrc4}
popd
rm -f ${pip_package_srcfile}
%{pip_package_pack_command}
popd
rm -rf cmsdist-patch-%{n}
fi
%endif
if [ $(cat files.list | wc -l) -eq 1 ] ; then
export PIPFILE=`cat files.list`
echo ${PIPFILE}
export PYTHONUSERBASE=%{i}
pip3 list --disable-pip-version-check
%{?PipPreBuildPy:%PipPreBuildPy}
%{PipInstallCommand}
PKG_NAME=$(%{PipPackageNameCommand})
[ "${PKG_NAME}" = "" ] && exit 1
DEPS=$(%{PipDepsCommand})
if [ "$DEPS" != "" ] ; then
echo "ERROR: Missing dependencies for %n (python3) found: $DEPS"
exit 1
fi
%{relocatePy3SitePackages}
%{?PipPostBuildPy:%PipPostBuildPy}
else
echo "Sorry I don't know how to handle no/multiple install files yet"
cat %{_builddir}/files.list
exit 1
fi
if [ -d %{i}/bin ] ; then
for py in $(grep -Rl -m1 '^#\!.*python' %{i}/bin) ; do
lnum=$(grep -n -m1 '^#\!.*python' $py | sed 's|:.*||')
sed -i -e "${lnum}c#!/usr/bin/env python3" $py
done
fi
%{?PipPostBuild:%PipPostBuild}
if [ -d %{i}/bin ] ; then
for s in $(grep -IRHl '^#!.*' %{i}/bin) ; do
perl -p -i -e "s|^#!.*python.*|#!/usr/bin/env python3|;s| %{cmsroot}/.*python3 | python3 |" $s
done
fi
%{?RelocatePython:perl -p -i -e "s|^#!.*python.*|#!/usr/bin/env python3|;s| %{cmsroot}/.*python3 | python3 |" %RelocatePython}
#Install Section
%install
%{?PipPreInstall:%PipPreInstall}
%{?PipPostInstall:%PipPostInstall}
[ ! -d %{i}/bin/__pycache__ ] || rm -rf %{i}/bin/__pycache__
chmod -R a+r %{i}
find %{i} -type d -print | xargs chmod 0755
#post Section
%post
%{?PipPrePost:%PipPrePost}
%{?PipPostPost:%PipPostPost}