Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/prerequisites.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This page describes the system prerequisites needed to run SQLMesh and provides

## SQLMesh prerequisites

You'll need Python 3.8 or higher to use SQLMesh. You can check your python version by running the following command:
You'll need Python 3.9 or higher to use SQLMesh. You can check your python version by running the following command:
```bash
python3 --version
```
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ authors = [{ name = "SQLMesh Contributors" }]
license = { file = "LICENSE" }
requires-python = ">= 3.9"
dependencies = [
"astor",
"click",
"croniter",
"duckdb>=0.10.0,!=0.10.3",
Expand Down Expand Up @@ -198,7 +197,6 @@ disable_error_code = "annotation-unchecked"
[[tool.mypy.overrides]]
module = [
"api.*",
"astor.*",
"IPython.*",
"hyperscript.*",
"py.*",
Expand Down
3 changes: 1 addition & 2 deletions sqlmesh/core/model/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import typing as t
from pathlib import Path

from astor import to_source
from difflib import get_close_matches
from sqlglot import exp
from sqlglot.helper import ensure_list
Expand Down Expand Up @@ -387,7 +386,7 @@ def get_first_arg(keyword_arg_name: str) -> t.Any:
)

try:
expression = to_source(first_arg)
expression = ast.unparse(t.cast(ast.expr, first_arg))
return eval(expression, env, local_env)
except Exception:
if strict_resolution:
Expand Down
11 changes: 7 additions & 4 deletions sqlmesh/utils/metaprogramming.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
from numbers import Number
from pathlib import Path

from astor import to_source

from sqlmesh.core import constants as c
from sqlmesh.utils import format_exception, unique
from sqlmesh.utils.errors import SQLMeshError
Expand Down Expand Up @@ -267,14 +265,19 @@ def normalize_source(obj: t.Any) -> str:

# remove docstrings
body = node.body
if body and isinstance(body[0], ast.Expr) and isinstance(body[0].value, ast.Str):
if (
body
and isinstance(body[0], ast.Expr)
and isinstance(body[0].value, ast.Constant)
and isinstance(body[0].value.value, str)
):
node.body = body[1:]

# remove function return type annotation
if isinstance(node, ast.FunctionDef):
node.returns = None

return to_source(root_node).strip()
return ast.unparse(root_node).strip()


def build_env(
Expand Down
8 changes: 3 additions & 5 deletions tests/utils/test_metaprogramming.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ def closure() -> int:
def test_normalize_source() -> None:
assert (
normalize_source(main_func)
== """def main_func(y: int, foo=exp.true(), *, bar=expressions.Literal.number(1) + 2
):
== """def main_func(y: int, foo=exp.true(), *, bar=expressions.Literal.number(1) + 2):
sqlglot.parse_one('1')
MyClass(47)
DataClass(x=y)
Expand Down Expand Up @@ -271,8 +270,7 @@ def test_serialize_env() -> None:
name="main_func",
alias="MAIN",
path="test_metaprogramming.py",
payload="""def main_func(y: int, foo=exp.true(), *, bar=expressions.Literal.number(1) + 2
):
payload="""def main_func(y: int, foo=exp.true(), *, bar=expressions.Literal.number(1) + 2):
sqlglot.parse_one('1')
MyClass(47)
DataClass(x=y)
Expand Down Expand Up @@ -370,7 +368,7 @@ def sample_context_manager():
"my_lambda": Executable(
name="my_lambda",
path="test_metaprogramming.py",
payload="my_lambda = lambda : print('z')",
payload="my_lambda = lambda: print('z')",
),
"normalize_model_name": Executable(
payload="from sqlmesh.core.dialect import normalize_model_name",
Expand Down