-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathsetup.py
101 lines (87 loc) · 3.25 KB
/
setup.py
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
import os
import platform
import subprocess
import sys
from setuptools import Extension
from setuptools import setup
def poppler_cpp_at_least(version):
try:
subprocess.check_call(
["pkg-config", "--exists", "poppler-cpp >= {}".format(version)]
)
except subprocess.CalledProcessError:
return False
except (FileNotFoundError, OSError):
print("WARNING: pkg-config not found--guessing at poppler version.")
print(" If the build fails, install pkg-config and try again.")
return True
def brew_poppler_include():
try:
brew_list = subprocess.check_output(["brew", "list", "poppler"])
try:
brew_list = brew_list.decode()
except (AttributeError, UnicodeDecodeError):
pass
include_dir = None
library_dir = None
for brew_file_line in brew_list.split("\n"):
brew_file = brew_file_line.split("(")[0].strip()
if brew_file.endswith("include/poppler/OptionalContent.h"):
include_dir = os.path.dirname(os.path.dirname(brew_file))
elif brew_file.endswith(".dylib"):
library_dir = os.path.dirname(brew_file)
return include_dir, library_dir
except (FileNotFoundError, OSError, subprocess.CalledProcessError):
return None, None
include_dirs = None
library_dirs = None
# On some BSDs, poppler is in /usr/local, which is not searched by default
if platform.system() in ["Darwin", "FreeBSD", "OpenBSD"]:
include_dirs = ["/usr/local/include"]
library_dirs = ["/usr/local/lib"]
# On Windows, only building with conda is tested so far
if platform.system() == "Windows":
conda_prefix = os.getenv("CONDA_PREFIX")
if conda_prefix is not None:
include_dirs = [os.path.join(conda_prefix, "Library\include")]
library_dirs = [os.path.join(conda_prefix, "Library\lib")]
extra_compile_args = ["-Wall"]
extra_link_args = []
# On macOS, some distributions of python build extensions for 10.6 by default,
# but poppler uses C++11 features that require at least 10.9
if platform.system() == "Darwin":
extra_compile_args += ["-mmacosx-version-min=10.9", "-std=c++11"]
extra_link_args += ["-mmacosx-version-min=10.9"]
brew_include, brew_library = brew_poppler_include()
if brew_include is not None:
include_dirs.append(brew_include)
if brew_library is not None:
library_dirs.append(brew_library)
macros = [
("POPPLER_CPP_AT_LEAST_0_58_0", int(poppler_cpp_at_least("0.58.0"))),
("POPPLER_CPP_AT_LEAST_0_88_0", int(poppler_cpp_at_least("0.88.0"))),
]
module = Extension(
"pdftotext",
sources=["pdftotext.cpp"],
libraries=["poppler-cpp"],
include_dirs=include_dirs,
library_dirs=library_dirs,
define_macros=macros,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
)
with open("README.md", "r") as f:
long_description = f.read()
setup(
name="pdftotext",
version="3.0.0",
author="Jason Alan Palmer",
author_email="[email protected]",
description="Simple PDF text extraction",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/jalan/pdftotext",
license="MIT",
ext_modules=[module],
)