oct2py/core.py
changed.
Other files ignored by Codecov
674bd36
... +0 ...
608d667
275 | 275 | Name of function to run or a path to an m-file. |
|
276 | 276 | func_args: object, optional |
|
277 | 277 | Args to send to the function. |
|
278 | - | nout: int, optional |
|
279 | - | Desired number of return arguments, defaults to 1. |
|
278 | + | nout: int or str, optional. |
|
279 | + | Desired number of return arguments, defaults to 1. If nout |
|
280 | + | value is 'max_nout', get_max_nout() will be used. |
|
280 | 281 | store_as: str, optional |
|
281 | 282 | If given, saves the result to the given Octave variable name |
|
282 | 283 | instead of returning it. |
342 | 343 | nout = kwargs.get('nout', None) |
|
343 | 344 | if nout is None: |
|
344 | 345 | nout = 1 |
|
346 | + | elif nout == 'max_nout': |
|
347 | + | nout = self._get_max_nout(func_path) |
|
345 | 348 | ||
346 | 349 | plot_dir = kwargs.get('plot_dir') |
|
347 | 350 |
743 | 746 | setattr(self, attr, obj) |
|
744 | 747 | ||
745 | 748 | return obj |
|
749 | + | ||
750 | + | def _get_max_nout(self, func_path): |
|
751 | + | """Get or count maximum nout of .m function.""" |
|
752 | + | ||
753 | + | if not osp.isabs(func_path): |
|
754 | + | func_path = self.which(func_path) |
|
755 | + | ||
756 | + | nout = 0 |
|
757 | + | status = 'NOT FUNCTION' |
|
758 | + | with open(func_path, encoding='utf8') as f: |
|
759 | + | for l in f: |
|
760 | + | if l[0] != 'f': #not function |
|
761 | + | if status == 'NOT FUNCTION': |
|
762 | + | continue |
|
763 | + | l = l.translate(str.maketrans('', '', '[]()')).split() |
|
764 | + | try: |
|
765 | + | l.remove('function') |
|
766 | + | except: |
|
767 | + | pass |
|
768 | + | for s in l: |
|
769 | + | if s == '...': |
|
770 | + | status = 'FUNCTION' |
|
771 | + | continue |
|
772 | + | if s != '=': |
|
773 | + | nout += 1 |
|
774 | + | else: |
|
775 | + | return nout |
|
776 | + | return nout |
Files | Coverage |
---|---|
oct2py | -1.34% 90.45% |
Project Totals (10 files) | 90.45% |
608d667
674bd36