You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

310 lines
12 KiB

3 years ago
Index: PyMuPDF-1.22.5/setup.py
--- PyMuPDF-1.22.5/setup.py.orig 2023-06-21 20:22:28.000000000 +0200
+++ PyMuPDF-1.22.5/setup.py 2023-06-22 09:45:45.630844000 +0200
3 years ago
@@ -1,3 +1,4 @@
+
'''
Overview:
5 years ago
3 years ago
@@ -576,271 +577,6 @@
3 years ago
# Create local mupdf.tgz, for inclusion in sdist.
3 years ago
get_mupdf_tgz()
4 years ago
3 years ago
-
3 years ago
-if ('-h' not in sys.argv and '--help' not in sys.argv
3 years ago
- and (0
- or 'bdist_wheel' in sys.argv
3 years ago
- or 'build' in sys.argv
- or 'bdist' in sys.argv
- or 'install' in sys.argv
- )
- ):
4 years ago
-
3 years ago
- # Build MuPDF before setuptools runs, so that it can link with the MuPDF
- # libraries.
- #
- mupdf_local = get_mupdf()
- if mupdf_local:
3 years ago
- if mupdf_local.endswith( '/'):
- mupdf_local = mupdf_local[:-1]
-
3 years ago
- log( f'mupdf_local={mupdf_local!r}')
3 years ago
- unix_build_dir = None
3 years ago
-
- # Always force clean build of PyMuPDF SWIG files etc, because setuptools
- # doesn't seem to notice when our mupdf headers etc are newer than the
- # SWIG-generated files.
- #
- remove( os.path.abspath( f'{__file__}/../build/'))
- remove( os.path.abspath( f'{__file__}/../install/'))
-
- if mupdf_local:
3 years ago
- # Build MuPDF before deferring to setuptools.setup().
- #
-
3 years ago
- log( f'Building mupdf.')
3 years ago
- # Copy PyMuPDF's config file into mupdf. For example it #define's TOFU,
- # which excludes various fonts in the MuPDF binaries.
3 years ago
- if os.environ.get('PYMUPDF_SETUP_MUPDF_OVERWRITE_CONFIG') == '0':
3 years ago
- # Use MuPDF default config.
- log( f'Not copying fitz/_config.h to {mupdf_local}/include/mupdf/fitz/config.h.')
3 years ago
- s = os.stat( f'{mupdf_local}/include/mupdf/fitz/config.h')
- log( f'{mupdf_local}/include/mupdf/fitz/config.h: {s} mtime={time.strftime("%F-%T", time.gmtime(s.st_mtime))}')
3 years ago
- else:
3 years ago
- # Use our special config in MuPDF.
3 years ago
- log( f'Copying fitz/_config.h to {mupdf_local}/include/mupdf/fitz/config.h')
- shutil.copy2( 'fitz/_config.h', f'{mupdf_local}/include/mupdf/fitz/config.h')
3 years ago
-
3 years ago
- if windows:
3 years ago
- # Windows build.
- devenv = os.environ.get('PYMUPDF_SETUP_DEVENV')
3 years ago
- log( 'PYMUPDF_SETUP_DEVENV={PYMUPDF_SETUP_DEVENV!r}')
3 years ago
- if not devenv:
- # Search for devenv in some known locations.
- devenv = glob.glob('C:/Program Files (x86)/Microsoft Visual Studio/2019/*/Common7/IDE/devenv.com')
- if devenv:
- devenv = devenv[0]
- if not devenv:
- devenv = 'devenv.com'
- log( f'Cannot find devenv.com in default locations, using: {devenv!r}')
- windows_config = 'Win32' if word_size()==32 else 'x64'
- command = (
- f'cd {mupdf_local}&&'
- f'"{devenv}"'
- f' platform/win32/mupdf.sln'
- f' /Build "ReleaseTesseract|{windows_config}"'
- f' /Project mupdf'
- )
- else:
- # Unix build.
3 years ago
- #
3 years ago
- flags = 'HAVE_X11=no HAVE_GLFW=no HAVE_GLUT=no HAVE_LEPTONICA=yes HAVE_TESSERACT=yes'
- flags += ' verbose=yes'
- env = ''
- make = 'make'
3 years ago
- if linux:
3 years ago
- env += ' CFLAGS="-fPIC"'
3 years ago
- if openbsd or freebsd:
3 years ago
- make = 'gmake'
- env += ' CFLAGS="-fPIC" CXX=clang++'
3 years ago
-
3 years ago
- unix_build_type = os.environ.get( 'PYMUPDF_SETUP_MUPDF_BUILD_TYPE', 'release')
- assert unix_build_type in ('debug', 'memento', 'release')
- flags += f' build={unix_build_type}'
3 years ago
-
- # This is for MacOS cross-compilation, where ARCHFLAGS can be
- # '-arch arm64'.
- #
- archflags = os.environ.get( 'ARCHFLAGS')
- if archflags:
- flags += f' XCFLAGS="{archflags}" XLIBS="{archflags}"'
-
- # We specify a build directory path containing 'pymupdf' so that we
- # coexist with non-pymupdf builds (because pymupdf builds have a
- # different config.h).
- #
- # We also append further text to try to allow different builds to
- # work if they reuse the mupdf directory.
- #
- # Using platform.machine() (e.g. 'amd64') ensures that different
- # builds of mupdf on a shared filesystem can coexist. Using
- # $_PYTHON_HOST_PLATFORM allows cross-compiled cibuildwheel builds
- # to coexist, e.g. on github.
- #
- build_prefix = f'pymupdf-{platform.machine()}-'
- build_prefix_extra = os.environ.get( '_PYTHON_HOST_PLATFORM')
- if build_prefix_extra:
- build_prefix += f'{build_prefix_extra}-'
- flags += f' build_prefix={build_prefix}'
-
3 years ago
- unix_build_dir = f'{mupdf_local}/build/{build_prefix}{unix_build_type}'
3 years ago
-
3 years ago
- if os.environ.get( 'PYMUPDF_SETUP_MUPDF_CLEAN') == '1':
- # Force clean build.
- log(f'Removing {unix_build_dir} because PYMUPDF_SETUP_MUPDF_CLEAN=1')
- assert '/build/' in unix_build_dir
- remove(unix_build_dir)
-
3 years ago
- command = f'cd {mupdf_local} && {env} {make} {flags}'
3 years ago
- command += f' && echo {unix_build_dir}:'
- command += f' && ls -l build/{build_prefix}{unix_build_type}'
3 years ago
-
3 years ago
- if os.environ.get( 'PYMUPDF_SETUP_MUPDF_REBUILD') == '0':
- log( f'PYMUPDF_SETUP_MUPDF_REBUILD is "0" so not building MuPDF; would have run: {command}')
- else:
- log( f'Building MuPDF by running: {command}')
- subprocess.run( command, shell=True, check=True)
- log( f'Finished building mupdf.')
3 years ago
- else:
- # Use installed MuPDF.
- log( f'Using system mupdf.')
3 years ago
- unix_build_type = ''
3 years ago
-
- # Set include and library paths for building PyMuPDF.
- #
3 years ago
- # We also add MuPDF's include directory to include path for Swig so that
- # fitz/fitz.i can do `%include "mupdf/fitz/version.h"` and .i code can use
- # `#if` with FZ_VERSION_* macros.
- #
3 years ago
- if mupdf_local:
- assert os.path.isdir( mupdf_local), f'Not a directory: {mupdf_local!r}'
3 years ago
- include_dirs.append( f'{mupdf_local}/include')
- include_dirs.append( f'{mupdf_local}/include/mupdf')
- include_dirs.append( f'{mupdf_local}/thirdparty/freetype/include')
3 years ago
- if unix_build_dir:
- library_dirs.append( unix_build_dir)
3 years ago
- extra_swig_args.append(f'-I{mupdf_local}/include')
4 years ago
-
3 years ago
- if mupdf_local and (linux or openbsd or freebsd):
- # setuptools' link command always seems to put '-L
- # /usr/local/lib' before any <library_dirs> that we specify,
- # so '-l mupdf -l mupdf-third' will end up using the system
- # libmupdf.so (if installed) instead of the one we've built in
- # <mupdf_local>.
- #
- # So we force linking with our mupdf libraries by specifying
- # them in <extra_link_args>.
- #
3 years ago
- extra_link_args.append( f'{unix_build_dir}/libmupdf.a')
- extra_link_args.append( f'{unix_build_dir}/libmupdf-third.a')
3 years ago
- library_dirs = []
- libraries = []
- if openbsd or freebsd:
- if os.environ.get( 'PYMUPDF_SETUP_MUPDF_BUILD_TYPE') == 'memento':
- extra_link_args.append( f'-lexecinfo')
-
- elif mupdf_local and darwin:
3 years ago
- library_dirs.append(f'{unix_build_dir}')
3 years ago
- libraries = [
- f'mupdf',
- f'mupdf-third',
- ]
-
- elif linux:
- # Use system libraries.
- include_dirs.append( '/usr/include/mupdf')
- include_dirs.append( '/usr/local/include/mupdf')
- include_dirs.append( '/usr/include/freetype2')
- libraries = load_libraries()
- extra_link_args = []
3 years ago
- extra_swig_args.append(f'-I/usr/local/include')
- extra_swig_args.append(f'-I/usr/include')
3 years ago
-
- elif darwin or openbsd or freebsd:
- # Use system libraries.
- include_dirs.append("/usr/local/include/mupdf")
- include_dirs.append("/usr/local/include")
- include_dirs.append("/opt/homebrew/include/mupdf")
- library_dirs.append("/usr/local/lib")
- libraries = ["mupdf", "mupdf-third"]
- library_dirs.append("/opt/homebrew/lib")
-
- include_dirs.append("/usr/include/freetype2")
- include_dirs.append("/usr/local/include/freetype2")
- include_dirs.append("/usr/X11R6/include/freetype2")
- include_dirs.append("/opt/homebrew/include")
- include_dirs.append("/opt/homebrew/include/freetype2")
3 years ago
-
- extra_swig_args.append(f'-I/usr/local/include')
- extra_swig_args.append(f'-I/opt/homebrew/include')
3 years ago
-
- library_dirs.append("/opt/homebrew/lib")
-
3 years ago
- if freebsd:
3 years ago
- libraries += [
- 'freetype',
- 'harfbuzz',
- ]
-
3 years ago
- elif windows:
3 years ago
- # Windows.
- assert mupdf_local
- if word_size() == 32:
3 years ago
- library_dirs.append( f'{mupdf_local}/platform/win32/ReleaseTesseract')
- library_dirs.append( f'{mupdf_local}/platform/win32/Release')
3 years ago
- else:
3 years ago
- library_dirs.append( f'{mupdf_local}/platform/win32/x64/ReleaseTesseract')
- library_dirs.append( f'{mupdf_local}/platform/win32/x64/Release')
3 years ago
- libraries = [
- "libmupdf",
- "libresources",
- "libthirdparty",
- ]
- extra_link_args = ["/NODEFAULTLIB:MSVCRT"]
3 years ago
-
3 years ago
- else:
- assert 0, 'Unrecognised OS'
-
3 years ago
- if linux or openbsd or freebsd or darwin:
- extra_compile_args.append( '-Wno-incompatible-pointer-types')
- extra_compile_args.append( '-Wno-pointer-sign')
- extra_compile_args.append( '-Wno-sign-compare')
- if unix_build_type == 'memento':
- extra_compile_args.append( '-DMEMENTO')
- if openbsd:
- extra_compile_args.append( '-Wno-deprecated-declarations')
3 years ago
-
- # add any local include and library folders
- pymupdf_dirs = os.environ.get("PYMUPDF_DIRS", None)
- if pymupdf_dirs:
- with open(pymupdf_dirs) as dirfile:
- local_dirs = json.load(dirfile)
- include_dirs += local_dirs.get("include_dirs", [])
- library_dirs += local_dirs.get("library_dirs", [])
-
3 years ago
- with open(f'fitz/helper-git-versions.i', 'w') as f:
- f.write('%pythoncode %{\n')
-
- def repr_escape(text):
- text = repr(text)
- text = text.replace('{', '{{')
- text = text.replace('}', '}}')
- text = text.replace('%', '{chr(37)})') # Avoid confusing swig.
- return 'f' + text
- def write_git(name, directory):
- sha, comment, diff, branch = get_git_id(directory)
- f.write(f'{name}_git_sha = \'{sha}\'\n')
- f.write(f'{name}_git_comment = {repr_escape(comment)}\n')
- f.write(f'{name}_git_diff = {repr_escape(diff)}\n')
- f.write(f'{name}_git_branch = {repr_escape(branch)}\n')
- f.write('\n')
-
- write_git('pymupdf', '.')
- if mupdf_local:
- write_git('mupdf', mupdf_local)
-
- f.write('%}\n')
-
# Disable bogus SWIG warning 509, 'Overloaded method ... effectively ignored,
# as it is shadowed by ...'.
extra_swig_args.append( '-w509')
3 years ago
@@ -856,9 +592,9 @@
4 years ago
"fitz._fitz",
3 years ago
["fitz/fitz.i"],
language="c++",
4 years ago
- include_dirs=include_dirs,
- library_dirs=library_dirs,
- libraries=libraries,
5 years ago
+ include_dirs=[ "@l_prefix@/include/mupdf", "@l_prefix@/include/freetype", "@l_prefix@/include", ],
+ library_dirs=[ "@l_prefix@/lib/", ],
3 years ago
+ libraries=[ "mupdf", "mupdf-third", ],
3 years ago
extra_compile_args=extra_compile_args,
3 years ago
extra_link_args=extra_link_args,
3 years ago
swig_opts=extra_swig_args,
4 years ago
Index: pdfrw-0.4/pdfrw/crypt.py
--- pdfrw-0.4/pdfrw/crypt.py.orig 2017-09-14 15:27:27.000000000 +0200
3 years ago
+++ pdfrw-0.4/pdfrw/crypt.py 2023-06-22 09:45:15.362164000 +0200
4 years ago
@@ -7,11 +7,7 @@
import hashlib
import struct
-try:
- from Crypto.Cipher import ARC4, AES
- HAS_CRYPTO = True
-except ImportError:
- HAS_CRYPTO = False
+HAS_CRYPTO = False
from .objects import PdfDict, PdfName