forked from cms-sw/cmsdist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-with-pip.file
114 lines (99 loc) · 3.8 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
#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_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 "%{?doPython2:set}" != "set"
Requires: python
%define doPython2 yes
%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=pip2&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 [ $(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 --disable-pip-version-check --user -v %{PipBuildOptions} %{?PipBuildOptionsPy3:%PipBuildOptionsPy3} $PIPFILE
PKG_NAME=$(pip3 show %{pip_name} --disable-pip-version-check | grep '^Name:' | sed 's|^Name: *||;s| ||g')
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
%{?PipPostBuildPy3:%PipPostBuildPy3}
%endif
%if "%{doPython2}" == "yes"
pip2 list --disable-pip-version-check
%{?PipPreBuildPy2:%PipPreBuildPy2}
pip2 install --disable-pip-version-check --user -v %{PipBuildOptions} %{?PipBuildOptionsPy2:%PipBuildOptionsPy2} $PIPFILE
PKG_NAME=$(pip2 show %{pip_name} --disable-pip-version-check | grep '^Name:' | sed 's|^Name: *||;s| ||g')
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
%{?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
%{?PipPostBuild:%PipPostBuild}
#Install Section
%install
%{?PipPreInstall:%PipPreInstall}
%{?PipPostInstall:%PipPostInstall}
echo "OK Install"
#post Section
%post
%{?PipPrePost:%PipPrePost}
%{?PipPostPost:%PipPostPost}