Skip to content

Commit 22a0d31

Browse files
committed
🎯 feat: add list versions method.
1 parent 28e79f4 commit 22a0d31

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/sqlplate/sqlplate.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ def list_formats(path: Optional[Path] = None) -> list[str]:
7272
if fmt.is_dir() and fmt.name != 'utils'
7373
]
7474

75+
@staticmethod
76+
def list_versions(fmt: str, path: Optional[Path] = None) -> list[str]:
77+
"""Return supported version of specific format with list of version
78+
string value.
79+
80+
Arges:
81+
path (Path | None): A template path that want to search.
82+
83+
:rtype: list[str]
84+
"""
85+
if path is None:
86+
path: Path = Path('./templates')
87+
return [
88+
f.name
89+
for f in (path / fmt).glob(pattern='*')
90+
if f.is_dir()
91+
]
92+
7593
@classmethod
7694
def format(cls, name: str, path: Optional[Path] = None) -> 'SQLPlate':
7795
"""Construction this class from a system value name.

tests/test_sqlplate.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ def test_sqlplate_version(template_path):
2727
fmt.version("latest")
2828

2929

30+
def test_sqlplate_versions(template_path):
31+
versions: list[str] = SQLPlate.list_versions(
32+
fmt="databricks", path=template_path
33+
)
34+
assert isinstance(versions, list)
35+
assert len(versions) > 0
36+
assert 'latest' in versions
37+
38+
3039
def test_sqlplate_check(template_path):
3140
fmt: SQLPlate = SQLPlate.format("databricks", path=template_path)
3241

0 commit comments

Comments
 (0)