forked from cms-sw/cmsdist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-with-pip.file
173 lines (155 loc) · 5.83 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
165
166
167
168
169
170
171
172
#File: with-with-pip
#pip_name: pip package name default is package name without starting py2
#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
#doPython(2|3): To disable building package for python2 or python3
#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/*
## INITENV +PATH PYTHON27PATH %{i}/${PYTHON_LIB_SITE_PACKAGES}
## 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 --no-deps
%endif
%if "%{?pkgsource:set}" != "set"
%define pkgsource source.tar.gz
%endif
%if "%{?PipInstallOptions:set}" != "set"
%define PipInstallOptions --no-clean
%endif
%if "%{?doPython2:set}" != "set"
Requires: python
%define doPython2 yes
%define pip pip2
%else
%define pip pip3
%endif
%if "%{?doPython3:set}" != "set"
Requires: python3
%define doPython3 yes
%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
Requires: py2-setuptools
BuildRequires: py2-pip
%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}
%if "%{doPython3}" == "yes"
pip3 list --disable-pip-version-check
%{?PipPreBuildPy3:%PipPreBuildPy3}
pip3 install --upgrade --upgrade-strategy only-if-needed --no-cache-dir --disable-pip-version-check --user -v %{PipInstallOptions} %{PipBuildOptions} %{?PipBuildOptionsPy3:%PipBuildOptionsPy3} $PIPFILE
PKG_NAME=$(pip3 show %{pip_name} --disable-pip-version-check | grep '^Name:' | sed 's|^Name: *||;s| ||g')
[ "${PKG_NAME}" = "" ] && exit 1
DEPS=$(pip3 check --disable-pip-version-check | grep "^${PKG_NAME} *%{realversion} *requires " | sed 's|,.*||;s|.* |py2-|' | tr '\n' ' ')
if [ "$DEPS" != "" ] ; then
echo "ERROR: Missing dependencies for %n (python3) found: $DEPS"
exit 1
fi
%{relocatePy3SitePackages}
%{?PipPostBuildPy3:%PipPostBuildPy3}
%endif
%if "%{doPython2}" == "yes"
pip2 list --disable-pip-version-check
%{?PipPreBuildPy2:%PipPreBuildPy2}
pip2 install --upgrade --upgrade-strategy only-if-needed --no-cache-dir --disable-pip-version-check --user -v %{PipInstallOptions} %{PipBuildOptions} %{?PipBuildOptionsPy2:%PipBuildOptionsPy2} $PIPFILE
PKG_NAME=$(pip2 show %{pip_name} --disable-pip-version-check | grep '^Name:' | sed 's|^Name: *||;s| ||g')
[ "${PKG_NAME}" = "" ] && exit 1
DEPS=$(pip2 check --disable-pip-version-check | grep "^${PKG_NAME} *%{realversion} *requires " | sed 's|,.*||;s|.* |py2-|' | tr '\n' ' ')
if [ "$DEPS" != "" ] ; then
echo "ERROR: Missing dependencies for %n (python2) found: $DEPS"
exit 1
fi
%{relocatePy2SitePackages}
%{?PipPostBuildPy2:%PipPostBuildPy2}
%endif
else
echo "Sorry I don't know how to handle no/multiple install files yet"
cat %{_builddir}/files.list
exit 1
fi
%if "%{doPython3}%{doPython2}" != "yesyes"
if [ -d %{i}/bin ] ; then
for py in $(grep -Rl -m1 '^#\!.*python' %{i}/bin) ; do
lnum=$(grep -n -m1 '^#\!.*python' $py | sed 's|:.*||')
%if "%{doPython2}" == "yes"
sed -i -e "${lnum}c#!/usr/bin/env python" $py
%else
sed -i -e "${lnum}c#!/usr/bin/env python3" $py
%endif
done
fi
%endif
%{?PipPostBuild:%PipPostBuild}
%{?RelocatePython:perl -p -i -e "s|^#!.*python|#!/usr/bin/env python|" %RelocatePython}
%{?RelocatePython3:perl -p -i -e "s|^#!.*python.*|#!/usr/bin/env python3|" %RelocatePython3}
#Install Section
%install
%{?PipPreInstall:%PipPreInstall}
%{?PipPostInstall:%PipPostInstall}
chmod -R a+r %{i}
find %{i} -type d -print | xargs chmod 0755
echo "OK Install"
#post Section
%post
%{?PipPrePost:%PipPrePost}
%{?PipPostPost:%PipPostPost}