pyfabric-dev 0.5.1__tar.gz → 0.5.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {pyfabric_dev-0.5.1/pyfabric_dev.egg-info → pyfabric_dev-0.5.2}/PKG-INFO +2 -2
  2. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/README.md +1 -1
  3. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/__init__.py +1 -1
  4. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/cli/generate_notebooks.py +13 -9
  5. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2/pyfabric_dev.egg-info}/PKG-INFO +2 -2
  6. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev.egg-info/SOURCES.txt +1 -0
  7. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyproject.toml +1 -1
  8. pyfabric_dev-0.5.2/tests/test_generate_notebooks.py +143 -0
  9. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/LICENSE +0 -0
  10. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/NOTICE +0 -0
  11. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/cli/__init__.py +0 -0
  12. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/cli/run_notebook.py +0 -0
  13. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/cli/run_pipeline.py +0 -0
  14. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/cli/run_tests_parallel.py +0 -0
  15. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/defs.py +0 -0
  16. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/fabric.py +0 -0
  17. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/functions.py +0 -0
  18. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/local_config.py +0 -0
  19. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/local_env.py +0 -0
  20. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/mock_notebookutils.py +0 -0
  21. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/runners/__init__.py +0 -0
  22. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/runners/hooks.py +0 -0
  23. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/runners/notebook.py +0 -0
  24. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/runners/pipeline.py +0 -0
  25. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev/spark.py +0 -0
  26. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev.egg-info/dependency_links.txt +0 -0
  27. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev.egg-info/entry_points.txt +0 -0
  28. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev.egg-info/requires.txt +0 -0
  29. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/pyfabric_dev.egg-info/top_level.txt +0 -0
  30. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/setup.cfg +0 -0
  31. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/tests/test_functions_merge.py +0 -0
  32. {pyfabric_dev-0.5.1 → pyfabric_dev-0.5.2}/tests/test_smoke.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyfabric-dev
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: Local development framework for Microsoft Fabric notebooks: source-of-truth Python, generated .Notebook artifacts, mocked Fabric APIs, parallel local testing.
5
5
  Author-email: CashHero <engineering@cashhero.ai>
6
6
  License: Apache-2.0
@@ -37,7 +37,7 @@ A development framework for [Microsoft Fabric](https://www.microsoft.com/fabric)
37
37
  notebooks. Write plain Python modules in `src/`, generate Fabric `.Notebook`
38
38
  artifacts from them, and run + test everything locally with mocked Fabric APIs.
39
39
 
40
- > **Status:** `v0.5.1`. APIs are stabilizing but pre-1.0; minor versions may break.
40
+ > **Status:** `v0.5.2`. APIs are stabilizing but pre-1.0; minor versions may break.
41
41
  >
42
42
  > **Disclaimer:** not affiliated with or endorsed by Microsoft.
43
43
 
@@ -4,7 +4,7 @@ A development framework for [Microsoft Fabric](https://www.microsoft.com/fabric)
4
4
  notebooks. Write plain Python modules in `src/`, generate Fabric `.Notebook`
5
5
  artifacts from them, and run + test everything locally with mocked Fabric APIs.
6
6
 
7
- > **Status:** `v0.5.1`. APIs are stabilizing but pre-1.0; minor versions may break.
7
+ > **Status:** `v0.5.2`. APIs are stabilizing but pre-1.0; minor versions may break.
8
8
  >
9
9
  > **Disclaimer:** not affiliated with or endorsed by Microsoft.
10
10
 
@@ -1,3 +1,3 @@
1
1
  """pyfabric-dev: local development framework for Microsoft Fabric notebooks."""
2
2
 
3
- __version__ = "0.5.1"
3
+ __version__ = "0.5.2"
@@ -849,11 +849,7 @@ def generate_test_notebook(config: NotebookConfig) -> str:
849
849
  # (since those are provided by %run common_functions and %run production_notebook)
850
850
  if config.module_path.exists():
851
851
  test_imports = extract_imports_from_module(config.module_path, skip_imports=[
852
- "from src.common",
853
- "import src.common",
854
- "from src.silver",
855
- "from src.bronze",
856
- "from src.gold",
852
+ "from src.",
857
853
  "import src.",
858
854
  "from tests.",
859
855
  ])
@@ -1067,8 +1063,14 @@ def find_modules_with_run_function(src_dir: Path) -> list[NotebookConfig]:
1067
1063
 
1068
1064
 
1069
1065
  def validate_no_src_imports(notebook_name: str, content: str, warn_only: bool = False):
1070
- """Ensure no src.* imports leaked into generated notebook content."""
1066
+ """Ensure no src.* imports leaked into generated notebook content.
1067
+
1068
+ With ``warn_only`` (test notebooks), indented src.* imports only warn —
1069
+ they live inside test functions that are skipped in Fabric. Top-level
1070
+ (column-0) imports always raise: they execute when the notebook runs.
1071
+ """
1071
1072
  in_docstring = False
1073
+ warned = False
1072
1074
  for i, line in enumerate(content.split("\n"), 1):
1073
1075
  stripped = line.strip()
1074
1076
  # Track docstrings (triple-quoted strings)
@@ -1094,9 +1096,11 @@ def validate_no_src_imports(notebook_name: str, content: str, warn_only: bool =
1094
1096
  f" src.* imports don't work in Fabric. Use try/except (ImportError, FileNotFoundError) "
1095
1097
  f"or move the functionality to common_functions."
1096
1098
  )
1097
- if warn_only:
1098
- print(f" WARNING: {msg}")
1099
- return # One warning per notebook is enough
1099
+ is_top_level = not line[:1].isspace()
1100
+ if warn_only and not is_top_level:
1101
+ if not warned:
1102
+ print(f" WARNING: {msg}")
1103
+ warned = True # One warning per notebook is enough
1100
1104
  else:
1101
1105
  raise ValueError(msg)
1102
1106
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyfabric-dev
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: Local development framework for Microsoft Fabric notebooks: source-of-truth Python, generated .Notebook artifacts, mocked Fabric APIs, parallel local testing.
5
5
  Author-email: CashHero <engineering@cashhero.ai>
6
6
  License: Apache-2.0
@@ -37,7 +37,7 @@ A development framework for [Microsoft Fabric](https://www.microsoft.com/fabric)
37
37
  notebooks. Write plain Python modules in `src/`, generate Fabric `.Notebook`
38
38
  artifacts from them, and run + test everything locally with mocked Fabric APIs.
39
39
 
40
- > **Status:** `v0.5.1`. APIs are stabilizing but pre-1.0; minor versions may break.
40
+ > **Status:** `v0.5.2`. APIs are stabilizing but pre-1.0; minor versions may break.
41
41
  >
42
42
  > **Disclaimer:** not affiliated with or endorsed by Microsoft.
43
43
 
@@ -26,4 +26,5 @@ pyfabric_dev/runners/hooks.py
26
26
  pyfabric_dev/runners/notebook.py
27
27
  pyfabric_dev/runners/pipeline.py
28
28
  tests/test_functions_merge.py
29
+ tests/test_generate_notebooks.py
29
30
  tests/test_smoke.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pyfabric-dev"
7
- version = "0.5.1"
7
+ version = "0.5.2"
8
8
  description = "Local development framework for Microsoft Fabric notebooks: source-of-truth Python, generated .Notebook artifacts, mocked Fabric APIs, parallel local testing."
9
9
  readme = "README.md"
10
10
  license = { text = "Apache-2.0" }
@@ -0,0 +1,143 @@
1
+ """Tests for the notebook generator's src-import stripping and validation."""
2
+
3
+ import pytest
4
+
5
+ from pyfabric_dev.cli.generate_notebooks import (
6
+ NotebookConfig,
7
+ extract_imports_from_module,
8
+ generate_test_notebook,
9
+ read_module_code,
10
+ validate_no_src_imports,
11
+ )
12
+
13
+ TEST_NOTEBOOK_SKIP_IMPORTS = [
14
+ "from src.",
15
+ "import src.",
16
+ "from tests.",
17
+ ]
18
+
19
+
20
+ def test_extract_imports_strips_src_from_any_layer(tmp_path):
21
+ """src.* imports must be stripped regardless of layer — including ones
22
+ added after the generator was written (e.g. src.backup)."""
23
+ module = tmp_path / "test_example.py"
24
+ module.write_text(
25
+ "from datetime import date\n"
26
+ "import pytest\n"
27
+ "from src.common.defs import SOME_CONSTANT\n"
28
+ "from src.bronze.ingest import run\n"
29
+ "from src.backup.backup_lakehouse_files import (\n"
30
+ " backup_lakehouse_files,\n"
31
+ " prune_old_snapshots,\n"
32
+ ")\n"
33
+ "import src.gold.build_full_ledger\n"
34
+ "from tests.fixtures import helper\n"
35
+ )
36
+
37
+ imports = extract_imports_from_module(module, skip_imports=TEST_NOTEBOOK_SKIP_IMPORTS)
38
+
39
+ assert "from datetime import date" in imports
40
+ assert "import pytest" in imports
41
+ assert not any("src." in imp for imp in imports)
42
+ assert not any("tests." in imp for imp in imports)
43
+
44
+
45
+ def test_validate_rejects_top_level_src_import_even_in_test_notebooks():
46
+ content = (
47
+ "import pytest\n"
48
+ "from src.backup.backup_lakehouse_files import run\n"
49
+ )
50
+ with pytest.raises(ValueError, match="src import"):
51
+ validate_no_src_imports("test_backup", content, warn_only=True)
52
+
53
+
54
+ def test_validate_warns_on_indented_src_import_in_test_notebooks(capsys):
55
+ """Indented src.* imports live in test functions skipped in Fabric —
56
+ they warn but don't fail generation."""
57
+ content = (
58
+ "def test_local_only():\n"
59
+ " from src.bronze.ingest_from_priority import run\n"
60
+ )
61
+ validate_no_src_imports("test_bronze", content, warn_only=True)
62
+ assert "WARNING" in capsys.readouterr().out
63
+
64
+
65
+ def test_validate_rejects_any_src_import_in_production_notebooks():
66
+ content = (
67
+ "def helper():\n"
68
+ " from src.bronze.ingest import run\n"
69
+ )
70
+ with pytest.raises(ValueError, match="src import"):
71
+ validate_no_src_imports("10_bronze_ingest", content, warn_only=False)
72
+
73
+
74
+ def test_validate_rejects_multiline_top_level_src_import_in_test_notebooks():
75
+ """The opening line of a multiline top-level src import is at column 0,
76
+ so it must raise even in test notebooks."""
77
+ content = (
78
+ "import pytest\n"
79
+ "from src.backup.backup_lakehouse_files import (\n"
80
+ " backup_lakehouse_files,\n"
81
+ " prune_old_snapshots,\n"
82
+ ")\n"
83
+ )
84
+ with pytest.raises(ValueError, match="src import"):
85
+ validate_no_src_imports("test_backup", content, warn_only=True)
86
+
87
+
88
+ def test_read_module_code_keeps_indented_imports_but_drops_top_level(tmp_path):
89
+ """With skip_top_level_only, the inlined test body drops column-0 imports
90
+ (re-emitted in the imports cell) but preserves imports inside functions."""
91
+ module = tmp_path / "test_example.py"
92
+ module.write_text(
93
+ "from src.bronze.ingest import run\n"
94
+ "import os\n"
95
+ "\n"
96
+ "def test_local_only():\n"
97
+ " from src.common.helpers import local_helper\n"
98
+ " return local_helper(run, os)\n"
99
+ )
100
+
101
+ body = read_module_code(
102
+ module, skip_imports=["import ", "from "], skip_top_level_only=True
103
+ )
104
+
105
+ assert "from src.bronze.ingest import run" not in body
106
+ assert "import os" not in body
107
+ # Indented import inside the test function survives.
108
+ assert " from src.common.helpers import local_helper" in body
109
+ assert "def test_local_only():" in body
110
+
111
+
112
+ def test_generate_test_notebook_strips_top_level_src_and_keeps_indented(tmp_path):
113
+ """End-to-end: a generated test notebook must carry no top-level src.*
114
+ import (they execute in Fabric) while keeping indented ones, and must
115
+ pass the test-notebook validation without raising."""
116
+ module = tmp_path / "test_sales.py"
117
+ module.write_text(
118
+ "from datetime import date\n"
119
+ "from src.bronze.ingest import run\n"
120
+ "from src.backup.backup_lakehouse_files import backup_lakehouse_files\n"
121
+ "\n"
122
+ "def run_tests(spark, logger):\n"
123
+ " from src.common.helpers import local_helper\n"
124
+ " _ = (date, run, backup_lakehouse_files, local_helper)\n"
125
+ )
126
+ config = NotebookConfig(
127
+ module_path=module, notebook_name="test_sales", layer="tests"
128
+ )
129
+
130
+ content = generate_test_notebook(config)
131
+
132
+ top_level_src = [
133
+ line
134
+ for line in content.split("\n")
135
+ if line.startswith("from src.") or line.startswith("import src.")
136
+ ]
137
+ assert not top_level_src, f"top-level src imports leaked: {top_level_src}"
138
+ # The indented import inside run_tests is preserved in the inlined body.
139
+ assert " from src.common.helpers import local_helper" in content
140
+ # Non-src top-level imports still make it into the imports cell.
141
+ assert "from datetime import date" in content
142
+ # Validation (as write_notebook runs it for test notebooks) must not raise.
143
+ validate_no_src_imports("test_sales", content, warn_only=True)
File without changes
File without changes
File without changes