Skip to content

Commit

Permalink
Merge pull request #3788 from davidlange6/python2path
Browse files Browse the repository at this point in the history
Python3 spec file
  • Loading branch information
davidlange6 committed Mar 2, 2018
2 parents e612df6 + 6e85532 commit fee943f
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmssw-tool-conf.spec
Expand Up @@ -67,6 +67,7 @@ Requires: pythia8-toolfile
Requires: vincia-toolfile
Requires: dire-toolfile
Requires: python-toolfile
Requires: python3-toolfile
Requires: qt-toolfile
Requires: root-toolfile
Requires: sherpa-toolfile
Expand Down
6 changes: 6 additions & 0 deletions python.spec
Expand Up @@ -191,6 +191,12 @@ for tool in $(echo %{requiredtools} | sed -e's|\s+| |;s|^\s+||'); do
fi
done

echo "from os import environ" > %i/lib/python2.7/sitecustomize.py
echo "if 'PYTHON27PATH' in environ:" >> %i/lib/python2.7/sitecustomize.py
echo " import sys" >> %i/lib/python2.7/sitecustomize.py
echo " sys.path =environ['PYTHON27PATH'].split(':') + sys.path">> %i/lib/python2.7/sitecustomize.py


%post
%{relocateConfig}lib/python2.7/config/Makefile
%{relocateConfig}lib/python2.7/_sysconfigdata.py
Expand Down
30 changes: 30 additions & 0 deletions python3-toolfile.spec
@@ -0,0 +1,30 @@
### RPM external python3-toolfile 1.0
Requires: python3
%prep

%build

%install

mkdir -p %i/etc/scram.d
cat << \EOF_TOOLFILE >%i/etc/scram.d/python.xml
<tool name="python3" version="@TOOL_VERSION@">
<lib name="python@PYTHON3V@m"/>
<client>
<environment name="PYTHON3_BASE" default="@TOOL_ROOT@"/>
<environment name="LIBDIR" default="$PYTHON3_BASE/lib"/>
<environment name="INCLUDE" default="$PYTHON3_BASE/include/python@PYTHON3V@m"/>
<environment name="PYTHON3_COMPILE" default="$PYTHON3_BASE/lib/python@PYTHON3V@/compileall.py"/>
</client>
<runtime name="PATH" value="$PYTHON3_BASE/bin" type="path"/>
<use name="sockets"/>
</tool>
EOF_TOOLFILE


# <runtime name="ROOT_INCLUDE_PATH" value="$INCLUDE" type="path"/>
# <use name="root_cxxdefaults"/>

export PYTHON3V=$(echo $PYTHON3_VERSION | cut -f1,2 -d.)

## IMPORT scram-tools-post
86 changes: 86 additions & 0 deletions python3.spec
@@ -0,0 +1,86 @@
### RPM external python3 3.6.4
## INITENV +PATH PATH %{i}/bin
## INITENV +PATH LD_LIBRARY_PATH %{i}/lib
## INITENV SETV PYTHON_LIB_SITE_PACKAGES lib/python%{pythonv}/site-packages
## INITENV SETV PYTHONHASHSEED random
# OS X patches and build fudging stolen from fink
%define pythonv %(echo %realversion | cut -d. -f 1,2)
%define python_major %(echo %realversion | cut -d. -f 1)

Requires: expat bz2lib db6 gdbm openssl libffi zlib sqlite

Source: https://www.python.org/ftp/python/%realversion/Python-%realversion.tgz

%prep
%setup -n Python-%{realversion}

%build
mkdir -p %{i}/{include,lib,bin}

# We need to export it because setup.py now uses it to determine the actual
# location of DB4, this was needed to avoid having it picked up from the system.
export DB6_ROOT
export LIBFFI_ROOT

# Python's configure parses LDFLAGS and CPPFLAGS to look for aditional library and include directories
LDFLAGS=""
CPPFLAGS=""
for d in ${EXPAT_ROOT} ${BZ2LIB_ROOT} ${DB6_ROOT} ${GDBM_ROOT} ${OPENSSL_ROOT} ${LIBFFI_ROOT} ${ZLIB_ROOT} ${SQLITE_ROOT}; do
LDFLAGS="$LDFLAGS -L$d/lib -L$d/lib64"
CPPFLAGS="$CPPFLAGS -I$d/include"
done

./configure \
--prefix=%{i} \
--enable-shared \
--enable-ipv6 \
--with-system-ffi \
--without-ensurepip \
--with-system-expat \
LDFLAGS="$LDFLAGS" \
CPPFLAGS="$CPPFLAGS"

make %{makeprocesses}

%install
make %{makeprocesses} install
sed -i -e "s|^#!.*python%{pythonv} *$|#!/usr/bin/env python%{python_major}|" %{i}/bin/* %{i}/lib/python*/*.py
sed -i -e 's|^#!/.*|#!/usr/bin/env python%{pythonv}m|' %{i}/lib/python*/config-*/python-config.py
sed -i -e 's|^#! */usr/local/bin/python|#!/usr/bin/env python|' %{i}/lib/python*/cgi.py

# is executable, but does not start with she-bang so not valid
# executable; this avoids problems with rpm 4.8+ find-requires
find %i -name '*.py' -perm +0111 | while read f; do
if head -n1 $f | grep -q '"'; then chmod -x $f; else :; fi
done

# Generate dependencies-setup.{sh,csh} so init.{sh,csh} picks full environment.
mkdir -p %i/etc/profile.d
: > %i/etc/profile.d/dependencies-setup.sh
: > %i/etc/profile.d/dependencies-setup.csh
for tool in $(echo %{requiredtools} | sed -e's|\s+| |;s|^\s+||'); do
root=$(echo $tool | tr a-z- A-Z_)_ROOT; eval r=\$$root
if [ X"$r" != X ] && [ -r "$r/etc/profile.d/init.sh" ]; then
echo "test X\$$root != X || . $r/etc/profile.d/init.sh" >> %i/etc/profile.d/dependencies-setup.sh
echo "test \$?$root != 0 || source $r/etc/profile.d/init.csh" >> %i/etc/profile.d/dependencies-setup.csh
fi
done

# Remove .pyo files
find %i -name '*.pyo' -exec rm {} \;

# Remove documentation, examples and test files.
rm -rf %{i}/share %{i}/lib/python*/test %{i}/lib/python%{pythonv}/distutils/tests %{i}/lib/python%{pythonv}/lib2to3/tests

echo "from os import environ" > %i/lib/python%{pythonv}/sitecustomize.py
echo "if 'PYTHON3PATH' in environ:" >> %i/lib/python%{pythonv}/sitecustomize.py
echo " import sys" >> %i/lib/python%{pythonv}/sitecustomize.py
echo " sys.path =environ['PYTHON3PATH'].split(':') + sys.path">> %i/lib/python%{pythonv}/sitecustomize.py



%post
%{relocateConfig}bin/python*-config
%{relocateConfig}lib/pkgconfig/python*.pc
%{relocateConfig}lib/python*/config-*/Makefile
%{relocateConfig}lib/python*/_sysconfigdata*.py

0 comments on commit fee943f

Please sign in to comment.