-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathsetup_binary.py
99 lines (82 loc) · 3.38 KB
/
setup_binary.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pypandoc
from setuptools import setup, Command
import sys
import os
import os.path
import io
try:
from urllib.request import urlopen
except ImportError:
from urllib import urlopen
with io.open('README.md', encoding="utf-8") as f:
long_description = f.read()
class DownloadPandocCommand(Command):
"""Download pandoc"""
description = "downloads a pandoc release and adds it to the package"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
from pypandoc.pandoc_download import download_pandoc
targetfolder = os.path.join(os.path.dirname(os.path.realpath(__file__)), "pypandoc", "files")
download_pandoc(targetfolder=targetfolder)
cmd_classes = {'download_pandoc': DownloadPandocCommand}
# Make sure wheels end up platform specific, if they include a pandoc binary
has_pandoc = (os.path.isfile(os.path.join("pypandoc", "files", "pandoc")) or
os.path.isfile(os.path.join("pypandoc", "files", "pandoc.exe")))
is_build_wheel = ("bdist_wheel" in sys.argv)
is_download_pandoc = ("download_pandoc" in sys.argv)
if is_build_wheel:
if has_pandoc or is_download_pandoc:
# we need to make sure that bdist_wheel is after is_download_pandoc,
# otherwise we don't include pandoc in the wheel... :-(
pos_bdist_wheel = sys.argv.index("bdist_wheel")
if is_download_pandoc:
pos_download_pandoc = sys.argv.index("download_pandoc")
if pos_bdist_wheel < pos_download_pandoc:
raise RuntimeError("'download_pandoc' needs to be before 'bdist_wheel'.")
# we also need to make sure that this version of bdist_wheel supports
# the --plat-name argument
try:
import wheel
from distutils.version import StrictVersion
if not StrictVersion(wheel.__version__) >= StrictVersion("0.27"):
msg = "Including pandoc in wheel needs wheel >=0.27 but found %s.\nPlease update wheel!"
raise RuntimeError(msg % wheel.__version__)
except ImportError:
# the real error will happen further down...
print("No wheel installed, please install 'wheel'...")
print("forcing platform specific wheel name...")
from distutils.util import get_platform
sys.argv.insert(pos_bdist_wheel + 1, '--plat-name')
sys.argv.insert(pos_bdist_wheel + 2, get_platform())
else:
print("no pandoc found, building platform unspecific wheel...")
print("use 'python setup.py download_pandoc' to download pandoc.")
module = pypandoc
setup(
name = 'pypandoc_binary',
version = module.__version__,
url = pypandoc.__url__,
license = pypandoc.__license__,
description = pypandoc.__description__,
long_description = long_description,
long_description_content_type='text/markdown',
author = module.__author__.encode('utf8'),
author_email = pypandoc.__author_email__,
packages = ['pypandoc'],
package_data={'pypandoc': ['files/*']},
python_requires=pypandoc.__python_requires__,
setup_requires = pypandoc.__setup_requires__,
classifiers=pypandoc.__classifiers__,
test_suite = 'tests',
cmdclass=cmd_classes,
project_urls={
'Source': pypandoc.__url__,
'Tracker': pypandoc.__url__ + '/issues',
}
)