Skip to content

Commit

Permalink
migrate to extras structure
Browse files Browse the repository at this point in the history
- move to sql extra
- move to http_request extra
  • Loading branch information
davidkhala committed Dec 11, 2024
1 parent 81a07ba commit b6d6a17
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
9 changes: 9 additions & 0 deletions davidkhala/sql/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from sqlparse import split, format


class SQL:
def __init__(self, sql: str):
self.sql = sql

def split(self) -> list[str]:
return split(format(self.sql, strip_comments=True))
10 changes: 0 additions & 10 deletions davidkhala/syntax/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,3 @@ class Serializable(ABC):
def as_dict(self) -> dict:
pass


from sqlparse import split, format


class SQL:
def __init__(self, sql: str):
self.sql = sql

def split(self) -> list[str]:
return split(format(self.sql, strip_comments=True))
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ packages = [{ include = "davidkhala" }]

[tool.poetry.dependencies]
python = "^3.10"
requests = "*"
sqlparse = "*"
# for extras
requests = { version = "*", optional = true }
sqlparse = { version = "*", optional = true }
[tool.poetry.group.dev.dependencies]
pytest = "*"
python-dotenv = "*"

[tool.poetry.extras]
sql = ["sqlparse"]
http_request = ["requests"]

[build-system]
requires = ["poetry-core"]
Expand Down
16 changes: 16 additions & 0 deletions test/sql_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest

from davidkhala.sql import SQL
from davidkhala.syntax import fs


class SQLParseTestCase(unittest.TestCase):
def test_split(self):
sql_content = fs.read('data/test.sql')
s = SQL(sql_content)
for statement in s.split():
print(statement)


if __name__ == '__main__':
unittest.main()
10 changes: 1 addition & 9 deletions test/syntax_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path

from davidkhala.syntax import Package, NameEnum, fs, for_each, path
from davidkhala.syntax.format import JSONReadable, Serializable, SQL
from davidkhala.syntax.format import JSONReadable, Serializable
from davidkhala.syntax.js import Array


Expand Down Expand Up @@ -132,13 +132,5 @@ def test_name(self):
self.assertRaises(AssertionError, Package, '@davidkhala/http')


class SQLParseTestCase(unittest.TestCase):
def test_split(self):
sql_content = fs.read('data/test.sql')
s = SQL(sql_content)
for statement in s.split():
print(statement)


if __name__ == '__main__':
unittest.main()

0 comments on commit b6d6a17

Please sign in to comment.