[Python-modules-commits] [python-djvulibre] 01/08: Import python-djvulibre_0.8.orig.tar.xz
Daniel Stender
stender at moszumanska.debian.org
Sat Aug 27 22:00:47 UTC 2016
This is an automated email from the git hooks/post-receive script.
stender pushed a commit to branch master
in repository python-djvulibre.
commit 423756fcc61c65df47a2a560c3f542462db7a490
Author: Daniel Stender <stender at debian.org>
Date: Sat Aug 27 23:14:26 2016 +0200
Import python-djvulibre_0.8.orig.tar.xz
---
PKG-INFO | 8 +-
djvu/decode.pyx | 17 ++--
djvu/dllpath.py | 61 ++++++++----
djvu/sexpr.pyx | 4 +-
doc/api/conf.py | 13 ++-
doc/api/expressions.rst | 8 +-
doc/changelog | 34 ++++++-
examples/djvu-crop-text | 6 +-
examples/djvu-dump-text | 2 +-
examples/djvu2png | 2 +-
private/mingw32-setup-env | 71 --------------
python_djvulibre.egg-info/PKG-INFO | 24 -----
python_djvulibre.egg-info/SOURCES.txt | 47 ---------
python_djvulibre.egg-info/dependency_links.txt | 1 -
python_djvulibre.egg-info/top_level.txt | 1 -
setup.cfg | 5 -
setup.py | 126 ++++++++++++++++---------
tests/test_decode.py | 14 +--
tests/test_sexpr.py | 50 ++++++++--
tests/tools.py | 16 ++--
20 files changed, 237 insertions(+), 273 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index 99e2001..e900d4b 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: python-djvulibre
-Version: 0.7.2
+Version: 0.8
Summary: Python support for the DjVu image format
Home-page: http://jwilk.net/software/python-djvulibre
Author: Jakub Wilk
@@ -9,13 +9,13 @@ License: GNU GPL 2
Description: *python-djvulibre* is a set of Python bindings for
the `DjVuLibre <http://djvu.sourceforge.net/>`_ library,
an open source implementation of `DjVu <http://djvu.org/>`_.
-Platform: all
+Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License (GPL)
Classifier: Operating System :: POSIX
-Classifier: Operating System :: Microsoft :: Windows :: Windows 95/98/2000
-Classifier: Operating System :: Microsoft :: Windows :: Windows NT/2000
+Classifier: Operating System :: Microsoft :: Windows
+Classifier: Programming Language :: Cython
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 3
diff --git a/djvu/decode.pyx b/djvu/decode.pyx
index 4962e2b..aad8f1e 100644
--- a/djvu/decode.pyx
+++ b/djvu/decode.pyx
@@ -1,4 +1,4 @@
-# Copyright © 2007-2015 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2007-2016 Jakub Wilk <jwilk at jwilk.net>
#
# This file is part of python-djvulibre.
#
@@ -14,7 +14,7 @@
#cython: autotestdict=False
'''
-DjVuLibre bindings: module for efficiently decoding and displaying DjVu documents.
+DjVuLibre bindings: module for efficiently decoding and displaying DjVu documents
Summary
-------
@@ -204,10 +204,13 @@ ELSE:
cdef extern from 'Python.h':
FILE* file_to_cfile 'PyFile_AsFile'(object)
int is_file 'PyFile_Check'(object)
-from posix.unistd cimport dup
+IF WINDOWS:
+ cdef extern from 'io.h' nogil:
+ int dup(int)
+ELSE:
+ from posix.unistd cimport dup
from libc.stdio cimport fclose
-cdef extern from 'unistd.h':
- FILE *fdopen(int, char*)
+from libc.stdio cimport fdopen
IF HAVE_LANGINFO_H:
cdef extern from 'langinfo.h':
@@ -1537,7 +1540,7 @@ cdef class Context:
which data is needed. The caller must then provide the raw data using
a NewStreamMessage.stream object.
- To open a local file, provide a FileUri instance as an uri.
+ To open a local file, provide a FileUri instance as a URI.
Localized characters in uri should be in URI-encoded.
@@ -2529,7 +2532,7 @@ cdef class ErrorMessage(Message):
cdef class InfoMessage(Message):
'''
- A InfoMessage provides informational text indicating the progress of the
+ An InfoMessage provides informational text indicating the progress of the
decoding process. This might be displayed in the browser status bar.
'''
diff --git a/djvu/dllpath.py b/djvu/dllpath.py
index bd4a30f..36dae63 100644
--- a/djvu/dllpath.py
+++ b/djvu/dllpath.py
@@ -1,6 +1,6 @@
# encoding=UTF-8
-# Copyright © 2011 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2011-2016 Jakub Wilk <jwilk at jwilk.net>
#
# This file is part of python-djvulibre.
#
@@ -14,7 +14,7 @@
# more details.
'''
-Module aimed to ease finding DjVuLibre DLLs in non-standard locations.
+ease finding DjVuLibre DLLs in non-standard locations
'''
import os
@@ -22,37 +22,58 @@ import os
if os.name != 'nt':
raise ImportError('This module is for Windows only')
-def guess_dll_path():
- import os
+import ctypes
+
+try:
+ # Python 3.X
+ import winreg
+ unicode = str
+except ImportError:
+ # Python 2.X
import _winreg as winreg
- registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
- try:
- key = winreg.OpenKey(registry, r'Software\Microsoft\Windows\CurrentVersion\Uninstall\DjVuLibre+DjView')
- try:
- value, tp = winreg.QueryValueEx(key, 'UninstallString')
+
+def _get(key, subkey):
+ unicode = type(b''.decode())
+ with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as registry:
+ with winreg.OpenKey(registry, key) as regkey:
+ value, tp = winreg.QueryValueEx(regkey, subkey)
+ del tp
if not isinstance(value, unicode):
- return
- path = os.path.dirname(value)
- if os.path.isfile(os.path.join(path, 'libdjvulibre.dll')):
- return path
- finally:
- winreg.CloseKey(key)
- except WindowsError:
+ raise TypeError
+ return value
+
+_djvulibre_key = r'Software\Microsoft\Windows\CurrentVersion\Uninstall\DjVuLibre+DjView'
+
+def guess_dll_path():
+ try:
+ path = _get(_djvulibre_key, 'UninstallString')
+ except (TypeError, WindowsError):
+ return
+ path = os.path.dirname(path)
+ if os.path.isfile(os.path.join(path, 'libdjvulibre.dll')):
+ return path
+
+def _guess_dll_version():
+ try:
+ version = _get(_djvulibre_key, 'DisplayVersion')
+ except (TypeError, WindowsError):
return
- finally:
- winreg.CloseKey(registry)
+ return version.split('+')[0]
def set_dll_search_path(path=None):
+ unicode = type(b''.decode())
if path is None:
path = guess_dll_path()
if path is None:
return
if not isinstance(path, unicode):
raise TypeError
- import ctypes
ctypes.windll.kernel32.SetDllDirectoryW(path)
return path
-del os
+__all__ = [
+ 'guess_dll_path',
+ 'set_dll_search_path'
+]
# vim:ts=4 sts=4 sw=4 et
diff --git a/djvu/sexpr.pyx b/djvu/sexpr.pyx
index 1f26d29..8ec9c15 100644
--- a/djvu/sexpr.pyx
+++ b/djvu/sexpr.pyx
@@ -119,8 +119,8 @@ cdef class _ExpressionIO:
cdef int (*backup_io_getc)()
cdef int (*backup_io_ungetc)(int c)
cdef int backup_io_7bit
- cdef object stdin
- cdef object stdout
+ cdef object stdin 'stdin_fp'
+ cdef object stdout 'stdout_fp'
cdef int stdout_binary
cdef object buffer
cdef object exc
diff --git a/doc/api/conf.py b/doc/api/conf.py
index 34519c4..bdf85a8 100644
--- a/doc/api/conf.py
+++ b/doc/api/conf.py
@@ -1,6 +1,6 @@
# encoding=UTF-8
-# Copyright © 2009-2015 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2009-2016 Jakub Wilk <jwilk at jwilk.net>
#
# This file is part of python-djvulibre.
#
@@ -13,15 +13,14 @@
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
-import os
import codecs
+import os
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.todo',
'sphinx.ext.coverage',
- 'sphinx.ext.pngmath',
'sphinx.ext.inheritance_diagram',
]
@@ -51,6 +50,7 @@ pygments_style = 'sphinx'
html_theme = 'haiku'
html_use_modindex = True
html_use_index = False
+html_static_path = ['static']
rst_epilog = '''
.. |djvu3ref| replace:: Lizardtech DjVu Reference
@@ -63,4 +63,11 @@ rst_epilog = '''
.. _djvuext: https://sourceforge.net/p/djvu/djvulibre-git/ci/release.3.5.23/tree/doc/djvuchanges.txt
'''
+# With a bit of our help, docutils is capable of rendering our simple formulas.
+# Sphinx math extension is not needed.
+import sphinx.writers.html
+del sphinx.writers.html.HTMLTranslator.visit_math
+def setup(app):
+ app.add_stylesheet('docutils-math.css')
+
# vim:ts=4 sts=4 sw=4 et
diff --git a/doc/api/expressions.rst b/doc/api/expressions.rst
index 14c52c8..3626725 100644
--- a/doc/api/expressions.rst
+++ b/doc/api/expressions.rst
@@ -84,7 +84,7 @@ S-expressions
>>> x
Expression(42)
>>> type(x)
- <class 'djvu.sexpr.IntExpression'>
+ <class 'djvu.sexpr.IntExpression'...>
>>> x.as_string()
'42'
>>> x.value
@@ -99,7 +99,7 @@ S-expressions
>>> x
Expression([4, 2])
>>> type(x)
- <class 'djvu.sexpr.ListExpression'>
+ <class 'djvu.sexpr.ListExpression'...>
>>> x.as_string()
'(4 2)'
>>> x.value
@@ -116,7 +116,7 @@ S-expressions
>>> x
Expression('eggs')
>>> type(x)
- <class 'djvu.sexpr.StringExpression'>
+ <class 'djvu.sexpr.StringExpression'...>
>>> x.as_string()
'"eggs"'
>>> x.value
@@ -131,7 +131,7 @@ S-expressions
>>> x
Expression(Symbol('ham'))
>>> type(x)
- <class 'djvu.sexpr.SymbolExpression'>
+ <class 'djvu.sexpr.SymbolExpression'...>
>>> x.as_string()
'ham'
>>> x.value
diff --git a/doc/changelog b/doc/changelog
index 5d0796e..181a75a 100644
--- a/doc/changelog
+++ b/doc/changelog
@@ -1,3 +1,31 @@
+python-djvulibre (0.8) unstable; urgency=low
+
+ * Fix Windows support. It is now possible to build the package using the
+ default compiler, Microsoft Visual C++ Compiler for Python.
+ https://github.com/jwilk/python-djvulibre/issues/1
+ + Remove support for cross-compiling using MinGW.
+ * Fix test failures on non-Linux systems.
+ * Improve documentation:
+ + Fix doctests' compatibility with Python 3.6.
+ + Don't require TeX distribution to render math formulas.
+ + Simplify some module docstrings.
+ + Fix typos in docstrings.
+ + Update bug tracker URLs.
+ The project repo has moved to GitHub.
+ * Improve the setup script:
+ + Check Cython version.
+ + Use “python -m cython” instead of the “cython” script.
+ + Report build-time requirements to pip.
+ + Don't use setuptools, except on Windows.
+ + Remove poorly standardized “platforms” metadata key. (The information
+ about supported platform is available in the “Operating System”
+ classifiers.)
+ + Add the “Programming Language :: Cython” classifier.
+ * Don't hardcode the Python interpreter path in script shebangs; use
+ “#!/usr/bin/env python” instead.
+
+ -- Jakub Wilk <jwilk at jwilk.net> Fri, 05 Aug 2016 22:52:25 +0200
+
python-djvulibre (0.7.2) unstable; urgency=low
* Fix compatibility with Cython 0.24.
@@ -80,7 +108,7 @@ python-djvulibre (0.4.1) unstable; urgency=low
* Exclude djvu/config.pxi from the source tarball.
Thanks to Daniel Stender for the bug report.
- https://bitbucket.org/jwilk/python-djvulibre/issues/4
+ https://github.com/jwilk/python-djvulibre/issues/4
-- Jakub Wilk <jwilk at jwilk.net> Mon, 27 Jul 2015 10:28:21 +0200
@@ -117,7 +145,7 @@ python-djvulibre (0.3.10) unstable; urgency=low
+ Fix test_bad_io failures with Cython ≥ 0.21.
* Improve setup.py:
+ Make it possible to build the package natively on Windows.
- https://bitbucket.org/jwilk/python-djvulibre/issue/1
+ https://github.com/jwilk/python-djvulibre/issues/1
* Use HTTPS URLs when they are available, in documentation and code.
-- Jakub Wilk <jwilk at jwilk.net> Tue, 04 Nov 2014 11:44:09 +0100
@@ -241,7 +269,7 @@ python-djvulibre (0.1.17) unstable; urgency=low
* Allow rendering images directly into a writable buffer (e.g. an array),
rather than to a newly created string. That should ease integration of
- python-djulibre with e.g. numpy or cairo.
+ python-djvulibre with e.g. numpy or cairo.
* Add two simple example programs.
-- Jakub Wilk <jwilk at jwilk.net> Thu, 11 Feb 2010 17:48:36 +0100
diff --git a/examples/djvu-crop-text b/examples/djvu-crop-text
index 3bd305b..09ae43e 100755
--- a/examples/djvu-crop-text
+++ b/examples/djvu-crop-text
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# encoding=UTF-8
# Copyright © 2008-2015 Jakub Wilk <jwilk at jwilk.net>
@@ -84,7 +84,7 @@ class Context(djvu.decode.Context):
text = EMPTY_TEXT_SEXPR
return text
- def process(self, path, pages = None):
+ def process(self, path, pages=None):
print('Processing {path!r}:'.format(path=path), file=sys.stderr)
document = self.new_document(djvu.decode.FileURI(path))
document.decoding_job.wait()
@@ -92,7 +92,7 @@ class Context(djvu.decode.Context):
if pages is None:
pages = iter(document.pages)
else:
- pages = (document.pages[i-1] for i in pages)
+ pages = (document.pages[i - 1] for i in pages)
sed_file.write('remove-txt\n')
for page in pages:
sed_file.write('select {0}\n'.format(page.n + 1))
diff --git a/examples/djvu-dump-text b/examples/djvu-dump-text
index d31eb2a..73d11ac 100755
--- a/examples/djvu-dump-text
+++ b/examples/djvu-dump-text
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# encoding=UTF-8
# Copyright © 2008-2015 Jakub Wilk <jwilk at jwilk.net>
diff --git a/examples/djvu2png b/examples/djvu2png
index 5b0b3e1..0f8367f 100755
--- a/examples/djvu2png
+++ b/examples/djvu2png
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# encoding=UTF-8
# Copyright © 2010-2015 Jakub Wilk <jwilk at jwilk.net>
diff --git a/private/mingw32-setup-env b/private/mingw32-setup-env
deleted file mode 100755
index c58d2a8..0000000
--- a/private/mingw32-setup-env
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/bin/sh
-
-# Copyright © 2010-2016 Jakub Wilk <jwilk at jwilk.net>
-#
-# This file is part of python-djvulibre.
-#
-# python-djvulibre is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 as published by
-# the Free Software Foundation.
-#
-# python-djvulibre is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
-
-if [ $# -ne 1 ]
-then
- printf 'Usage: %s <target>\n\n<target> is e.g. i686-w64-mingw32\n\n' "$0"
- exit 1
-fi
-
-set -e -x
-
-target="$1"
-pwd=$(pwd)
-mkdir -p "$target/common/"
-tmpdir=$(mktemp -d -t python-djvulibre.mingw32.XXXXXX) || exit 1
-cd "$tmpdir"
-wget -i - <<EOF
-https://downloads.sourceforge.net/project/djvu/DjVuLibre_Windows/3.5.23%2B4.6/DjVuLibre%2BDjView-3.5.23b%2B4.6-Setup.exe
-https://www.python.org/ftp/python/2.6.6/python-2.6.6.msi
-https://www.python.org/ftp/python/2.7.1/python-2.7.1.msi
-https://www.python.org/ftp/python/3.1.2/python-3.1.2.msi
-https://www.python.org/ftp/python/3.2/python-3.2.msi
-EOF
-sha256sum -c - << EOF
-3b986a2fbb1c35a91750ae0d29232c111a52883bd99eb14d20805bc9f5592203 DjVuLibre+DjView-3.5.23b+4.6-Setup.exe
-1192931440475d07fb3e9724531a53de34097ad24e519bff2e5f458c375a31b3 python-2.6.6.msi
-0af8bc05a5f9ed15df120150c6a6ddd0fc50d018e35b891cba22040e0404dfb6 python-2.7.1.msi
-ca802f144a7e8268a773fa2567fecb0a1d792c62c00f751f27d103a263352113 python-3.1.2.msi
-3132305f1b19905178be0f76206ebeeebbf35e5ccef367f6f22cd32aef1d6e56 python-3.2.msi
-EOF
-WINEPREFIX="$tmpdir" wine DjVuLibre*exe /S
-for version in 2.6 2.7 3.1 3.2
-do
- mkdir -p "$pwd/$target/python$version/"
- cabextract -d "$pwd/$target/python$version/" -F '*.h' python-$version*.msi
- cabextract -d "$pwd/$target/python$version/" -F 'python*.dll' python-$version*.msi
- for file in msvcr90.dll libmsvcr.a libdjvulibre.dll libjpeg.dll libdjvu
- do
- ln -sf "../common/$file" "$pwd/$target/python$version/$file"
- done
-done
-cabextract -d "$pwd/$target/common/" -F 'msvcr90.dll' python-2.6*.msi
-cat > msvcr.def <<EOF
-EXPORTS
-__dllonexit
-_assert
-_errno
-fflush
-free
-malloc
-EOF
-"$target-dlltool" --kill-at --def msvcr.def --dllname msvcr90.dll --output-lib "$pwd/$target/common/libmsvcr.a"
-cd 'drive_c/Program Files/DjVuZone/DjVuLibre/'
-cp -v libdjvulibre.dll libjpeg.dll "$pwd/$target/common/"
-cp -vr include/libdjvu "$pwd/$target/common/"
-cd /
-rm -Rf "$tmpdir"
-
-# vim:ts=4 sts=4 sw=4 et
diff --git a/python_djvulibre.egg-info/PKG-INFO b/python_djvulibre.egg-info/PKG-INFO
deleted file mode 100644
index 99e2001..0000000
--- a/python_djvulibre.egg-info/PKG-INFO
+++ /dev/null
@@ -1,24 +0,0 @@
-Metadata-Version: 1.1
-Name: python-djvulibre
-Version: 0.7.2
-Summary: Python support for the DjVu image format
-Home-page: http://jwilk.net/software/python-djvulibre
-Author: Jakub Wilk
-Author-email: jwilk at jwilk.net
-License: GNU GPL 2
-Description: *python-djvulibre* is a set of Python bindings for
- the `DjVuLibre <http://djvu.sourceforge.net/>`_ library,
- an open source implementation of `DjVu <http://djvu.org/>`_.
-Platform: all
-Classifier: Development Status :: 4 - Beta
-Classifier: Intended Audience :: Developers
-Classifier: License :: OSI Approved :: GNU General Public License (GPL)
-Classifier: Operating System :: POSIX
-Classifier: Operating System :: Microsoft :: Windows :: Windows 95/98/2000
-Classifier: Operating System :: Microsoft :: Windows :: Windows NT/2000
-Classifier: Programming Language :: Python
-Classifier: Programming Language :: Python :: 2
-Classifier: Programming Language :: Python :: 3
-Classifier: Topic :: Multimedia :: Graphics
-Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
-Classifier: Topic :: Text Processing
diff --git a/python_djvulibre.egg-info/SOURCES.txt b/python_djvulibre.egg-info/SOURCES.txt
deleted file mode 100644
index 6e4ea0c..0000000
--- a/python_djvulibre.egg-info/SOURCES.txt
+++ /dev/null
@@ -1,47 +0,0 @@
-MANIFEST.in
-setup.py
-djvu/__init__.py
-djvu/common.pxi
-djvu/const.py
-djvu/decode.pxd
-djvu/decode.pyx
-djvu/dllpath.py
-djvu/sexpr.pxd
-djvu/sexpr.pyx
-doc/COPYING
-doc/build-reqs.txt
-doc/changelog
-doc/credits.txt
-doc/todo.txt
-doc/api/annotations.rst
-doc/api/conf.py
-doc/api/documents.rst
-doc/api/event-model.rst
-doc/api/exceptions.rst
-doc/api/expressions.rst
-doc/api/files.rst
-doc/api/geometry.rst
-doc/api/index.rst
-doc/api/messages.rst
-doc/api/outline.rst
-doc/api/pages.rst
-doc/api/text-zones.rst
-examples/djvu-crop-text
-examples/djvu-dump-text
-examples/djvu2png
-private/apt-install-build-reqs
-private/build-and-test
-private/mingw32-setup-env
-python_djvulibre.egg-info/PKG-INFO
-python_djvulibre.egg-info/SOURCES.txt
-python_djvulibre.egg-info/dependency_links.txt
-python_djvulibre.egg-info/top_level.txt
-tests/sexpr-gc.py
-tests/test_const.py
-tests/test_decode.py
-tests/test_sexpr.py
-tests/tools.py
-tests/images/Makefile
-tests/images/test0.djvu
-tests/images/test0.tex
-tests/images/test1.djvu
\ No newline at end of file
diff --git a/python_djvulibre.egg-info/dependency_links.txt b/python_djvulibre.egg-info/dependency_links.txt
deleted file mode 100644
index 8b13789..0000000
--- a/python_djvulibre.egg-info/dependency_links.txt
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/python_djvulibre.egg-info/top_level.txt b/python_djvulibre.egg-info/top_level.txt
deleted file mode 100644
index 9a8b15a..0000000
--- a/python_djvulibre.egg-info/top_level.txt
+++ /dev/null
@@ -1 +0,0 @@
-djvu
diff --git a/setup.cfg b/setup.cfg
deleted file mode 100644
index 861a9f5..0000000
--- a/setup.cfg
+++ /dev/null
@@ -1,5 +0,0 @@
-[egg_info]
-tag_build =
-tag_date = 0
-tag_svn_revision = 0
-
diff --git a/setup.py b/setup.py
index 6deaa04..9567454 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
# encoding=UTF-8
-# Copyright © 2007-2015 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2007-2016 Jakub Wilk <jwilk at jwilk.net>
#
# This file is part of python-djvulibre.
#
@@ -24,8 +24,8 @@ Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: GNU General Public License (GPL)
Operating System :: POSIX
-Operating System :: Microsoft :: Windows :: Windows 95/98/2000
-Operating System :: Microsoft :: Windows :: Windows NT/2000
+Operating System :: Microsoft :: Windows
+Programming Language :: Cython
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 3
@@ -36,30 +36,20 @@ Topic :: Text Processing
import glob
import os
-import sys
import subprocess as ipc
+import re
+import sys
-if os.name == 'posix' and os.getenv('python_djvulibre_mingw32'):
- import mingw32cross
-else:
- mingw32cross = None
-
+need_setuptools = False
if os.name == 'nt':
import djvu.dllpath
+ need_setuptools = True
-# Just to make sure setuptools won't try to be clever:
-fake_module = type(sys)('fake_module')
-fake_module.build_ext = None
-sys.modules['Pyrex'] = sys.modules['Pyrex.Distutils'] = sys.modules['Pyrex.Distutils.build_ext'] = fake_module
-del fake_module
-
-try:
- import setuptools as distutils_core
+if need_setuptools:
import setuptools.extension
assert setuptools.extension.have_pyrex
-except ImportError:
- import distutils.core as distutils_core
-import distutils
+
+import distutils.core
import distutils.ccompiler
import distutils.command.build_ext
import distutils.dep_util
@@ -80,18 +70,17 @@ def ext_modules():
yield module
ext_modules = list(ext_modules())
-def get_version():
- open_opts = {}
+def uopen(path):
if str != bytes:
- open_opts.update(encoding='UTF-8')
- changelog = open(
- os.path.join(os.path.dirname(__file__), 'doc', 'changelog'),
- **open_opts
- )
- try:
- return changelog.readline().split()[1].strip('()')
- finally:
- changelog.close()
+ return open(path, 'rt', encoding='UTF-8')
+ else:
+ return open(path, 'rt')
+
+def get_version():
+ path = os.path.join(os.path.dirname(__file__), 'doc', 'changelog')
+ with uopen(path) as file:
+ line = file.readline()
+ return line.split()[1].strip('()')
def run_pkgconfig(*cmdline):
cmdline = ['pkg-config'] + list(cmdline)
@@ -100,9 +89,8 @@ def run_pkgconfig(*cmdline):
cmdline,
stdout=ipc.PIPE, stderr=ipc.PIPE
)
- except EnvironmentError:
- _, exc, _ = sys.exc_info()
- msg = 'cannot execute pkg-config: {exc}'.format(exc=exc)
+ except EnvironmentError as exc:
+ msg = 'cannot execute pkg-config: {exc.strerror}'.format(exc=exc)
distutils.log.warn(msg)
return
stdout, stderr = pkgconfig.communicate()
@@ -127,8 +115,9 @@ def pkgconfig_build_flags(*packages, **kwargs):
dll_path = djvu.dllpath.guess_dll_path()
if dll_path is not None:
fallback.update(
- extra_compile_args=['-I' + os.path.join(dll_path, 'include')],
- extra_link_args=['-L' + os.path.join(dll_path)],
+ include_dirs=[os.path.join(dll_path, 'include')],
+ library_dirs=[os.path.join(dll_path)],
+ libraries=['libdjvulibre'],
)
stdout = run_pkgconfig('--libs', '--cflags', *packages)
if stdout is None:
@@ -146,17 +135,42 @@ def pkgconfig_build_flags(*packages, **kwargs):
return kwargs
def pkgconfig_version(package):
- V = distutils.version.LooseVersion
stdout = run_pkgconfig('--modversion', package)
if stdout is None:
+ return
+ return stdout.strip()
+
+def get_djvulibre_version():
+ version = pkgconfig_version('ddjvuapi')
+ if version is None:
if os.name == 'posix':
raise RuntimeError('cannot determine DjVuLibre version')
- return V('0')
- version = stdout.strip()
- return V(version)
+ elif os.name == 'nt':
+ version = djvu.dllpath._guess_dll_version()
+ version = version or '0'
+ return distutils.version.LooseVersion(version)
+
+def get_cython_version():
+ cmdline = ['python', '-m', 'cython', '--version']
+ cmd = ipc.Popen(cmdline, stdout=ipc.PIPE, stderr=ipc.STDOUT)
+ stdout, stderr = cmd.communicate()
+ if not isinstance(stdout, str):
+ stdout = stdout.decode('ASCII')
+ match = re.match(r'\ACython version (\d\S+)', stdout)
+ if match:
+ ver = match.group(1)
+ else:
+ ver = '0'
+ return distutils.version.LooseVersion(ver)
-djvulibre_version = pkgconfig_version('ddjvuapi')
py_version = get_version()
+cython_version = get_cython_version()
+if str != bytes:
+ # Python 3.X
+ req_cython_version = '0.20'
+else:
+ # Python 2.X
+ req_cython_version = '0.19'
# Work-around for <https://bugs.python.org/issue969718>:
os.environ.pop('CFLAGS', None)
@@ -164,13 +178,15 @@ os.environ.pop('CFLAGS', None)
class build_ext(distutils.command.build_ext.build_ext):
def run(self):
+ djvulibre_version = get_djvulibre_version()
if djvulibre_version != '0' and djvulibre_version < '3.5.21':
raise RuntimeError('DjVuLibre >= 3.5.21 is required')
new_config = [
'DEF PY3K = {0}'.format(sys.version_info >= (3, 0)),
'DEF PYTHON_DJVULIBRE_VERSION = b"{0}"'.format(py_version),
'DEF HAVE_MINIEXP_IO_T = {0}'.format(djvulibre_version >= '3.5.26'),
- 'DEF HAVE_LANGINFO_H = {0}'.format(os.name == 'posix' and not mingw32cross),
+ 'DEF HAVE_LANGINFO_H = {0}'.format(os.name == 'posix'),
+ 'DEF WINDOWS = {0}'.format(os.name == 'nt'),
]
self.src_dir = src_dir = os.path.join(self.build_temp, 'src')
distutils.dir_util.mkpath(src_dir)
@@ -206,8 +222,10 @@ class build_ext(distutils.command.build_ext.build_ext):
continue
distutils.log.info('cythoning {ext.name!r} extension'.format(ext=ext))
def build_c(source, target):
+ if cython_version < req_cython_version:
+ raise RuntimeError('Cython >= {ver} is required'.format(ver=req_cython_version))
distutils.spawn.spawn([
- 'cython',
+ 'python', '-m', 'cython',
'-I', os.path.dirname(self.config_path),
'-o', target,
source,
@@ -235,7 +253,7 @@ else:
compiler_flags = pkgconfig_build_flags('ddjvuapi')
-setup_params = dict(
+meta = dict(
name='python-djvulibre',
version=py_version,
author='Jakub Wilk',
@@ -245,7 +263,9 @@ setup_params = dict(
long_description=__doc__.strip(),
classifiers=classifiers,
url='http://jwilk.net/software/python-djvulibre',
- platforms=['all'],
+)
+
+setup_params = dict(
packages=['djvu'],
ext_modules=[
distutils.command.build_ext.Extension(
@@ -261,10 +281,22 @@ setup_params = dict(
(cmd.__name__, cmd)
for cmd in (build_ext, build_sphinx)
if cmd is not None
- )
+ ),
+ **meta
)
if __name__ == '__main__':
- distutils_core.setup(**setup_params)
+ if 'setuptools' in sys.modules and sys.argv[1] == 'egg_info':
+ # We wouldn't normally want setuptools; but pip forces it upon us anyway,
+ # so let's abuse it to instruct pip to install Cython if it's missing.
+ distutils.core.setup(
+ install_requires=['Cython>={ver}'.format(ver=req_cython_version)],
+ # Conceptually, “setup_requires” would make more sense than
+ # “install_requires”, but the former is not supported by pip:
+ # https://github.com/pypa/pip/issues/1820
+ **meta
+ )
+ else:
+ distutils.core.setup(**setup_params)
# vim:ts=4 sts=4 sw=4 et
diff --git a/tests/test_decode.py b/tests/test_decode.py
index d0445e6..4967ce6 100644
--- a/tests/test_decode.py
+++ b/tests/test_decode.py
@@ -109,18 +109,16 @@ else:
def run(*cmd, **kwargs):
stdin = kwargs.pop('stdin', None)
- env = {}
+ env = dict(os.environ)
for key, value in kwargs.items():
if key.isupper():
env[key] = value
continue
raise TypeError('{key!r} is an invalid keyword argument for this function'.format(key=key))
- def preexec_fn():
- os.environ.update(env)
kwargs = dict(
- preexec_fn=preexec_fn,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
+ env=env,
)
if stdin is not None:
kwargs.update(stdin=subprocess.PIPE)
@@ -172,8 +170,7 @@ class test_documents:
path = '__nonexistent__'
try:
os.stat(path)
- except OSError:
- _, ex, _ = sys.exc_info()
+ except OSError as ex:
c_message = ex.args[1]
else:
raise OSError(errno.EEXIST, os.strerror(errno.EEXIST), path)
@@ -200,8 +197,7 @@ class test_documents:
try:
with interim_locale(LC_ALL='ja_JP.UTF-8'):
os.stat(path)
- except OSError:
- _, ex, _ = sys.exc_info()
+ except OSError as ex:
c_message = ex.args[1]
else:
raise OSError(errno.EEXIST, os.strerror(errno.EEXIST), path)
@@ -537,7 +533,7 @@ class test_page_jobs():
page_job.render(RENDER_COLOR, (0, 0, 10, 10), (0, 0, 10, 10), PixelFormatRgb(), -1)
with assert_raises_regex(MemoryError, r'\AUnable to allocate [0-9]+ bytes for an image memory\Z'):
- x = int((maxsize//2) ** 0.5)
+ x = int((maxsize // 2) ** 0.5)
page_job.render(RENDER_COLOR, (0, 0, x, x), (0, 0, x, x), PixelFormatRgb(), 8)
s = page_job.render(RENDER_COLOR, (0, 0, 10, 10), (0, 0, 4, 4), PixelFormatGrey(), 1)
diff --git a/tests/test_sexpr.py b/tests/test_sexpr.py
index 9379a78..376fc24 100644
--- a/tests/test_sexpr.py
+++ b/tests/test_sexpr.py
@@ -1,6 +1,6 @@
# encoding=UTF-8
-# Copyright © 2007-2015 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2007-2016 Jakub Wilk <jwilk at jwilk.net>
#
# This file is part of python-djvulibre.
#
@@ -13,11 +13,14 @@
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
-import collections
import codecs
+import collections
import copy
import errno
import io
+import os
+import shutil
+import sys
import tempfile
import pickle
@@ -537,10 +540,20 @@ class test_expression_parser():
Expression.from_stream(42)
def test_bad_file_io(self):
+ if os.name == 'nt':
+ raise SkipTest('not implemented on Windows')
+ path = '/proc/self/mem'
+ try:
+ os.stat(path)
+ except OSError as exc:
+ raise SkipTest('{exc.filename}: {exc.strerror}'.format(exc=exc))
with open('/proc/self/mem') as fp:
with assert_raises(IOError) as ecm:
Expression.from_stream(fp)
- assert_equal(ecm.exception.errno, errno.EIO)
+ assert_in(
+ ecm.exception.errno,
+ (errno.EIO, errno.EFAULT)
+ )
if py3k:
def test_bad_unicode_io(self):
@@ -583,11 +596,15 @@ class test_expression_parser_ascii():
self.t(fp)
def test_codecs_io(self):
- with tempfile.NamedTemporaryFile(mode='w+b') as bfp:
- with codecs.open(bfp.name, mode='w+', encoding='UTF-16-LE') as fp:
+ tmpdir = tempfile.mkdtemp()
+ try:
+ path = os.path.join(tmpdir, 'tmp')
+ with codecs.open(path, mode='w+', encoding='UTF-16-LE') as fp:
fp.write(u(self.expr))
fp.seek(0)
self.t(fp)
+ finally:
+ shutil.rmtree(tmpdir)
def test_file_io_binary(self):
with tempfile.TemporaryFile(mode='w+b') as fp:
@@ -612,7 +629,12 @@ class test_expression_writer():
def test_bad_file_io(self):
ecm = None
- fp = open('/dev/full', 'w', buffering=2)
+ path = '/dev/full'
+ try:
+ os.stat(path)
+ except OSError as exc:
+ raise SkipTest('{exc.filename}: {exc.strerror}'.format(exc=exc))
+ fp = open(path, 'w', buffering=2)
expr = Expression(23)
try:
with assert_raises(IOError) as ecm:
@@ -685,18 +707,26 @@ class test_expression_writer_ascii():
assert_equal(fp.read(), self.urepr)
def test_codecs_io_text_7(self):
- with tempfile.NamedTemporaryFile(mode='w+b') as bfp:
- with codecs.open(bfp.name, mode='w+', encoding='UTF-16-LE') as fp:
+ tmpdir = tempfile.mkdtemp()
+ try:
+ path = os.path.join(tmpdir, 'tmp')
+ with codecs.open(path, mode='w+', encoding='UTF-16-LE') as fp:
self.expr.print_into(fp)
fp.seek(0)
assert_equal(fp.read(), self.repr)
+ finally:
+ shutil.rmtree(tmpdir)
def test_codecs_io_text_8(self):
- with tempfile.NamedTemporaryFile(mode='w+b') as bfp:
... 67 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-djvulibre.git
More information about the Python-modules-commits
mailing list