-- The Python bindings bundle a separate cmake build of the C++ library, -- which fails against abseil 20250127+. Prefer the system sentencepiece -- shared libraries when they are available, and accept .so as well as .a. -- Also fix the pyproject.toml license field for current setuptools. --- setup.py.orig 2026-07-01 09:52:43 UTC +++ setup.py @@ -74,15 +74,20 @@ '-I' + os.path.normpath(os.path.join(root, 'include')), ] + get_protobuf_includes() libs = [] - if os.path.exists(os.path.join(root, 'lib/libsentencepiece.a')): + libdir = None + suffix = None + for d in ['lib', 'lib64']: + for ext in ['.so', '.a']: + if os.path.exists(os.path.join(root, d, 'libsentencepiece' + ext)): + libdir = d + suffix = ext + break + if libdir: + break + if libdir: libs = [ - os.path.join(root, 'lib/libsentencepiece.a'), - os.path.join(root, 'lib/libsentencepiece_train.a'), - ] - elif os.path.exists(os.path.join(root, 'lib64/libsentencepiece.a')): - libs = [ - os.path.join(root, 'lib64/libsentencepiece.a'), - os.path.join(root, 'lib64/libsentencepiece_train.a'), + os.path.join(root, libdir, 'libsentencepiece' + suffix), + os.path.join(root, libdir, 'libsentencepiece_train' + suffix), ] return cflags, libs @@ -104,16 +109,24 @@ """Override build_extension to run cmake.""" def build_extension(self, ext): - cflags, libs = get_cflags_and_libs('../build/root') - abseil_libs = find_abseil_lib('../build/third_party') - cflags.extend(find_absl_include(is_msvc=False)) + cflags, libs = get_cflags_and_libs('/usr/local') + use_system = len(libs) > 0 + abseil_libs = [] + if not use_system: + cflags, libs = get_cflags_and_libs('../build/root') + abseil_libs = find_abseil_lib('../build/third_party') + cflags.extend(find_absl_include(is_msvc=False)) + if len(libs) == 0: subprocess.check_call(['./build_bundled.sh', __version__]) cflags, libs = get_cflags_and_libs('./build/root') abseil_libs = find_abseil_lib('./build/third_party') cflags.extend(find_absl_include(is_msvc=False)) + if use_system: + cflags = ['-std=c++17', '-I/usr/local/include'] + # Fix compile on some versions of Mac OSX # See: https://github.com/neulab/xnmt/issues/199 if sys.platform == 'darwin': --- pyproject.toml.orig 2026-07-01 09:52:43 UTC +++ pyproject.toml @@ -10,7 +10,7 @@ ] description = "Unsupervised text tokenizer and detokenizer." readme = "README.md" -license = "Apache-2.0" +license = {text = "Apache-2.0"} requires-python = ">=3.9" urls = { "Homepage" = "https://github.com/google/sentencepiece" } classifiers = [