diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 558fe8525a..d791dd58bf 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -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 diff --git a/experimental/python/databricks/bundles/core/_load.py b/experimental/python/databricks/bundles/core/_load.py index e643dc4b1b..cf5cb30355 100644 --- a/experimental/python/databricks/bundles/core/_load.py +++ b/experimental/python/databricks/bundles/core/_load.py @@ -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, ) diff --git a/experimental/python/databricks/bundles/core/_location.py b/experimental/python/databricks/bundles/core/_location.py index 809c3da1d7..7e7d47a652 100644 --- a/experimental/python/databricks/bundles/core/_location.py +++ b/experimental/python/databricks/bundles/core/_location.py @@ -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"]: diff --git a/experimental/python/databricks_tests/core/test_load.py b/experimental/python/databricks_tests/core/test_load.py index 93ff3144fc..c45050a618 100644 --- a/experimental/python/databricks_tests/core/test_load.py +++ b/experimental/python/databricks_tests/core/test_load.py @@ -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", ), } diff --git a/experimental/python/databricks_tests/core/test_location.py b/experimental/python/databricks_tests/core/test_location.py new file mode 100644 index 0000000000..17598ad4c8 --- /dev/null +++ b/experimental/python/databricks_tests/core/test_location.py @@ -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)