forked from hhatto/python-hoedown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
113 lines (95 loc) · 3.57 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
102
103
104
105
106
107
108
109
110
111
112
113
import os
import glob
import shutil
import os.path
try:
from setuptools import setup, Extension, Command
except ImportError:
from distutils.core import setup, Extension, Command
exec(open('hoedownpy/_version.py').read())
dirname = os.path.dirname(os.path.abspath(__file__))
class BaseCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
class CleanCommand(BaseCommand):
description = 'cleanup directories created by packaging and build processes'
def run(self):
for path in ['build', 'dist', 'hoedown.egg-info', 'docs/_build', 'temp']:
if os.path.exists(path):
path = os.path.join(dirname, path)
print('removing %s' % path)
shutil.rmtree(path)
class CythonCommand(BaseCommand):
description = 'compile Cython files(s) into C file(s)'
def run(self):
try:
from Cython.Compiler.Main import compile
for f in ("hoedown.pyx", ):
path = os.path.join(dirname, 'hoedownpy', f)
print('compiling %s' % path)
compile(path)
except ImportError:
print('Cython is not installed. Please install Cython first.')
class VendorCommand(BaseCommand):
description = 'update hoedown files. Use `git submodule init`, '\
'`git submodule update` and `git submodule foreach git pull origin master`'\
' to the most recent files'
def run(self):
os.system('git submodule update --init')
os.system('git submodule foreach git pull origin master')
files = []
dest = os.path.join(dirname, 'hoedownpy/_hoedown/src')
for path in ['vendor/hoedown/src/*', ]:
files += glob.glob(os.path.join(dirname, path))
for path in files:
if os.path.exists(path):
print('copy %s -> %s' % (path, dest))
shutil.copy(path, dest)
class TestCommand(BaseCommand):
description = 'run unit tests'
def run(self):
os.system('python tests/hoedown_test.py')
setup(
name='hoedown',
version=__version__,
description='The Python binding for Hoedown, a markdown parsing library.',
author='Hideo Hattori',
author_email='[email protected]',
url='https://github.com/hhatto/python-hoedown',
license='MIT',
long_description=open(os.path.join(dirname, 'README.rst')).read(),
scripts=['scripts/hoedownpy'],
cmdclass={
'clean': CleanCommand,
'compile_cython': CythonCommand,
'update_vendor': VendorCommand,
'test': TestCommand
},
ext_modules=[Extension('hoedown', [
'hoedownpy/hoedown.c',
'hoedownpy/wrapper.c',
'hoedownpy/_hoedown/src/html.c',
'hoedownpy/_hoedown/src/stack.c',
'hoedownpy/_hoedown/src/document.c',
'hoedownpy/_hoedown/src/html_smartypants.c',
'hoedownpy/_hoedown/src/html_blocks.c',
'hoedownpy/_hoedown/src/escape.c',
'hoedownpy/_hoedown/src/buffer.c',
'hoedownpy/_hoedown/src/autolink.c'
], define_macros=[('inithoedownpy', 'inithoedown')])],
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: C',
'Programming Language :: Cython',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Topic :: Text Processing :: Markup',
'Topic :: Text Processing :: Markup :: HTML',
'Topic :: Utilities'
]
)