Skip to content

Commit

Permalink
Merge pull request #1301 from gnu-octave/codespell
Browse files Browse the repository at this point in the history
Codespell: trying to get CI running
  • Loading branch information
cbm755 authored May 16, 2024
2 parents 95e0be5 + 7b36087 commit 65b92d3
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 43 deletions.
11 changes: 11 additions & 0 deletions .codespell-ignorelines
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-License-Identifier: FSFAP
# Copyright (C) 2024 Colin B. Macdonald
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.

# lines that codespell should ignore: whitespace matters!

%!error <ndefined>
14 changes: 14 additions & 0 deletions .codespell-ignorewords
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-License-Identifier: FSFAP
# Copyright (C) 2024 Colin B. Macdonald
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.

# words that codespell should not complain about
ans
nin
te
unequalities
unequality
12 changes: 12 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ jobs:
flatpak run org.freedesktop.appstream.cli validate --strict --pedantic --explain io.github.gnu_octave.symbolic.metainfo.xml
codespell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: codespell-project/actions-codespell@v2
with:
ignore_words_file: .codespell-ignorewords
exclude_file: .codespell-ignorelines
check_filenames: true
check_hidden: true


# Built-in Self Tests and Doctests for various supported Octave and SymPy
# Test newest Octave and all supported SymPy
# Test other supported Octave releases with latest available SymPy
Expand Down
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# SPDX-License-Identifier: FSFAP
# Copyright (C) 2024 Colin B. Macdonald
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
#
# Git ignore file for Octave's Symbolic package.

*.so
*~

octave-workspace

# temporary communcation files
# temporary communication files
temp_sym_python_cmd.py
inlog.txt
outlog.txt
Expand Down
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ octsympy 2.6.0 (2017-07-27)
* `sym` now accepts function handles such as anonymous functions as
inputs.

* `subs` is not approriate for numerical evaluation; add an example in
* `subs` is not appropriate for numerical evaluation; add an example in
`help subs` which shows how to do this with `function_handle`.

* Calling `sym(cell)` now creates a sym array instead of a cell array.
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# TODO List, mostly historial now
# TODO List, mostly historical now

## assumptions

Expand Down
63 changes: 30 additions & 33 deletions inst/@sym/isAlways.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
%% Copyright (C) 2014-2016, 2019, 2022 Colin B. Macdonald
%% SPDX-License-Identifier: AGPL-3.0-or-later
%% Copyright (C) 2014-2016, 2019, 2022, 2024 Colin B. Macdonald
%%
%% This file is part of OctSymPy.
%%
Expand Down Expand Up @@ -78,49 +79,45 @@

if (nargin == 3)
assert(strcmpi(varargin{1}, 'unknown'))
cant = varargin{2};
if islogical(cant)
map_unknown_to = varargin{2};
if islogical(map_unknown_to)
% SMT doesn't allow nonstring but it seems reasonable
elseif strcmpi(cant, 'true')
cant = true;
elseif strcmpi(cant, 'false')
cant = false;
elseif strcmpi(cant, 'error')
elseif strcmpi(map_unknown_to, 'true')
map_unknown_to = true;
elseif strcmpi(map_unknown_to, 'false')
map_unknown_to = false;
elseif strcmpi(map_unknown_to, 'error')
% no-op
else
error('isAlways: invalid argument for "unknown" keyword')
end
else
cant = false;
map_unknown_to = false;
end

cmd = {
'def simplify_tfn(p):'
'def simplify_true_false_none(p):'
' if p in (S.true, S.false):'
' return bool(p)'
' r = simplify(p)'
' #FIXME; Boolean, simplify more than once?'
' if r in (S.true, S.false):'
' return bool(r)'
' # FIXME: hopefully we get sympy patched for some of this'
' #ver = sympy.__version__'
' #if ver == "0.7.5" or ver.startswith("0.7.6") or ver.startswith("0.7.7"):'
' if True:'
' if isinstance(p, Equality):'
' r = Eq(sp.simplify(p.lhs - p.rhs), 0)'
' r = simplify(r)'
' if r in (S.true, S.false):'
' return bool(r)'
' if isinstance(p, Unequality):'
' r = Eq(sp.simplify(p.lhs - p.rhs), 0)'
' r = simplify(r)'
' if r in (S.true, S.false):'
' return not bool(r)'
' if isinstance(p, (Lt, Gt, Le, Ge)):'
' r = p._eval_relation(sp.simplify(p.lhs - p.rhs), sp.S(0))'
' r = simplify(r)'
' if r in (S.true, S.false):'
' return bool(r)'
' if isinstance(p, Equality):'
' r = Eq(sp.simplify(p.lhs - p.rhs), 0)'
' r = simplify(r)'
' if r in (S.true, S.false):'
' return bool(r)'
' if isinstance(p, Unequality):'
' r = Eq(sp.simplify(p.lhs - p.rhs), 0)'
' r = simplify(r)'
' if r in (S.true, S.false):'
' return not bool(r)'
' if isinstance(p, (Lt, Gt, Le, Ge)):'
' r = p._eval_relation(sp.simplify(p.lhs - p.rhs), sp.S(0))'
' r = simplify(r)'
' if r in (S.true, S.false):'
' return bool(r)'
' # for SMT compat'
' if p.is_number:'
' r = p.is_zero' % FIXME: return bool(r)?
Expand All @@ -130,20 +127,20 @@
% could distinguish b/w None and return a string for this last case

cmd = vertcat(cmd, {
'(x, unknown) = _ins'
'(x, map_unknown_to) = _ins'
'if x is not None and x.is_Matrix:'
' r = [a for a in x.T]' % note transpose
'else:'
' r = [x,]'
'r = [simplify_tfn(a) for a in r]'
'r = [unknown if a is None else a for a in r]'
'r = [simplify_true_false_none(a) for a in r]'
'r = [map_unknown_to if a is None else a for a in r]'
'flag = True'
'if r.count("error") > 0:'
' flag = False'
' r = "cannot reliably convert sym to bool"'
'return (flag, r)' });

[flag, r] = pycall_sympy__ (cmd, p, cant);
[flag, r] = pycall_sympy__ (cmd, p, map_unknown_to);

if (~flag)
assert (ischar (r), 'isAlways: programming error?')
Expand Down
6 changes: 4 additions & 2 deletions inst/@sym/logical.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
%% Copyright (C) 2014-2016, 2019 Colin B. Macdonald
%% SPDX-License-Identifier: AGPL-3.0-or-later
%% Copyright (C) 2014-2016, 2019, 2024 Colin B. Macdonald
%%
%% This file is part of OctSymPy.
%%
Expand Down Expand Up @@ -76,6 +77,7 @@

% do not simplify here

% convert a scalar expression to true/false/none
cmd = {
'def scalar2tfn(p):'
' if p in (S.true, S.false):'
Expand Down Expand Up @@ -116,7 +118,7 @@

% FIXME: oo, zoo error too in SMT
% ' elif p is nan:'
% ' raise TE # FIXME: check SMT'
% ' raise TypeError # FIXME: check SMT'


if (~flag)
Expand Down
3 changes: 3 additions & 0 deletions inst/private/assert_pythonic_and_sympy.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
%% SPDX-License-Identifier: AGPL-3.0-or-later
%% Copyright (C) 2019, 2022, 2024 Colin B. Macdonald
%% Copyright (C) 2022-2023 Alex Vong
%%
Expand Down Expand Up @@ -27,6 +28,8 @@

function assert_pythonic_and_sympy (verbose)

% Ubuntu 20.04: 1.5.1, EOL Apr 2025
% Ubuntu 22.04: 1.9, EOL Apr 2027
minsympyver = '1.5.1';

if (nargin < 1)
Expand Down
7 changes: 4 additions & 3 deletions inst/private/python_copy_vars_to.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
%% Copyright (C) 2014-2017, 2023 Colin B. Macdonald
%% SPDX-License-Identifier: AGPL-3.0-or-later
%% Copyright (C) 2014-2017, 2023-2024 Colin B. Macdonald
%%
%% This file is part of OctSymPy.
%%
Expand All @@ -16,10 +17,10 @@
%% License along with this software; see the file COPYING.
%% If not, see <http://www.gnu.org/licenses/>.

function L = python_copy_vars_to(in, te, varargin)
function L = python_copy_vars_to(in, try_except, varargin)
%private function

if (~te)
if (~try_except)
%% no error checking
L = do_list(0, in, varargin);
L = { sprintf('%s = []', in) ...
Expand Down
4 changes: 2 additions & 2 deletions util/convert_comments.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% Copyright (C) 2014-2018, 2023 Colin B. Macdonald
%% Copyright (C) 2014-2018, 2023-2024 Colin B. Macdonald
%%
%% This file is part of OctSymPy.
%%
Expand Down Expand Up @@ -240,7 +240,7 @@ function convert_comments (basedir, subdir, dirout)
fprintf(f, '%% %s\n', copyright_summary);

%fdisp(f, '%');
%fdisp(f, '% [Genereated from a GNU Octave .m file, edit that instead.]');
%fdisp(f, '% [Generated from a GNU Octave .m file, edit that instead.]');

%fprintf(f,(s)

Expand Down

0 comments on commit 65b92d3

Please sign in to comment.