From 07ffa56966396d5a56a3f48bc08d0fbe0f4a4b72 Mon Sep 17 00:00:00 2001 From: Hayk Martiros Date: Sat, 11 Jun 2022 13:00:45 -0700 Subject: [PATCH] Fix code printer import --- symforce/codegen/backends/cpp/cpp_code_printer.py | 4 +--- symforce/codegen/backends/cpp/cpp_config.py | 4 ++-- symforce/codegen/backends/python/python_code_printer.py | 4 +--- symforce/codegen/backends/python/python_config.py | 4 ++-- symforce/codegen/codegen_config.py | 4 ++-- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/symforce/codegen/backends/cpp/cpp_code_printer.py b/symforce/codegen/backends/cpp/cpp_code_printer.py index 00c453172..035722a8e 100644 --- a/symforce/codegen/backends/cpp/cpp_code_printer.py +++ b/symforce/codegen/backends/cpp/cpp_code_printer.py @@ -3,14 +3,12 @@ # This source code is under the Apache 2.0 license found in the LICENSE file. # ---------------------------------------------------------------------------- +import sympy from sympy.printing.c import get_math_macros from sympy.printing.cxx import CXX11CodePrinter from symforce import typing as T -# Everything in this file is SymPy, not SymEngine (even when SymForce is on the SymEngine backend) -import sympy - class CppCodePrinter(CXX11CodePrinter): """ diff --git a/symforce/codegen/backends/cpp/cpp_config.py b/symforce/codegen/backends/cpp/cpp_config.py index 0f25a20ed..bf6d5f993 100644 --- a/symforce/codegen/backends/cpp/cpp_config.py +++ b/symforce/codegen/backends/cpp/cpp_config.py @@ -2,9 +2,9 @@ # SymForce - Copyright 2022, Skydio, Inc. # This source code is under the Apache 2.0 license found in the LICENSE file. # ---------------------------------------------------------------------------- -from __future__ import annotations from dataclasses import dataclass from pathlib import Path +from sympy.printing.codeprinter import CodePrinter from symforce import typing as T from symforce.codegen.codegen_config import CodegenConfig @@ -60,7 +60,7 @@ def templates_to_render(self, generated_file_name: str) -> T.List[T.Tuple[str, s return templates - def printer(self) -> "sympy.CodePrinter": + def printer(self) -> CodePrinter: # NOTE(hayk): Is there any benefit to this being lazy? from symforce.codegen.backends.cpp import cpp_code_printer diff --git a/symforce/codegen/backends/python/python_code_printer.py b/symforce/codegen/backends/python/python_code_printer.py index c6ae5223d..3c2d34822 100644 --- a/symforce/codegen/backends/python/python_code_printer.py +++ b/symforce/codegen/backends/python/python_code_printer.py @@ -3,10 +3,8 @@ # This source code is under the Apache 2.0 license found in the LICENSE file. # ---------------------------------------------------------------------------- -from sympy.printing.pycode import PythonCodePrinter as _PythonCodePrinter - -# Everything in this file is SymPy, not SymEngine (even when SymForce is on the SymEngine backend) import sympy +from sympy.printing.pycode import PythonCodePrinter as _PythonCodePrinter class PythonCodePrinter(_PythonCodePrinter): diff --git a/symforce/codegen/backends/python/python_config.py b/symforce/codegen/backends/python/python_config.py index 27e10df98..d2a805e06 100644 --- a/symforce/codegen/backends/python/python_config.py +++ b/symforce/codegen/backends/python/python_config.py @@ -2,9 +2,9 @@ # SymForce - Copyright 2022, Skydio, Inc. # This source code is under the Apache 2.0 license found in the LICENSE file. # ---------------------------------------------------------------------------- -from __future__ import annotations from dataclasses import dataclass from pathlib import Path +from sympy.printing.codeprinter import CodePrinter from symforce import typing as T from symforce.codegen.codegen_config import CodegenConfig @@ -52,7 +52,7 @@ def templates_to_render(self, generated_file_name: str) -> T.List[T.Tuple[str, s ("function/__init__.py.jinja", "__init__.py"), ] - def printer(self) -> "sympy.CodePrinter": + def printer(self) -> CodePrinter: from symforce.codegen.backends.python import python_code_printer return python_code_printer.PythonCodePrinter() diff --git a/symforce/codegen/codegen_config.py b/symforce/codegen/codegen_config.py index 6ac5ac32a..4c0e8a1e5 100644 --- a/symforce/codegen/codegen_config.py +++ b/symforce/codegen/codegen_config.py @@ -2,10 +2,10 @@ # SymForce - Copyright 2022, Skydio, Inc. # This source code is under the Apache 2.0 license found in the LICENSE file. # ---------------------------------------------------------------------------- -from __future__ import annotations from abc import abstractmethod from dataclasses import dataclass from pathlib import Path +from sympy.printing.codeprinter import CodePrinter from symforce import typing as T @@ -63,7 +63,7 @@ def templates_to_render(self, generated_file_name: str) -> T.List[T.Tuple[str, s pass @abstractmethod - def printer(self) -> "sympy.CodePrinter": + def printer(self) -> CodePrinter: """ Return an instance of the code printer to use for this language. """