Skip to content
Merged
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
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Bundles
* Raise an error when Unity Catalog volumes are used for paths other than artifacts ([#2754](https://github.com/databricks/cli/pull/2754))
* Fixed issue with jobs and pipelines declared in Python not showing in "Bundle resource explorer" in VSCode ([#2764](https://github.com/databricks/cli/pull/2764))
* Made `experimental/python/mutators` and `experimental/python/resources` fields optional in JSON schema ([#2761](https://github.com/databricks/cli/pull/2761))

### API Changes
3 changes: 2 additions & 1 deletion experimental/python/databricks/bundles/core/_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def _parse_locations(module: ModuleType) -> dict[str, Location]:

locations[var_name] = Location(
line=stmt.lineno,
column=stmt.col_offset,
# do conversion: col_offset is 0-based, and column is 1-based
column=stmt.col_offset + 1,
file=file,
)

Expand Down
15 changes: 15 additions & 0 deletions experimental/python/databricks/bundles/core/_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,23 @@
@dataclass(kw_only=True, frozen=True)
class Location:
file: str

line: Optional[int] = None
"""
Line number in the file. Line numbers are 1-based and should be greater than 0.
"""

column: Optional[int] = None
"""
Column number in the line. Column numbers are 1-based and should be greater than 0.
"""

def __post_init__(self):
if self.line is not None and self.line < 1:
raise ValueError(f"Line number must be greater than 0, got {self.line}")

if self.column is not None and self.column < 1:
raise ValueError(f"Column number must be greater than 0, got {self.column}")

@staticmethod
def from_callable(fn: Callable) -> Optional["Location"]:
Expand Down
2 changes: 1 addition & 1 deletion experimental/python/databricks_tests/core/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_parse_locations():
assert locations == {
"my_job": Location(
line=3,
column=0,
column=1,
file="databricks_tests/fixtures/dummy_module.py",
),
}
Expand Down
19 changes: 19 additions & 0 deletions experimental/python/databricks_tests/core/test_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest

from databricks.bundles.core._location import Location


def test_line_number_positive():
"""
Line numbers are 1-based and should be greater than 0.
"""
with pytest.raises(ValueError, match="Line number must be greater than 0"):
Location(file="test.py", line=0)


def test_column_number_positive():
"""
Column numbers are 1-based and should be greater than 0.
"""
with pytest.raises(ValueError, match="Column number must be greater than 0"):
Location(file="test.py", line=1, column=0)
Loading