Skip to content

Commit d72a60f

Browse files
committed
Initial commit
1 parent a534c08 commit d72a60f

File tree

126 files changed

+18201
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+18201
-13
lines changed

.gitignore

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#########################################
2+
# Editor temporary/working/backup files #
3+
.#*
4+
[#]*#
5+
*~
6+
*$
7+
*.bak
8+
*.kdev4
9+
.project
10+
.pydevproject
11+
12+
# Compiled source #
13+
###################
14+
*.a
15+
*.com
16+
*.class
17+
*.dll
18+
*.exe
19+
*.o
20+
*.py[ocd]
21+
*.so
22+
23+
# Python files #
24+
################
25+
# setup.py working directory
26+
build
27+
# sphinx build directory
28+
doc/build
29+
doc/source/_generated
30+
# setup.py dist directory
31+
dist
32+
# Egg metadata
33+
*.egg-info
34+
# tox testing tool
35+
.tox
36+
MANIFEST
37+
38+
# OS generated files #
39+
######################
40+
.directory
41+
.gdb_history
42+
.DS_Store?
43+
ehthumbs.db
44+
Icon?
45+
Thumbs.db
46+
47+
src/doc/*.c
48+
src/doc/*.h

LICENSE

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
Copyright (c) 2013, Matplotlib Developers
1+
Copyright (c) 2013, Michael Droettboom
22
All rights reserved.
33

4-
Redistribution and use in source and binary forms, with or without modification,
5-
are permitted provided that the following conditions are met:
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
66

7-
Redistributions of source code must retain the above copyright notice, this
8-
list of conditions and the following disclaimer.
9-
10-
Redistributions in binary form must reproduce the above copyright notice, this
11-
list of conditions and the following disclaimer in the documentation and/or
12-
other materials provided with the distribution.
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
1312

1413
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1514
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1615
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
1817
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1918
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21-
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2221
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23+
24+
The views and conclusions contained in the software and documentation are those
25+
of the authors and should not be interpreted as representing official policies,
26+
either expressed or implied, of the FreeBSD Project.

MANIFEST.in

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include README
2+
include buildext/*.py
3+
include tox.ini
4+
include src/*.c src/*.h
5+
include docstrings/*.py

buildext/convert_docstrings.py

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright (c) 2013, Michael Droettboom All rights reserved.
4+
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions
7+
# are met:
8+
9+
# 1. Redistributions of source code must retain the above copyright
10+
# notice, this list of conditions and the following disclaimer.
11+
# 2. Redistributions in binary form must reproduce the above copyright
12+
# notice, this list of conditions and the following disclaimer in
13+
# the documentation and/or other materials provided with the
14+
# distribution.
15+
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20+
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
29+
# The views and conclusions contained in the software and
30+
# documentation are those of the authors and should not be interpreted
31+
# as representing official policies, either expressed or implied, of
32+
# the FreeBSD Project.
33+
34+
from __future__ import print_function, unicode_literals, absolute_import
35+
36+
import glob
37+
import imp
38+
import os
39+
import re
40+
import sys
41+
42+
43+
def write_if_different(filename, data):
44+
""" Write `data` to `filename`, if the content of the file is different.
45+
46+
Parameters
47+
----------
48+
filename : str
49+
The file name to be written to.
50+
data : bytes
51+
The data to be written to `filename`.
52+
"""
53+
assert isinstance(data, bytes)
54+
55+
if os.path.exists(filename):
56+
with open(filename, 'rb') as fd:
57+
original_data = fd.read()
58+
else:
59+
original_data = None
60+
61+
if original_data != data:
62+
with open(filename, 'wb') as fd:
63+
fd.write(data)
64+
65+
66+
if sys.version_info[0] >= 3:
67+
from io import StringIO
68+
string_types = (str, bytes)
69+
70+
def get_byte(x):
71+
return x
72+
else:
73+
from cStringIO import StringIO
74+
string_types = (str, unicode)
75+
76+
def get_byte(x):
77+
return ord(x)
78+
79+
def generate_c_docstrings(name, input_path, output_path):
80+
input_file_path = os.path.join(input_path, name + ".py")
81+
module = imp.load_source(name, input_file_path)
82+
docstrings = module.__dict__
83+
84+
keys = [
85+
key for key in docstrings.keys()
86+
if not key.startswith('__') and type(key) in string_types and
87+
type(docstrings[key]) in string_types]
88+
keys.sort()
89+
docs = {}
90+
for key in keys:
91+
docs[key] = docstrings[key].encode('utf8').lstrip() + b'\0'
92+
93+
h_file = StringIO()
94+
h_file.write("""/*
95+
DO NOT EDIT!
96+
97+
This file is autogenerated by setup.py. To edit its contents, edit
98+
{0}.
99+
*/
100+
101+
#ifndef __DOC_{1}_H__
102+
#define __DOC_{1}_H__
103+
""".format(input_file_path, name.upper(), name))
104+
for key in keys:
105+
val = docs[key]
106+
h_file.write('extern char doc_{0}[{1}];\n'.format(key, len(val)))
107+
h_file.write("\n#endif\n\n")
108+
109+
write_if_different(
110+
os.path.join(output_path, name + ".h"),
111+
h_file.getvalue().encode('utf-8'))
112+
113+
c_file = StringIO()
114+
c_file.write("""/*
115+
DO NOT EDIT!
116+
117+
This file is autogenerated by setup.py. To edit its contents, edit
118+
{0}
119+
120+
We use numeric array initializers rather than string literals here,
121+
because some C compilers, notably MSVC, do not support string literals
122+
greater than 256 characters.
123+
*/
124+
125+
#include "{1}.h"
126+
127+
""".format(input_file_path, name))
128+
129+
for key in keys:
130+
val = docs[key]
131+
c_file.write('char doc_{0}[{1}] = {{\n'.format(
132+
key, len(val)))
133+
for i in range(0, len(val), 10):
134+
c_file.write(' ')
135+
for c in val[i:i+10]:
136+
c_file.write("0x{0:02x}, ".format(get_byte(c)))
137+
c_file.write('\n')
138+
c_file.write('};\n\n')
139+
140+
write_if_different(
141+
os.path.join(output_path, name + ".c"),
142+
c_file.getvalue().encode('utf-8'))
143+
144+
145+
def convert_all_docstrings(input_dir, output_dir):
146+
sys.path.insert(0, input_dir)
147+
148+
if not os.path.exists(output_dir):
149+
os.makedirs(output_dir)
150+
151+
for path in glob.glob(os.path.join(input_dir, "*.py")):
152+
name = os.path.basename(path)[:-3]
153+
module = imp.load_source(name, path)
154+
generate_c_docstrings(name, input_dir, output_dir)

0 commit comments

Comments
 (0)