Skip to content

Commit 6168809

Browse files
authored
Merge branch 'master' into feature/axes-tick-label-rotation
2 parents e777a49 + d759c1c commit 6168809

File tree

7 files changed

+55
-48
lines changed

7 files changed

+55
-48
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ README.rst
88
dist/
99
build/
1010
.cache/
11+
*.egg-info/

.travis.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ language: python
44

55
python:
66
- '2.7'
7-
- '3.4'
8-
9-
virtualenv:
10-
system_site_packages: true
7+
- '3.6'
118

129
addons:
1310
apt:
@@ -53,8 +50,7 @@ before_script:
5350
script:
5451
# cd into test directory to make sure we're using the pip-installed
5552
# matplotlib2tikz.
56-
- cd test
57-
- MPLBACKEND=Agg pytest --cov matplotlib2tikz
53+
- cd test && MPLBACKEND=Agg pytest --cov matplotlib2tikz
5854

5955
after_success:
6056
- bash <(curl -s https://codecov.io/bash)

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ README.rst: README.md
1313
python setup.py check -r -s || exit 1
1414

1515
upload: setup.py README.rst
16-
python setup.py sdist upload --sign
16+
rm -f dist/*
17+
python setup.py bdist_wheel --universal
18+
gpg --detach-sign -a dist/*
19+
twine upload dist/*
1720

1821
tag:
1922
@echo "Tagging v$(VERSION)..."

matplotlib2tikz/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
__copyright__ = 'Copyright (c) 2010-2017, %s <%s>' % (__author__, __email__)
66
__credits__ = []
77
__license__ = 'License :: OSI Approved :: MIT License'
8-
__version__ = '0.6.3'
8+
__version__ = '0.6.5'
99
__maintainer__ = u'Nico Schlömer'
1010
__status__ = 'Development Status :: 5 - Production/Stable'

matplotlib2tikz/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
__status__
1515
)
1616

17-
from matplotlib2tikz.save import save
17+
from matplotlib2tikz.save import get_tikz_code, save
1818

1919
import pipdated
20-
if pipdated.needs_checking('matplotlib2tikz'):
21-
msg = pipdated.check('matplotlib2tikz', __version__)
22-
if msg:
23-
print(msg)
20+
if pipdated.needs_checking(__name__):
21+
print(pipdated.check(__name__, __version__))

matplotlib2tikz/save.py

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,27 @@
99
from . import patch
1010
from . import text as mytext
1111

12+
from .__about__ import __version__
13+
14+
import codecs
1215
import os
1316
import matplotlib as mpl
14-
from .__about__ import __version__
1517

1618

17-
def save(filepath,
18-
figure='gcf',
19-
encoding=None,
20-
figurewidth=None,
21-
figureheight=None,
22-
textsize=10.0,
23-
tex_relative_path_to_data=None,
24-
strict=False,
25-
wrap=True,
26-
extra=None,
27-
dpi=None,
28-
show_info=True
29-
):
19+
def get_tikz_code(
20+
filepath,
21+
figure='gcf',
22+
encoding=None,
23+
figurewidth=None,
24+
figureheight=None,
25+
textsize=10.0,
26+
tex_relative_path_to_data=None,
27+
strict=False,
28+
wrap=True,
29+
extra=None,
30+
dpi=None,
31+
show_info=True
32+
):
3033
'''Main function. Here, the recursion into the image starts and the
3134
contents are picked up. The actual file gets written in this routine.
3235
@@ -132,13 +135,6 @@ def save(filepath,
132135
else:
133136
data['dpi'] = dpi
134137

135-
# open file
136-
import codecs
137-
file_handle = codecs.open(filepath, 'w', encoding)
138-
139-
if show_info:
140-
print('file encoding: {0}'.format(file_handle.encoding))
141-
142138
# gather the file content
143139
data, content = _recurse(data, figure)
144140

@@ -150,32 +146,45 @@ def save(filepath,
150146
disclaimer = 'This file was created by matplotlib2tikz v%s.' % __version__
151147

152148
# write disclaimer to the file header
153-
file_handle.write(_tex_comment(disclaimer))
149+
code = ''''''
150+
code += _tex_comment(disclaimer)
154151

155152
# write the contents
156153
if wrap:
157-
file_handle.write('\\begin{tikzpicture}\n\n')
154+
code += '\\begin{tikzpicture}\n\n'
158155

159156
coldefs = _get_color_definitions(data)
160157
if coldefs:
161-
file_handle.write('\n'.join(coldefs))
162-
file_handle.write('\n\n')
158+
code += '\n'.join(coldefs)
159+
code += '\n\n'
163160

164-
try:
165-
file_handle.write(''.join(content))
166-
except UnicodeEncodeError:
167-
# We're probably using Python 2, so use proper unicode treatment
168-
file_handle.write(unicode(''.join(content)).encode('utf-8'))
161+
code += ''.join(content)
169162

170163
if wrap:
171-
file_handle.write('\\end{tikzpicture}')
172-
173-
# close file
174-
file_handle.close()
164+
code += '\\end{tikzpicture}'
175165

176166
# print message about necessary pgfplot libs to command line
177167
if show_info:
178168
_print_pgfplot_libs_message(data)
169+
return code
170+
171+
172+
def save(*args, **kwargs):
173+
'''Same as `get_tikz_code()`, but actually saves the code to a file.
174+
'''
175+
code = get_tikz_code(*args, **kwargs)
176+
177+
file_handle = codecs.open(
178+
args[0],
179+
'w',
180+
kwargs['encoding'] if 'encoding' in kwargs else None
181+
)
182+
try:
183+
file_handle.write(code)
184+
except UnicodeEncodeError:
185+
# We're probably using Python 2, so use proper unicode treatment
186+
file_handle.write(unicode(code).encode('utf-8'))
187+
file_handle.close()
179188
return
180189

181190

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
from distutils.core import setup
3+
from setuptools import setup
44
import os
55
import codecs
66

0 commit comments

Comments
 (0)