Mercurial > pytave
annotate pyversion.m @ 375:d0a7f66393fc
Fix __py_class_name__ tests to work with Python 2
* __py_struct_from_dict__.cc: Fix __py_class_name__ tests to work with Python 2.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Fri, 26 Aug 2016 18:51:29 -0700 |
parents | b0d012e9975f |
children |
rev | line source |
---|---|
341
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
1 ## Copyright (C) 2016 Mike Miller |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
2 ## |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
3 ## This file is part of Pytave. |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
4 ## |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
5 ## Pytave is free software; you can redistribute it and/or modify it |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
8 ## your option) any later version. |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
9 ## |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
10 ## Pytave is distributed in the hope that it will be useful, but |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
13 ## General Public License for more details. |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
14 ## |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
16 ## along with Pytave; see the file COPYING. If not, see |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
18 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
20 ## @deftypefn {} {} pyversion |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
21 ## @deftypefnx {} {@var{ver} =} pyversion |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
22 ## @deftypefnx {} {[@var{ver}, @var{exec}, @var{loaded}] =} pyversion |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
23 ## List information about the Python runtime used by Octave Python functions. |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
24 ## @end deftypefn |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
25 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
26 function varargout = pyversion () |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
27 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
28 if (nargin > 0) |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
29 print_usage (); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
30 endif |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
31 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
32 ver = char (pycall ("sysconfig.get_python_version")); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
33 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
34 if ((nargout == 0) || (nargout > 1)) |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
35 exec = char (py.sys.executable); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
36 endif |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
37 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
38 ## FIXME: determine whether the Python runtime has been loaded yet |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
39 if ((nargout == 0) || (nargout > 2)) |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
40 loaded = true; |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
41 endif |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
42 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
43 if (nargout == 0) |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
44 dlllibrary = char (pycall ("sysconfig.get_config_var", "DLLLIBRARY")); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
45 if (isempty (dlllibrary)) |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
46 libdir = pycall ("sysconfig.get_config_var", "LIBDIR"); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
47 ldlibrary = pycall ("sysconfig.get_config_var", "LDLIBRARY"); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
48 else |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
49 libdir = pycall ("sysconfig.get_config_var", "BINDIR"); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
50 ldlibrary = dlllibrary; |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
51 endif |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
52 multiarch = pycall ("sysconfig.get_config_var", "MULTIARCH"); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
53 lib = char (pycall ("os.path.join", libdir, multiarch, ldlibrary)); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
54 prefix = char (pycall ("sysconfig.get_config_var", "prefix")); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
55 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
56 printf (" version: \"%s\"\n", ver); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
57 printf (" executable: \"%s\"\n", exec); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
58 printf (" library: \"%s\"\n", lib); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
59 printf (" prefix: \"%s\"\n", prefix); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
60 printf (" loaded: %d\n", loaded); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
61 else |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
62 if (nargout > 0) |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
63 varargout{1} = ver; |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
64 endif |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
65 if (nargout > 1) |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
66 varargout{2} = exec; |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
67 endif |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
68 if (nargout > 2) |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
69 varargout{3} = loaded; |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
70 endif |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
71 endif |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
72 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
73 endfunction |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
74 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
75 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
76 %!assert (ischar (pyversion ())) |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
77 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
78 %!test |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
79 %! [m, n] = regexp (pyversion (), '^(\d\.\d)$'); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
80 %! assert ([m, n], [1, 3]) |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
81 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
82 %!test |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
83 %! [~, ~, v] = pyversion (); |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
84 %! assert (v, true) |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
85 |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
86 %!error pyversion (1) |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
87 %!error pyversion ("python") |
b0d012e9975f
pyversion: new function to report Python runtime version and path information
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
88 %!error pyversion ("/usr/bin/python") |