Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/blink1073/oct2py
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Mar 30, 2015
2 parents 65f7003 + a2390a8 commit 19d9e32
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 35 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ script:
else
nosetests --exe -v oct2py;
fi
- make docs

after_success:
- coveralls
11 changes: 11 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
Release History
---------------

3.2.0 ()
++++++++++++++++++
- Better handling of returned empty values


3.1.0 (2015-02-13)
++++++++++++++++++
- Fix handling of temporary files for multiprocessing
- Clean up handling of plot settings


3.0.0 (2015-01-10)
++++++++++++++++++
- Add `convert_to_float` property that is True by default.
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Note: This is meant for Oct2Py developer use only
.PHONY: all clean test cover release gh-pages
.PHONY: all clean test cover release gh-pages docs

export TEST_ARGS=--exe -v --with-doctest
export NAME=oct2py
Expand Down Expand Up @@ -36,12 +36,16 @@ release: test gh-pages
git push origin --all
git push origin --tags

gh-pages: clean
docs: clean
export SPHINXOPTS=-W
pip install sphinx-bootstrap-theme numpydoc sphinx ghp-import
make -C docs html

gh-pages:
git checkout master
git pull origin master
cp oct2py/tests/*.m example
git commit -a -m "Keep examples in sync"; true
git push origin; true
make -C docs html
make docs
ghp-import -n -p -m $(GHP_MSG) docs/_build/html
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MAT files. Usage is as simple as:
>>> oc = oct2py.Oct2Py()
>>> x = oc.zeros(3,3)
>>> print x, x.dtype
>>> print(x, x.dtype)
[[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]] float64
Expand Down
2 changes: 2 additions & 0 deletions conda/oct2py-3.1.0/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"%PYTHON%" setup.py install
if errorlevel 1 exit 1
3 changes: 3 additions & 0 deletions conda/oct2py-3.1.0/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

$PYTHON setup.py install
32 changes: 32 additions & 0 deletions conda/oct2py-3.1.0/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package:
name: oct2py
version: "3.1.0"

source:
fn: oct2py-3.1.0.tar.gz
url: https://pypi.python.org/packages/source/o/oct2py/oct2py-3.1.0.tar.gz
md5: 12fcdcdb95f3bf6d7ebd04a382ce9242

requirements:
build:
- python
- setuptools

run:
- python
- numpy >=1.7.1
- scipy >=0.12
- ipython

test:
# Python imports
imports:
- oct2py
- oct2py.tests
- oct2py.ipython
- oct2py.ipython.tests

about:
home: http://github.com/blink1073/oct2py
license: MIT License
summary: 'Python to GNU Octave bridge --> run m-files from python.'
12 changes: 11 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,18 @@
# -----------------------------------------------------------------------------
# intersphinx
# -----------------------------------------------------------------------------
_python_doc_base = 'http://docs.python.org/2.7'
_python_doc_base = 'https://docs.python.org/2.7'
intersphinx_mapping = {
_python_doc_base: None,
}


# remove non-local uri warning
import sphinx.environment
from docutils.utils import get_source_line

def _warn_node(self, msg, node):
if not msg.startswith('nonlocal image URI found:'):
self._warnfunc(msg, '%s:%s' % get_source_line(node))

sphinx.environment.BuildEnvironment.warn_node = _warn_node
2 changes: 1 addition & 1 deletion oct2py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""

__title__ = 'oct2py'
__version__ = '3.0.0'
__version__ = '3.1.0'
__author__ = 'Steven Silvester'
__license__ = 'MIT'
__copyright__ = 'Copyright 2014 Steven Silvester'
Expand Down
46 changes: 17 additions & 29 deletions oct2py/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def push(self, name, var, verbose=False, timeout=None):
>>> octave.pull(['x', 'y']) # doctest: +SKIP
[u'spam', array([[1, 2, 3, 4]])]
Note
----
Notes
-----
Integer type arguments will be converted to floating point
unless `convert_to_float=False`.
Expand Down Expand Up @@ -335,40 +335,41 @@ def _get_plot_commands(self, plot_dir, plot_format, plot_width,

pre_call += """
set(0, 'DefaultFigurePosition', [300, 200, %(plot_width)s, %(plot_height)s]);
__oct2py_figures = [];
""" % locals()

if not plot_dir is None:

pre_call += """
close all;
__oct2py_figure_visible = 'off';
set(0, 'defaultfigurevisible', 'off');
"""

plot_dir = plot_dir.replace("\\", "/")

post_call += '''
for f = __oct2py_figures
out_file = sprintf('%(plot_dir)s/%(plot_name)s%%03d.%(plot_format)s', f + %(plot_offset)s);
p = get(f, 'position');
w = %(plot_width)s;
h = %(plot_height)s;
if p(3) > %(plot_width)s
h = p(4) * w / p(3);
figHandles_ = get(0, 'children');
for fig_ = 1:length(figHandles_)
f_ = figHandles_(fig_);
outfile_ = sprintf('%(plot_dir)s/%(plot_name)s%%03d.%(plot_format)s', f_ + %(plot_offset)s);
p_ = get(f_, 'position');
w_ = %(plot_width)s;
h_ = %(plot_height)s;
if p_(3) > %(plot_width)s
h_ = p_(4) * w_ / p_(3);
end
if p(4) > %(plot_height)s
w = p(3) * h / p(4);
if p_(4) > %(plot_height)s
w_ = p_(3) * h_ / p_(4);
end
size_fmt = sprintf('-S%%d,%%d', w, h);
size_fmt_ = sprintf('-S%%d,%%d', w_, h_);
try
print(f, out_file, '-d%(plot_format)s', '-tight', size_fmt);
print(f_, outfile_, '-d%(plot_format)s', '-tight', size_fmt_);
end
end
close('all');
''' % locals()
else:
pre_call += """
__oct2py_figure_visible = 'on';
"set(0, 'defaultfigurevisible', 'on');"
"""

post_call += """
Expand Down Expand Up @@ -735,10 +736,6 @@ def evaluate(self, cmds, logger=None, out_file='', log=True,
clear("a__");
disp(char(2))
try
set(0, 'DefaultFigureCreateFcn', @fig_create)
end
try
disp(char(2));
%(expr)s
Expand Down Expand Up @@ -837,15 +834,6 @@ def _handle_first_run(self):
'(gnuplot-x11 on Linux)')

self.first_run = False
self.write("""
global __oct2py_figures = [];
global __oct2py_figure_visible = 'on';
function fig_create(src, event);
global __oct2py_figures;
global __oct2py_figure_visible;
set(src, 'visible', __oct2py_figure_visible);
__oct2py_figures(end + 1) = src;
end;\n""")

def interrupt(self):
if os.name == 'nt':
Expand Down
6 changes: 6 additions & 0 deletions oct2py/matread.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,10 @@ def get_data(val):
elif val.size == 1:
if hasattr(val, 'flatten'):
val = val.flatten()[0]
elif val.size == 0:
if val.dtype.kind in 'US':
val = ''
else:
val = []

return val
10 changes: 10 additions & 0 deletions oct2py/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,13 @@ def test_multiline_statement(self):
text = hdlr.stream.getvalue().strip()
assert ans == 4
assert text.endswith('\na = 1\nb = 3\nans = 4')

def test_empty_values(self):
self.oc.push('a', '')
assert self.oc.pull('a') == ''

self.oc.push('a', [])
assert self.oc.pull('a') == []

self.oc.push('a', None)
assert np.isnan(self.oc.pull('a'))

0 comments on commit 19d9e32

Please sign in to comment.