Skip to content

Commit 99701a5

Browse files
Merge pull request sympy#20250 from asmeurer/restore-ccode
Restore sympy.printing.{ccode,fcode,cxxcode} for backwards compatibility
2 parents 7f18926 + c70cb90 commit 99701a5

File tree

7 files changed

+68
-2
lines changed

7 files changed

+68
-2
lines changed

sympy/printing/ccode.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
This is a shim file to provide backwards compatibility (ccode.py was renamed
3+
to c.py in SymPy 1.7).
4+
"""
5+
6+
from sympy.utilities.exceptions import SymPyDeprecationWarning
7+
8+
SymPyDeprecationWarning(
9+
feature="importing from sympy.printing.ccode",
10+
useinstead="Import from sympy.printing.c",
11+
issue=20256,
12+
deprecated_since_version="1.7").warn()
13+
14+
from .c import (ccode, print_ccode, known_functions_C89, known_functions_C99, # noqa:F401
15+
reserved_words, reserved_words_c99, get_math_macros,
16+
C89CodePrinter, C99CodePrinter, C11CodePrinter,
17+
c_code_printers)

sympy/printing/cxxcode.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
This is a shim file to provide backwards compatibility (cxxcode.py was renamed
3+
to cxx.py in SymPy 1.7).
4+
"""
5+
6+
from sympy.utilities.exceptions import SymPyDeprecationWarning
7+
8+
SymPyDeprecationWarning(
9+
feature="importing from sympy.printing.cxxcode",
10+
useinstead="Import from sympy.printing.cxx",
11+
issue=20256,
12+
deprecated_since_version="1.7").warn()
13+
14+
from .cxx import (cxxcode, reserved, CXX98CodePrinter, # noqa:F401
15+
CXX11CodePrinter, CXX17CodePrinter, cxx_code_printers)

sympy/printing/fcode.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
This is a shim file to provide backwards compatibility (fcode.py was renamed
3+
to fortran.py in SymPy 1.7).
4+
"""
5+
6+
from sympy.utilities.exceptions import SymPyDeprecationWarning
7+
8+
SymPyDeprecationWarning(
9+
feature="importing from sympy.printing.fcode",
10+
useinstead="Import from sympy.printing.fortran",
11+
issue=20256,
12+
deprecated_since_version="1.7").warn()
13+
14+
from .fortran import fcode, print_fcode, known_functions, FCodePrinter # noqa:F401

sympy/printing/tests/test_c.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from sympy.sets import Range
1111
from sympy.logic import ITE
1212
from sympy.codegen import For, aug_assign, Assignment
13-
from sympy.testing.pytest import raises, XFAIL
13+
from sympy.testing.pytest import raises, XFAIL, warns_deprecated_sympy
1414
from sympy.printing.c import C89CodePrinter, C99CodePrinter, get_math_macros
1515
from sympy.codegen.ast import (
1616
AddAugmentedAssignment, Element, Type, FloatType, Declaration, Pointer, Variable, value_const, pointer_const,
@@ -835,3 +835,8 @@ def test_ccode_codegen_ast():
835835
'pwer(x);',
836836
'return x;',
837837
])
838+
839+
def test_ccode_submodule():
840+
# Test the compatibility sympy.printing.ccode module imports
841+
with warns_deprecated_sympy():
842+
import sympy.printing.ccode # noqa:F401

sympy/printing/tests/test_cxx.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from sympy.printing.cxx import CXX98CodePrinter, CXX11CodePrinter, CXX17CodePrinter, cxxcode
44
from sympy.codegen.cfunctions import log1p
55

6+
from sympy.testing.pytest import warns_deprecated_sympy
7+
68
x, y = symbols('x y')
79

810

@@ -54,3 +56,8 @@ def test_CXX17CodePrinter():
5456

5557
def test_cxxcode():
5658
assert sorted(cxxcode(sqrt(x)*.5).split('*')) == sorted(['0.5', 'std::sqrt(x)'])
59+
60+
def test_cxxcode_submodule():
61+
# Test the compatibility sympy.printing.cxxcode module imports
62+
with warns_deprecated_sympy():
63+
import sympy.printing.cxxcode # noqa:F401

sympy/printing/tests/test_fortran.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from sympy.printing.fortran import fcode, FCodePrinter
1515
from sympy.tensor import IndexedBase, Idx
1616
from sympy.utilities.lambdify import implemented_function
17-
from sympy.testing.pytest import raises
17+
from sympy.testing.pytest import raises, warns_deprecated_sympy
1818

1919

2020
def test_printmethod():
@@ -804,3 +804,8 @@ def test_FunctionDefinition_print():
804804
# Should be changed to proper test once multi-line generation is working
805805
# see https://github.com/sympy/sympy/issues/15824
806806
raises(NotImplementedError, lambda: fcode(fd1))
807+
808+
def test_fcode_submodule():
809+
# Test the compatibility sympy.printing.fcode module imports
810+
with warns_deprecated_sympy():
811+
import sympy.printing.fcode # noqa:F401

sympy/testing/runtests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ def _get_doctest_blacklist():
675675
"sympy/matrices/densearith.py", # raises deprecation warning
676676
"sympy/matrices/densesolve.py", # raises deprecation warning
677677
"sympy/matrices/densetools.py", # raises deprecation warning
678+
"sympy/printing/ccode.py", # backwards compatibility shim, importing it breaks the codegen doctests
679+
"sympy/printing/fcode.py", # backwards compatibility shim, importing it breaks the codegen doctests
680+
"sympy/printing/cxxcode.py", # backwards compatibility shim, importing it breaks the codegen doctests
678681
"sympy/parsing/autolev/_antlr/autolevlexer.py", # generated code
679682
"sympy/parsing/autolev/_antlr/autolevparser.py", # generated code
680683
"sympy/parsing/autolev/_antlr/autolevlistener.py", # generated code

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy