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
|
from __future__ import print_function
from setuptools import setup, Extension
# sysconfig with setuptools v48.0.0+ is incompatible for Python 3.6 only, so fall back to distutils.
# FIXME: When support for Python 3.6 is dropped simplify this
import sys
if sys.version_info < (3, 7):
from distutils import sysconfig
else:
import sysconfig
from os import getenv, walk, path
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 not in ['-Wstrict-prototypes' ${CLANG_PROHIBITED} ] ) + " --std=c++14"
cflags = cfg_vars["CFLAGS"]
cfg_vars["CFLAGS"] = " ".join( flag for flag in cflags.split() if flag not in ['-Wstrict-prototypes' ${CLANG_PROHIBITED} ] ) + " --std=c++14"
# pypy doesn't define PY_CFLAGS so skip it if it's missing
if "PY_CFLAGS" in cfg_vars:
py_cflags = cfg_vars["PY_CFLAGS"]
cfg_vars["PY_CFLAGS"] = " ".join( flag for flag in py_cflags.split() if flag not in ['-Wstrict-prototypes' ${CLANG_PROHIBITED} ] ) + " --std=c++14"
ccl=cfg_vars["CC"].split()
ccl[0]="${CMAKE_C_COMPILER}"
cfg_vars["CC"] = " ".join(ccl)
cxxl=cfg_vars["CXX"].split()
cxxl[0]="${CMAKE_CXX_COMPILER}"
cfg_vars["CXX"] = " ".join(cxxl)
cfg_vars["PY_CXXFLAGS"] = "${CMAKE_CXX_FLAGS}"
# Make the RPATH relative to the python module
cfg_vars['LDSHARED'] = cfg_vars['LDSHARED'] + " -Wl,-rpath,${XRDCL_RPATH}"
sources = list()
depends = list()
for dirname, dirnames, filenames in walk('${CMAKE_CURRENT_SOURCE_DIR}/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))
xrdcllibdir = "${XRDCL_LIBDIR}"
xrdlibdir = "${XRD_LIBDIR}"
xrdsrcincdir = "${XRD_SRCINCDIR}"
xrdbinincdir = "${XRD_BININCDIR}"
version = "${XROOTD_VERSION}"
if version.startswith('unknown'):
try:
import os
version_file_path = os.path.join('${CMAKE_CURRENT_SOURCE_DIR}', 'VERSION')
print('Version file path: {}'.format(version_file_path))
with open(version_file_path, 'r') as f:
version = f.read().split('/n')[0]
print('Version from file: {}'.format(version))
except Exception as e:
print('{} \nCannot open VERSION_INFO file. {} will be used'.format(e, version))
# Sanitize in keeping with PEP 440
# c.f. https://www.python.org/dev/peps/pep-0440/
# c.f. https://github.com/pypa/pip/issues/8368
# version needs to pass pip._vendor.packaging.version.Version()
version = version.replace("-", ".")
if version.startswith("v"):
version = version[1:]
version_parts = version.split(".")
# Ensure release candidates sanitized to <major>.<minor>.<patch>rc<candidate>
if version_parts[-1].startswith("rc"):
version = ".".join(version_parts[:-1]) + version_parts[-1]
version_parts = version.split(".")
if len(version_parts[0]) == 8:
# CalVer
date = version_parts[0]
year = date[:4]
incremental = date[4:]
if incremental.startswith("0"):
incremental = incremental[1:]
version = year + "." + incremental
if len(version_parts) > 1:
# https://github.com/pypa/pip/issues/9188#issuecomment-736025963
hash = version_parts[1]
version = version + "+" + hash
print('XRootD library dir: ', xrdlibdir)
print('XRootD src include dir:', xrdsrcincdir)
print('XRootD bin include dir:', xrdbinincdir)
print('Version: ', version)
setup( name = 'xrootd',
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' : '${CMAKE_CURRENT_SOURCE_DIR}/src',
'XRootD' : '${CMAKE_CURRENT_SOURCE_DIR}/libs',
'XRootD.client': '${CMAKE_CURRENT_SOURCE_DIR}/libs/client'},
ext_modules = [
Extension(
'pyxrootd.client',
sources = sources,
depends = depends,
libraries = ['XrdCl', 'XrdUtils', 'dl'],
extra_compile_args = ['-g'],
include_dirs = [xrdsrcincdir, xrdbinincdir],
library_dirs = [xrdlibdir, xrdcllibdir]
)
]
)
|