[Python-modules-commits] [pypandoc] 01/05: Import pypandoc_1.4+ds0.orig.tar.gz
Elena Grandi
valhalla-guest at moszumanska.debian.org
Fri May 19 17:36:39 UTC 2017
This is an automated email from the git hooks/post-receive script.
valhalla-guest pushed a commit to branch master
in repository pypandoc.
commit 815856f6cf3fa9d8728011d2273931ae0e1ff548
Author: Elena Grandi <valhalla-d at trueelena.org>
Date: Fri May 19 19:00:02 2017 +0200
Import pypandoc_1.4+ds0.orig.tar.gz
---
README.md | 97 +++++++++++++++++++++++++--------------------
pypandoc/__init__.py | 8 ++--
pypandoc/pandoc_download.py | 62 ++++++++++++++++++++++-------
setup.cfg | 1 -
setup.py | 9 +++++
tests.py | 29 ++++++++------
6 files changed, 132 insertions(+), 74 deletions(-)
diff --git a/README.md b/README.md
index 6749f45..6b4b43a 100644
--- a/README.md
+++ b/README.md
@@ -1,22 +1,27 @@
# pypandoc
[](https://travis-ci.org/bebraw/pypandoc)
+[](https://ci.appveyor.com/project/bebraw/pypandoc)
+[](https://github.com/bebraw/pypandoc/releases)
[](https://pypi.python.org/pypi/pypandoc/)
[](https://anaconda.org/conda-forge/pypandoc/)
+[](https://pypi.python.org/pypi/pypandoc/)
+[](https://pypi.python.org/pypi/pypandoc/)
+
-pypandoc provides a thin wrapper for [pandoc](http://johnmacfarlane.net/pandoc/), a universal
+Pypandoc provides a thin wrapper for [pandoc](https://pandoc.org), a universal
document converter.
## Installation
-pypandoc uses `pandoc`, so it needs an available installation of `pandoc`. For some common cases
-(wheels, conda packages), pypandoc already includes `pandoc` (and `pandoc_citeproc`) in it's
+Pypandoc uses pandoc, so it needs an available installation of pandoc. For some common cases
+(wheels, conda packages), pypandoc already includes pandoc (and pandoc-citeproc) in it's
prebuilt package.
-If `pandoc` is already installed (`pandoc` is in the PATH), `pypandoc` uses the version with the
-higher version number and if both are the same, the already installed version. See [Specifying the location of pandoc binaries](#specifying_binaries) for more.
+If pandoc is already installed (i.e. pandoc is in the `PATH`), pypandoc uses the version with the
+higher version number, and if both are the same, the already installed version. See [Specifying the location of pandoc binaries](#specifying-the-location-of-pandoc-binaries) for more.
-To use `pandoc` filters, you must have the relevant filter installed on your machine.
+To use pandoc filters, you must have the relevant filters installed on your machine.
### Installing via pip
@@ -24,18 +29,18 @@ Install via `pip install pypandoc`.
Prebuilt [wheels for Windows and Mac OS X](https://pypi.python.org/pypi/pypandoc/) include
pandoc. If there is no prebuilt binary available, you have to
-[install `pandoc` yourself](#installing-pandoc-manually).
+[install pandoc yourself](#installing-pandoc-manually).
-If you use Linux and have [your own wheelhouse](http://wheel.readthedocs.org/en/latest/#usage),
-you can build a wheel which include `pandoc` with
+If you use Linux and have [your own wheelhouse](https://wheel.readthedocs.org/en/latest/#usage),
+you can build a wheel which include pandoc with
`python setup.py download_pandoc; python setup.py bdist_wheel`. Be aware that this works only
on 64bit intel systems, as we only download it from the
-[official source](https://github.com/jgm/pandoc/releases).
+[official releases](https://github.com/jgm/pandoc/releases).
### Installing via conda
-`pypandoc` is included in [conda-forge](https://conda-forge.github.io/). The conda packages will
-also install the `pandoc` package, so `pandoc` is available in the installation.
+Pypandoc is included in [conda-forge](https://conda-forge.github.io/). The conda packages will
+also install the pandoc package, so pandoc is available in the installation.
Install via `conda install -c conda-forge pypandoc`.
@@ -45,28 +50,30 @@ use `conda install pypandoc` directly and also lets you update via `conda update
### Installing pandoc
-If you don't get `pandoc` installed via a prebuild wheel which includes `pandoc` or via the
-conda package dependencies, you need to install `pandoc` by yourself.
+If you don't get pandoc installed via a prebuild wheel which includes pandoc or via the
+conda package dependencies, you need to install pandoc by yourself.
#### Installing pandoc via pypandoc
-Installing via pypandoc is possible on Windows, Mac OS X or Linux (Intel-based):
+Installing via pypandoc is possible on Windows, Mac OS X or Linux (Intel-based, 64-bit):
```python
-# expects a installed pypandoc: pip install pypandoc
+# expects an installed pypandoc: pip install pypandoc
from pypandoc.pandoc_download import download_pandoc
# see the documentation how to customize the installation path
-# but be aware that you then need to include it in the PATH
+# but be aware that you then need to include it in the `PATH`
download_pandoc()
```
-The default install location is included in the search path for `pandoc`, so you
-don't need to add it to `PATH`.
+The default install location is included in the search path for pandoc, so you
+don't need to add it to the `PATH`.
+
+By default, the latest pandoc version is installed. If you want to specify your own version, say 1.19.1, use `download_pandoc(version='1.19.1')` instead.
#### Installing pandoc manually
Installing manually via the system mechanism is also possible. Such installation mechanism
-make `pandoc` available on many more platforms:
+make pandoc available on many more platforms:
- Ubuntu/Debian: `sudo apt-get install pandoc`
- Fedora/Red Hat: `sudo yum install pandoc`
@@ -74,18 +81,18 @@ make `pandoc` available on many more platforms:
- Mac OS X with Homebrew: `brew install pandoc pandoc-citeproc Caskroom/cask/mactex`
- Machine with Haskell: `cabal-install pandoc`
- Windows: There is an installer available
- [here](http://johnmacfarlane.net/pandoc/installing.html)
-- [FreeBSD port](http://www.freshports.org/textproc/pandoc/)
- - Or see http://johnmacfarlane.net/pandoc/installing.html
+ [here](https://pandoc.org/installing.html)
+- [FreeBSD port](https://www.freshports.org/textproc/pandoc/)
+ - Or see [Pandoc - Installing pandoc](https://pandoc.org/installing.html)
-Be aware that not all install mechanismen put `pandoc` in `PATH`, so you either
-have to change `PATH` yourself or set the full path to `pandoc` in
+Be aware that not all install mechanisms put pandoc in the `PATH`, so you either
+have to change the `PATH` yourself or set the full `PATH` to pandoc in
`PYPANDOC_PANDOC`. See the next section for more information.
-### <a name="specifying_binaries"></a>Specifying the location of pandoc binaries
+### Specifying the location of pandoc binaries
You can point to a specific pandoc version by setting the environment variable
-`PYPANDOC_PANDOC` to the full path to the pandoc binary
+`PYPANDOC_PANDOC` to the full `PATH` to the pandoc binary
(`PYPANDOC_PANDOC=/home/x/whatever/pandoc` or `PYPANDOC_PANDOC=c:\pandoc\pandoc.exe`).
If this environment variable is set, this is the only place where pandoc is searched for.
@@ -99,7 +106,7 @@ os.environ.setdefault('PYPANDOC_PANDOC', '/home/x/whatever/pandoc')
## Usage
-There are two basic ways to use `pypandoc`: with input files or with input
+There are two basic ways to use pypandoc: with input files or with input
strings.
@@ -121,7 +128,7 @@ output = pypandoc.convert_text('#some title', 'rst', format='md')
`convert_text` expects this string to be unicode or utf-8 encoded bytes. `convert_*` will always
return a unicode string.
-It's also possible to directly let `pandoc` write the output to a file. This is the only way to
+It's also possible to directly let pandoc write the output to a file. This is the only way to
convert to some output formats (e.g. odt, docx, epub, epub3, pdf). In that case `convert_*()` will
return an empty string.
@@ -133,7 +140,7 @@ assert output == ""
```
In addition to `format`, it is possible to pass `extra_args`.
-That makes it possible to access various `pandoc` options easily.
+That makes it possible to access various pandoc options easily.
```python
output = pypandoc.convert_text(
@@ -147,8 +154,9 @@ output = pypandoc.convert(
extra_args=['--base-header-level=2'])
# output == '<h2 id="primary-heading">Primary Heading</h2>\r\n'
```
+
pypandoc now supports easy addition of
-[pandoc filters](http://johnmacfarlane.net/pandoc/scripting.html).
+[pandoc filters](https://pandoc.org/scripting.html).
```python
filters = ['pandoc-citeproc']
@@ -160,10 +168,11 @@ output = pd.convert_file(source=filename,
extra_args=pdoc_args,
filters=filters)
```
+
Please pass any filters in as a list and not as a string.
Please refer to `pandoc -h` and the
-[official documentation](http://johnmacfarlane.net/pandoc/README.html) for further details.
+[official documentation](https://pandoc.org/MANUAL.html) for further details.
> Note: the old way of using `convert(input, output)` is deprecated as in some cases it wasn't
possible to determine whether the input should be used as a filename or as text.
@@ -184,8 +193,8 @@ it won't work. This gotcha has to do with the way
## Getting Pandoc Version
-As it can be useful sometimes to check what Pandoc version is available at your system or which
-particular `pandoc` binary is used by `pypandoc`. For that, `pypandoc` provides the following
+As it can be useful sometimes to check what pandoc version is available at your system or which
+particular pandoc binary is used by pypandoc. For that, pypandoc provides the following
utility functions. Example:
```
@@ -197,9 +206,10 @@ print(pypandoc.get_pandoc_formats())
## Related
* [pydocverter](https://github.com/msabramo/pydocverter) is a client for a service called
-[Docverter](http://www.docverter.com/), which offers `pandoc` as a service (plus some extra goodies).
-* See [pyandoc](http://pypi.python.org/pypi/pyandoc/) for an alternative implementation of a `pandoc`
+[Docverter](https://www.docverter.com), which offers pandoc as a service (plus some extra goodies).
+* See [pyandoc](https://pypi.python.org/pypi/pyandoc/) for an alternative implementation of a pandoc
wrapper from Kenneth Reitz. This one hasn't been active in a while though.
+* See [panflute](https://github.com/sergiocorreia/panflute) which provides `convert_text` similar to pypandoc's. Its focus is on writing and running pandoc filters though.
## Contributing
@@ -217,27 +227,28 @@ Note that for citeproc tests to pass you'll need to have [pandoc-citeproc](https
* [Valentin Haenel](https://github.com/esc) - String conversion fix
* [Daniel Sanchez](https://github.com/ErunamoJAZZ) - Automatic parsing of input/output formats
* [Thomas G.](https://github.com/coldfix) - Python 3 support
-* [Ben Jao Ming](https://github.com/benjaoming) - Fail gracefully if `pandoc` is missing
-* [Ross Crawford-d'Heureuse](http://github.com/rosscdh) - Encode input in UTF-8 and add Django
+* [Ben Jao Ming](https://github.com/benjaoming) - Fail gracefully if pandoc is missing
+* [Ross Crawford-d'Heureuse](https://github.com/rosscdh) - Encode input in UTF-8 and add Django
example
* [Michael Chow](https://github.com/machow) - Decode output in UTF-8
* [Janusz Skonieczny](https://github.com/wooyek) - Support Windows newlines and allow encoding to
be specified.
* [gabeos](https://github.com/gabeos) - Fix help parsing
-* [Marc Abramowitz](https://github.com/msabramo) - Make `setup.py` fail hard if `pandoc` is
+* [Marc Abramowitz](https://github.com/msabramo) - Make `setup.py` fail hard if pandoc is
missing, Travis, Dockerfile, PyPI badge, Tox, PEP-8, improved documentation
* [Daniel L.](https://github.com/mcktrtl) - Add `extra_args` example to README
* [Amy Guy](https://github.com/rhiaro) - Exception handling for unicode errors
* [Florian Eßer](https://github.com/flesser) - Allow Markdown extensions in output format
* [Philipp Wendler](https://github.com/PhilippWendler) - Allow Markdown extensions in input format
-* [Jan Schulz](https://github.com/JanSchulz) - Handling output to a file, Travis to work on newer version of Pandoc, return code checking, get_pandoc_version. Helped to fix the Travis build, new `convert_*` API
+* [Jan Schulz](https://github.com/JanSchulz) - Handling output to a file, Travis to work on newer version of pandoc, return code checking, get_pandoc_version. Helped to fix the Travis build, new `convert_*` API
* [Aaron Gonzales](https://github.com/xysmas) - Added better filter handling
* [David Lukes](https://github.com/dlukes) - Enabled input from non-plain-text files and made sure tests clean up template files correctly if they fail
* [valholl](https://github.com/valholl) - Set up licensing information correctly and include examples to distribution version
-* [Cyrille Rossant](https://github.com/rossant) - Fixed bug by trimming out stars in the list of `pandoc` formats. Helped to fix the Travis build.
-* [Paul Osborne](https://github.com/posborne) - Don't require `pandoc` to install pypandoc.
+* [Cyrille Rossant](https://github.com/rossant) - Fixed bug by trimming out stars in the list of pandoc formats. Helped to fix the Travis build.
+* [Paul Osborne](https://github.com/posborne) - Don't require pandoc to install pypandoc.
* [Felix Yan](https://github.com/felixonmars) - Added installation instructions for Arch Linux.
+* [Kolen Cheung](https://github.com/ickc) - Implement `_get_pandoc_urls` for installing arbitrary version as well as the latest version of pandoc. Minor: README, Travis, setup.py.
## License
-`pypandoc` is available under MIT license. See LICENSE for more details. `pandoc` itself is [available under the GPL2 license](https://github.com/jgm/pandoc/blob/master/COPYING).
+Pypandoc is available under MIT license. See LICENSE for more details. Pandoc itself is [available under the GPL2 license](https://github.com/jgm/pandoc/blob/master/COPYING.md).
diff --git a/pypandoc/__init__.py b/pypandoc/__init__.py
index 8da7529..abde4e3 100644
--- a/pypandoc/__init__.py
+++ b/pypandoc/__init__.py
@@ -14,7 +14,7 @@ from .py3compat import string_types, cast_bytes, cast_unicode, urlparse
from pypandoc.pandoc_download import DEFAULT_TARGET_FOLDER, download_pandoc
__author__ = u'Juho Vepsäläinen'
-__version__ = '1.3.3'
+__version__ = '1.4'
__license__ = 'MIT'
__all__ = ['convert', 'convert_file', 'convert_text',
'get_pandoc_formats', 'get_pandoc_version', 'get_pandoc_path',
@@ -224,14 +224,14 @@ def _validate_formats(format, to, outputfile):
base_to_format = _get_base_format(to)
- file_extension = os.path.splitext(base_to_format)[1]
+ file_extension = os.path.splitext(to)[1]
if (base_to_format not in to_formats and
base_to_format != "pdf" and # pdf is handled later # noqa: E127
file_extension != '.lua'):
raise RuntimeError(
- 'Invalid output format! Expected one of these: ' +
- ', '.join(to_formats))
+ 'Invalid output format! Got %s but expected one of these: %s' % (
+ base_to_format, ', '.join(to_formats)))
# list from https://github.com/jgm/pandoc/blob/master/pandoc.hs
# `[...] where binaries = ["odt","docx","epub","epub3"] [...]`
diff --git a/pypandoc/pandoc_download.py b/pypandoc/pandoc_download.py
index 07a76c6..c9378c9 100644
--- a/pypandoc/pandoc_download.py
+++ b/pypandoc/pandoc_download.py
@@ -7,6 +7,7 @@ import tempfile
import os.path
import subprocess
import platform
+import re
try:
from urllib.request import urlopen
@@ -14,17 +15,6 @@ except ImportError:
from urllib import urlopen
-# Uses sys.platform keys, but removes the 2 from linux2
-# Adding a new platform means implementing unpacking in "DownloadPandocCommand"
-# and adding the URL here
-PANDOC_URLS = {
- "win32": "https://github.com/jgm/pandoc/releases/download/1.18/pandoc-1.18-windows.msi",
- "linux": "https://github.com/jgm/pandoc/releases/download/1.18/pandoc-1.18-1-amd64.deb",
- "darwin": "https://github.com/jgm/pandoc/releases/download/1.18/pandoc-1.18-osx.pkg"
-}
-
-INCLUDED_PANDOC_VERSION = "1.18"
-
DEFAULT_TARGET_FOLDER = {
"win32": "~\\AppData\\Local\\Pandoc",
"linux": "~/bin",
@@ -32,6 +22,47 @@ DEFAULT_TARGET_FOLDER = {
}
+def _get_pandoc_urls(version="latest"):
+ """Get the urls of pandoc's binaries
+ Uses sys.platform keys, but removes the 2 from linux2
+ Adding a new platform means implementing unpacking in "DownloadPandocCommand"
+ and adding the URL here
+
+ :param str version: pandoc version.
+ Valid values are either a valid pandoc version e.g. "1.19.1", or "latest"
+ Default: "latest".
+
+ :return: str pandoc_urls: a dictionary with keys as system platform
+ and values as the url pointing to respective binaries
+
+ :return: str version: actual pandoc version. (e.g. "lastest" will be resolved to the actual one)
+ """
+ # url to pandoc download page
+ url = "https://github.com/jgm/pandoc/releases/" + \
+ ("tag/" if version != "latest" else "") + version
+ # read the HTML content
+ response = urlopen(url)
+ content = response.read()
+ # regex for the binaries
+ regex = re.compile(r"/jgm/pandoc/releases/download/.*\.(?:msi|deb|pkg)")
+ # a list of urls to the bainaries
+ pandoc_urls_list = regex.findall(content.decode("utf-8"))
+ # actual pandoc version
+ version = pandoc_urls_list[0].split('/')[5]
+ # dict that lookup the platform from binary extension
+ ext2platform = {
+ 'msi': 'win32',
+ 'deb': 'linux',
+ 'pkg': 'darwin'
+ }
+ # parse pandoc_urls from list to dict
+ # py26 don't like dict comprehension. Use this one instead when py26 support is dropped
+ # pandoc_urls = {ext2platform[url_frag[-3:]]: ("https://github.com" + url_frag) for url_frag in pandoc_urls_list}
+ pandoc_urls = dict((ext2platform[
+ url_frag[-3:]], ("https://github.com" + url_frag)) for url_frag in pandoc_urls_list)
+ return pandoc_urls, version
+
+
def _make_executable(path):
mode = os.stat(path).st_mode
mode |= (mode & 0o444) >> 2 # copy R bits to X
@@ -118,7 +149,7 @@ def _handle_win32(filename, targetfolder):
print("* Done.")
-def download_pandoc(url=None, targetfolder=None):
+def download_pandoc(url=None, targetfolder=None, version="latest"):
"""Download and unpack pandoc
Downloads prebuild binaries for pandoc from `url` and unpacks it into
@@ -133,6 +164,9 @@ def download_pandoc(url=None, targetfolder=None):
location: `~/bin` on Linux, `~/Applications/pandoc` on Mac OS X, and
`~\\AppData\\Local\\Pandoc` on Windows.
"""
+ # get pandoc_urls
+ pandoc_urls, _ = _get_pandoc_urls(version)
+
pf = sys.platform
# compatibility with py3
@@ -141,11 +175,11 @@ def download_pandoc(url=None, targetfolder=None):
if platform.architecture()[0] != "64bit":
raise RuntimeError("Linux pandoc is only compiled for 64bit.")
- if pf not in PANDOC_URLS:
+ if pf not in pandoc_urls:
raise RuntimeError("Can't handle your platform (only Linux, Mac OS X, Windows).")
if url is None:
- url = PANDOC_URLS[pf]
+ url = pandoc_urls[pf]
filename = url.split("/")[-1]
if os.path.isfile(filename):
diff --git a/setup.cfg b/setup.cfg
index ebbec92..8bfd5a1 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,4 @@
[egg_info]
tag_build =
-tag_svn_revision = 0
tag_date = 0
diff --git a/setup.py b/setup.py
index bd25e7a..41549c8 100755
--- a/setup.py
+++ b/setup.py
@@ -102,6 +102,15 @@ setup(
'Programming Language :: Python',
'Topic :: Text Processing',
'Topic :: Text Processing :: Filters',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.6',
+ 'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.3',
+ 'Programming Language :: Python :: 3.4',
+ 'Programming Language :: Python :: 3.5',
+ 'Programming Language :: Python :: Implementation :: CPython',
+ 'Programming Language :: Python :: Implementation :: PyPy'
],
test_suite = 'tests',
cmdclass=cmd_classes
diff --git a/tests.py b/tests.py
index 1426647..90c801f 100755
--- a/tests.py
+++ b/tests.py
@@ -16,14 +16,19 @@ import subprocess
@contextlib.contextmanager
-def closed_tempfile(suffix, text=None):
- with tempfile.NamedTemporaryFile('w+t', suffix=suffix, delete=False) as test_file:
+def closed_tempfile(suffix, text=None, dir_name=None):
+ if dir_name:
+ dir_name = tempfile.mkdtemp(suffix=dir_name)
+ with tempfile.NamedTemporaryFile('w+t', suffix=suffix, delete=False, dir=dir_name) as test_file:
file_name = test_file.name
if text:
test_file.write(text)
test_file.flush()
yield file_name
- shutil.rmtree(file_name, ignore_errors=True)
+ if dir_name:
+ shutil.rmtree(dir_name, ignore_errors=True)
+ else:
+ os.remove(file_name)
# Stolen from pandas
@@ -171,7 +176,7 @@ class TestPypandoc(unittest.TestCase):
def test_convert_with_custom_writer(self):
lua_file_content = self.create_sample_lua()
with closed_tempfile('.md', text='#title\n') as file_name:
- with closed_tempfile('.lua', text=lua_file_content) as lua_file_name:
+ with closed_tempfile('.lua', text=lua_file_content, dir_name="foo-bar+baz") as lua_file_name:
expected = u'<h1 id="title">title</h1>{0}'.format(os.linesep)
received = pypandoc.convert_file(file_name, lua_file_name)
self.assertEqualExceptForNewlineEnd(expected, received)
@@ -327,19 +332,19 @@ class TestPypandoc(unittest.TestCase):
self.assertRaises(RuntimeError, f)
- def f():
- # outputfile needs to end in pdf
- with closed_tempfile('.WRONG') as file_name:
+ # outputfile needs to end in pdf
+ with closed_tempfile('.WRONG') as file_name:
+ def f():
pypandoc.convert_text('#some title\n', to='pdf', format='md', outputfile=file_name)
- self.assertRaises(RuntimeError, f)
+ self.assertRaises(RuntimeError, f)
- def f():
- # no extensions allowed
- with closed_tempfile('.pdf') as file_name:
+ # no extensions allowed
+ with closed_tempfile('.pdf') as file_name:
+ def f():
pypandoc.convert_text('#some title\n', to='pdf+somethign', format='md', outputfile=file_name)
- self.assertRaises(RuntimeError, f)
+ self.assertRaises(RuntimeError, f)
def test_get_pandoc_path(self):
result = pypandoc.get_pandoc_path()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pypandoc.git
More information about the Python-modules-commits
mailing list