From e5b7572d99fd4aa194c3d856e52d2952efa23131 Mon Sep 17 00:00:00 2001 From: Elvin Sindrilaru Date: Fri, 24 Jul 2015 10:12:24 +0200 Subject: [PATCH 1/3] Python: Add setup file to create sdist package for PyPI The new setup_pypi.py file can be used to generate the sdist package for the XRootD python bindings. This should be used only wen creating the package for distribution in PyPI. --- bindings/python/MANIFEST.in | 7 +++++ bindings/python/setup_pypi.py | 58 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 bindings/python/MANIFEST.in create mode 100644 bindings/python/setup_pypi.py diff --git a/bindings/python/MANIFEST.in b/bindings/python/MANIFEST.in new file mode 100644 index 00000000000..4c7c7a982d5 --- /dev/null +++ b/bindings/python/MANIFEST.in @@ -0,0 +1,7 @@ +include README.rst +include VERSION_INFO +include genversion.sh +recursive-include tests * +recursive-include examples *.py +recursive-include docs * +recursive-include src * diff --git a/bindings/python/setup_pypi.py b/bindings/python/setup_pypi.py new file mode 100644 index 00000000000..5b70160546a --- /dev/null +++ b/bindings/python/setup_pypi.py @@ -0,0 +1,58 @@ +from distutils.core import setup, Extension +from distutils import sysconfig +from os import getenv, walk, path, path, getcwd, chdir +import subprocess + +# Remove the "-Wstrict-prototypes" compiler option, which isn't valid for C++. +cfg_vars = sysconfig.get_config_vars() +opt = cfg_vars["OPT"] +cfg_vars["OPT"] = " ".join( flag for flag in opt.split() if flag != '-Wstrict-prototypes' ) + + +sources = list() +depends = list() + +for dirname, dirnames, filenames in walk('src'): + for filename in filenames: + if filename.endswith('.cc'): + sources.append(path.join(dirname, filename)) + elif filename.endswith('.hh'): + depends.append(path.join(dirname, filename)) + +xrdlibdir = getenv( 'XRD_LIBDIR' ) or '/usr/lib' +xrdincdir = getenv( 'XRD_INCDIR' ) or '/usr/include/xrootd' + +# Get package version +topdir = path.dirname(path.dirname(getcwd())) +p = subprocess.Popen(['./genversion.sh', '--print-only'], stdout=subprocess.PIPE, cwd=topdir) +version, err = p.communicate() +version = version.strip() + +print 'XRootD library dir: ', xrdlibdir +print 'XRootD include dir: ', xrdincdir +print 'Version: ', version + +setup( name = 'pyxrootd', + version = version, + author = 'XRootD Developers', + author_email = 'xrootd-dev@slac.stanford.edu', + url = 'http://xrootd.org', + license = 'LGPLv3+', + description = "XRootD Python bindings", + long_description = "XRootD Python bindings", + packages = ['pyxrootd', 'XRootD', 'XRootD.client'], + package_dir = {'pyxrootd' : 'src', + 'XRootD' : 'libs', + 'XRootD.client': 'libs/client'}, + ext_modules = [ + Extension( + 'pyxrootd.client', + sources = sources, + depends = depends, + libraries = ['XrdCl', 'XrdUtils', 'dl'], + extra_compile_args = ['-g'], + include_dirs = [xrdincdir], + library_dirs = [xrdlibdir] + ) + ] + ) From b02410e142b9abad65bd8272017de616d8c68edd Mon Sep 17 00:00:00 2001 From: otron Date: Wed, 29 Jul 2015 17:07:27 +0200 Subject: [PATCH 2/3] Python: add script for generating, uploading sdist The "v" is stripped from the version number generated by `genversion.sh` as PyPi does not accept version numbers containing letters. The version is generated as a part of the script and written to a file which is read by setup.py. --- bindings/python/.gitignore | 4 +++- bindings/python/MANIFEST.in | 1 - bindings/python/setup_pypi.py | 6 ++---- dopy.sh | 10 ++++++++++ 4 files changed, 15 insertions(+), 6 deletions(-) create mode 100755 dopy.sh diff --git a/bindings/python/.gitignore b/bindings/python/.gitignore index f7e4859c728..22eb52622ed 100755 --- a/bindings/python/.gitignore +++ b/bindings/python/.gitignore @@ -2,4 +2,6 @@ build .project .pydevproject .cproject -*.py[co] \ No newline at end of file +*.py[co] +MANIFEST +VERSION_INFO diff --git a/bindings/python/MANIFEST.in b/bindings/python/MANIFEST.in index 4c7c7a982d5..2110b2157d3 100644 --- a/bindings/python/MANIFEST.in +++ b/bindings/python/MANIFEST.in @@ -1,6 +1,5 @@ include README.rst include VERSION_INFO -include genversion.sh recursive-include tests * recursive-include examples *.py recursive-include docs * diff --git a/bindings/python/setup_pypi.py b/bindings/python/setup_pypi.py index 5b70160546a..b9bf4685913 100644 --- a/bindings/python/setup_pypi.py +++ b/bindings/python/setup_pypi.py @@ -23,10 +23,8 @@ xrdincdir = getenv( 'XRD_INCDIR' ) or '/usr/include/xrootd' # Get package version -topdir = path.dirname(path.dirname(getcwd())) -p = subprocess.Popen(['./genversion.sh', '--print-only'], stdout=subprocess.PIPE, cwd=topdir) -version, err = p.communicate() -version = version.strip() +with open ('VERSION_INFO') as verfile: + version = verfile.read().strip() print 'XRootD library dir: ', xrdlibdir print 'XRootD include dir: ', xrdincdir diff --git a/dopy.sh b/dopy.sh new file mode 100755 index 00000000000..2f870ad8dc2 --- /dev/null +++ b/dopy.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# Writes the xrootd version to bindings/python/VERSION_INFO, +# generates and uploads a source distribution for the python bindings. +./genversion.sh --print-only | sed "s/v//" > bindings/python/VERSION_INFO +cd bindings/python +cp setup_pypi.py setup.py +python setup.py sdist +twine upload dist/* +rm setup.py dist/* + From 87ebf644a6ab7ae96a94b35b80cf8ff89f18bc30 Mon Sep 17 00:00:00 2001 From: otron Date: Tue, 28 Jul 2015 16:14:59 +0200 Subject: [PATCH 3/3] Python: limited support for osx w/ homebrew Looks for xrootd include and library directories where they are found on OS X/Darwin systems where xrootd has been installed via homebrew. Only works if the bindings version match the xrootd version installed via homebrew. Comments on the installation procedure for OSX in README.rst --- bindings/python/README.rst | 16 ++++++++++++++++ bindings/python/setup_pypi.py | 17 ++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/bindings/python/README.rst b/bindings/python/README.rst index e69de29bb2d..cf5c2bd0129 100644 --- a/bindings/python/README.rst +++ b/bindings/python/README.rst @@ -0,0 +1,16 @@ +Prerequisites (incomplete): xrootd + +# Installing on OSX +Setup should succeed if: + - xrootd is installed on your system + - xrootd was installed via homebrew + - you're installing the bindings package with the same version number as the + xrootd installation (`xrootd -v`). + +If you have xrootd installed and the installation still fails, do +`XRD_LIBDIR=XYZ; XRD_INCDIR=ZYX; pip install xrootd` +where XYZ and ZYX are the paths to the XRootD library and include directories on your system. + +## How to find the lib and inc directories +To find the library directory, search your system for "libXrd*" files. +The include directory should contain a file named "XrdVersion.hh", so search for that. diff --git a/bindings/python/setup_pypi.py b/bindings/python/setup_pypi.py index b9bf4685913..2830e2d7c29 100644 --- a/bindings/python/setup_pypi.py +++ b/bindings/python/setup_pypi.py @@ -1,6 +1,7 @@ from distutils.core import setup, Extension from distutils import sysconfig from os import getenv, walk, path, path, getcwd, chdir +from platform import system import subprocess # Remove the "-Wstrict-prototypes" compiler option, which isn't valid for C++. @@ -19,13 +20,23 @@ elif filename.endswith('.hh'): depends.append(path.join(dirname, filename)) -xrdlibdir = getenv( 'XRD_LIBDIR' ) or '/usr/lib' -xrdincdir = getenv( 'XRD_INCDIR' ) or '/usr/include/xrootd' - # Get package version with open ('VERSION_INFO') as verfile: version = verfile.read().strip() +def getincdir_osx(): + # Assume xrootd was installed via homebrew + return '/usr/local/Cellar/xrootd/{0}/include/xrootd'.format(version) + +def getlibdir(): + return (system() == 'Darwin' and '/usr/local/lib') or '/usr/lib' + +def getincdir(): + return (system() == 'Darwin' and getincdir_osx()) or '/usr/include/xrootd' + +xrdlibdir = getenv( 'XRD_LIBDIR' ) or getlibdir() +xrdincdir = getenv( 'XRD_INCDIR' ) or getincdir() + print 'XRootD library dir: ', xrdlibdir print 'XRootD include dir: ', xrdincdir print 'Version: ', version