Skip to content

Commit db66446

Browse files
Curts0Curts0BT
andauthored
0.5.6 Tmdl POC (#102)
* concept of tmdl implemented * woops misspelled * tmdl poc * reworking test framework w/ tox * basic tmdl tests * clean up paramtrize into conftest * pytest_generate_test cleanup * drop 3.8 add 3.13 * nevermind I'll keep 3.8 --------- Co-authored-by: Curtis Stallings <curtis.stallings@bakertilly.com>
1 parent b8b30bf commit db66446

25 files changed

+133
-117
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
2-
extend-ignore=E203
2+
extend-ignore=E203, D107
33
max-line-length=100
44
docstring-convention=google

.github/workflows/docstr-coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030
python-version: '3.10'
3131
- run: pip install --upgrade pip
3232
- run: pip install docstr-coverage==2.2.0
33-
- run: docstr-coverage
33+
- run: docstr-coverage --skip-init

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ docs/_config.yml# Byte-compiled / optimized / DLL files
178178
*$py.class
179179
/Best_Practice_Analyzer
180180
/Tabular_Editor_2
181+
*.tmdl
181182

182183
# Test files for new functionality
183184
test-notebook.ipynb

.pre-commit-config.yaml

Lines changed: 0 additions & 21 deletions
This file was deleted.

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
exclude pytabular/localsecret.py
21
include pytabular/dll/Microsoft.AnalysisServices.AdomdClient.dll
32
include pytabular/dll/Microsoft.AnalysisServices.Core.dll
43
include pytabular/dll/Microsoft.AnalysisServices.dll

docs/tmdl.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:::pytabular.tmdl.Tmdl

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ nav:
2525
- best_practice_analyzer: best_practice_analyzer.md
2626
- pbi_helper: pbi_helper.md
2727
- logic_utils: logic_utils.md
28+
- tmdl: tmdl.md
2829
- Running Traces: tabular_tracing.md
2930
- Documenting Model: document.md
3031
- Contributing: CONTRIBUTING.md

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "python_tabular"
7-
version = "0.5.5"
7+
version = "0.5.6"
88
authors = [
99
{ name="Curtis Stallings", email="curtisrstallings@gmail.com" },
1010
]
@@ -25,6 +25,7 @@ classifiers = [
2525
"Programming Language :: Python :: 3.10",
2626
"Programming Language :: Python :: 3.11",
2727
"Programming Language :: Python :: 3.12",
28+
"Programming Language :: Python :: 3.13",
2829
"Development Status :: 5 - Production/Stable",
2930
"Operating System :: Microsoft",
3031
"License :: OSI Approved :: MIT License"

pytabular/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
from .query import Connection
6666
from .pbi_helper import find_local_pbi_instances
6767
from .document import ModelDocumenter
68+
from .tmdl import Tmdl
6869

6970

7071
logger.info("Import successful...")

pytabular/tmdl.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""See [TMDL Scripting].(https://learn.microsoft.com/en-us/analysis-services/tmdl/tmdl-overview).
2+
3+
Run `Tmdl(model).save_to_folder()` to save tmdl of model.
4+
Run `Tmdl(model).execute()` to execute a specific set of tmdl scripts.
5+
"""
6+
7+
from Microsoft.AnalysisServices.Tabular import TmdlSerializer
8+
9+
10+
class Tmdl:
11+
"""Specify the specific model you want to use for scripting.
12+
13+
Args:
14+
model (Tabular): Initialize with Tabular model.
15+
"""
16+
def __init__(self, model):
17+
self.model = model
18+
19+
def save_to_folder(self, path: str = "tmdl"):
20+
"""Runs `SerializeModelToFolder` from .net library.
21+
22+
Args:
23+
path (str, optional): directory where to save tmdl structure.
24+
Defaults to "tmdl".
25+
"""
26+
TmdlSerializer.SerializeModelToFolder(self.model._object, path)
27+
return True
28+
29+
def execute(self, path: str = "tmdl", auto_save: bool = True):
30+
"""Runs `DeserializeModelFromFolder` from .net library.
31+
32+
Args:
33+
path (str, optional): directory to look for tmdl scripts.
34+
Defaults to "tmdl".
35+
auto_save (bool, optional): You can set to false
36+
if you want to precheck a few things, but will need to
37+
run `model.save_changes()`. Setting to `True` will go ahead
38+
and execute `model.save_changes()` Defaults to True.
39+
"""
40+
model_object = TmdlSerializer.DeserializeModelFromFolder(path)
41+
model_object.CopyTo(self.model._object)
42+
if auto_save:
43+
return self.model.save_changes()
44+
else:
45+
return True

0 commit comments

Comments
 (0)