absurdfarce commented on code in PR #1264:
URL:
https://github.com/apache/cassandra-python-driver/pull/1264#discussion_r2767650594
##########
setup.py:
##########
@@ -254,193 +104,78 @@ class build_extensions(build_ext):
$ brew install libev
===============================================================================
- """
-
- def run(self):
- try:
- self._setup_extensions()
- build_ext.run(self)
- except DistutilsPlatformError as exc:
- sys.stderr.write('%s\n' % str(exc))
- warnings.warn(self.error_message % "C extensions.")
-
- def build_extensions(self):
- if build_concurrency > 1:
- self.check_extensions_list(self.extensions)
-
- import multiprocessing.pool
-
multiprocessing.pool.ThreadPool(processes=build_concurrency).map(self.build_extension,
self.extensions)
- else:
- build_ext.build_extensions(self)
-
- def build_extension(self, ext):
- try:
- build_ext.build_extension(self, ext)
- except (CCompilerError, DistutilsExecError,
- DistutilsPlatformError, IOError) as exc:
- sys.stderr.write('%s\n' % str(exc))
- name = "The %s extension" % (ext.name,)
- warnings.warn(self.error_message % (name,))
-
- def _setup_extensions(self):
- # We defer extension setup until this command to leveraage
'setup_requires' pulling in Cython before we
- # attempt to import anything
- self.extensions = []
-
- if try_murmur3:
- self.extensions.append(murmur3_ext)
-
- if try_libev:
- sys.stderr.write("Appending libev extension %s" % libev_ext)
- self.extensions.append(libev_ext)
-
- if try_cython:
- try:
- from Cython.Build import cythonize
- cython_candidates = ['cluster', 'concurrent', 'connection',
'cqltypes', 'metadata',
- 'pool', 'protocol', 'query', 'util']
- compile_args = [] if is_windows else ['-Wno-unused-function']
- self.extensions.extend(cythonize(
- [Extension('cassandra.%s' % m, ['cassandra/%s.py' % m],
- extra_compile_args=compile_args)
- for m in cython_candidates],
- nthreads=build_concurrency,
- exclude_failures=True))
-
- self.extensions.extend(cythonize(NoPatchExtension("*",
["cassandra/*.pyx"], extra_compile_args=compile_args),
- nthreads=build_concurrency))
- except Exception:
- sys.stderr.write("Failed to cythonize one or more modules.
These will not be compiled as extensions (optional).\n")
-
-
-def pre_build_check():
- """
- Try to verify build tools
- """
- if os.environ.get('CASS_DRIVER_NO_PRE_BUILD_CHECK'):
- return True
-
- try:
- from distutils.ccompiler import new_compiler
- from distutils.sysconfig import customize_compiler
- from distutils.dist import Distribution
-
- # base build_ext just to emulate compiler option setup
- be = build_ext(Distribution())
- be.initialize_options()
- be.finalize_options()
+"""
- # First, make sure we have a Python include directory
- have_python_include = any(os.path.isfile(os.path.join(p, 'Python.h'))
for p in be.include_dirs)
- if not have_python_include:
- sys.stderr.write("Did not find 'Python.h' in %s.\n" %
(be.include_dirs,))
- return False
+# ========================== A few upfront checks ==========================
+if is_pypy:
+ sys.stderr.write(pypy_unsupported_msg)
+if not is_supported_platform:
+ sys.stderr.write(platform_unsupported_msg)
+elif not is_supported_arch:
+ sys.stderr.write(arch_unsupported_msg)
- compiler = new_compiler(compiler=be.compiler)
- customize_compiler(compiler)
+# ========================== Extensions ==========================
+pyproject_toml = Path(__file__).parent / "pyproject.toml"
+pyproject_data = toml.load(pyproject_toml)
+driver_project_data = pyproject_data["tool"]["cassandra-driver"]
- try:
- # We must be able to initialize the compiler if it has that method
- if hasattr(compiler, "initialize"):
- compiler.initialize()
- except OSError:
- return False
+murmur3_ext = Extension('cassandra.cmurmur3', sources=['cassandra/cmurmur3.c'])
- executables = []
- if compiler.compiler_type in ('unix', 'cygwin'):
- executables = [compiler.executables[exe][0] for exe in
('compiler_so', 'linker_so')]
- elif compiler.compiler_type == 'nt':
- executables = [getattr(compiler, exe) for exe in ('cc', 'linker')]
+DEFAULT_LIBEV_INCLUDES = ['/usr/include/libev', '/usr/local/include',
'/opt/local/include', '/usr/include']
+DEFAULT_LIBEV_LIBS = ['/usr/local/lib', '/opt/local/lib', '/usr/lib64']
+libev_includes = driver_project_data["libev-includes"] or
DEFAULT_LIBEV_INCLUDES
+libev_libs = driver_project_data["libev-libs"] or DEFAULT_LIBEV_LIBS
+if is_macos:
+ libev_includes.extend(['/opt/homebrew/include',
os.path.expanduser('~/homebrew/include')])
+ libev_libs.extend(['/opt/homebrew/lib'])
+libev_ext = Extension('cassandra.io.libevwrapper',
+ sources=['cassandra/io/libevwrapper.c'],
+ include_dirs=libev_includes,
+ libraries=['ev'],
+ library_dirs=libev_libs)
- if executables:
- from distutils.spawn import find_executable
- for exe in executables:
- if not find_executable(exe):
- sys.stderr.write("Failed to find %s for compiler type
%s.\n" % (exe, compiler.compiler_type))
- return False
+try_extensions = driver_project_data["build-extensions"] and
is_supported_platform and is_supported_arch
+try_murmur3 = driver_project_data["build-murmur3-extension"]
+try_libev = driver_project_data["build-libev-extension"]
+try_cython = driver_project_data["build-cython-extensions"] and not is_pypy
Review Comment:
Agree that these options have been removed but this was done by design. The
same functionality is available via binary vals in "tool.cassandra-driver" in
pyproject.toml. One of the wins of going to pyproject.toml is that the build
gets more declarative, and if we're going to do that we should be steering
users away from CLI flags defined at build time that modify behaviour.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]