Skip to content

Commit c417b76

Browse files
committed
changes
1 parent bb66898 commit c417b76

File tree

4 files changed

+138
-2
lines changed

4 files changed

+138
-2
lines changed

build.sbt

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,41 @@ lazy val sparkV1 = (project in file("spark"))
393393
val dir = baseDirectory.value.getParentFile / "target" / "scala-2.13" / "classes"
394394
Files.createDirectories(dir.toPath)
395395
},
396-
Compile / compile := ((Compile / compile) dependsOn createTargetClassesDir).value,
396+
// Generate Python version.py file with hardcoded version.
397+
// This file is committed to git and auto-updated during build.
398+
generatePythonVersion := {
399+
val versionValue = version.value
400+
// Trim -SNAPSHOT suffix to get PyPI-compatible version (like setup.py does)
401+
val trimmedVersion = versionValue.split("-SNAPSHOT")(0)
402+
val versionFile = baseDirectory.value.getParentFile / "python" / "delta" / "version.py"
403+
val content =
404+
s"""#
405+
|# Copyright (2021) The Delta Lake Project Authors.
406+
|#
407+
|# Licensed under the Apache License, Version 2.0 (the "License");
408+
|# you may not use this file except in compliance with the License.
409+
|# You may obtain a copy of the License at
410+
|#
411+
|# http://www.apache.org/licenses/LICENSE-2.0
412+
|#
413+
|# Unless required by applicable law or agreed to in writing, software
414+
|# distributed under the License is distributed on an "AS IS" BASIS,
415+
|# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
416+
|# See the License for the specific language governing permissions and
417+
|# limitations under the License.
418+
|#
419+
|
420+
|# This file is auto-generated by the build.sbt generatePythonVersion task.
421+
|# Do not edit manually - edit version.sbt instead and run:
422+
|# build/sbt sparkV1/generatePythonVersion
423+
|
424+
|__version__ = "$trimmedVersion"
425+
|""".stripMargin
426+
IO.write(versionFile, content)
427+
versionFile
428+
},
429+
// Hook both createTargetClassesDir and generatePythonVersion into compile task
430+
Compile / compile := ((Compile / compile) dependsOn createTargetClassesDir dependsOn generatePythonVersion).value,
397431
// Generate the package object to provide the version information in runtime.
398432
Compile / sourceGenerators += Def.task {
399433
val file = (Compile / sourceManaged).value / "io" / "delta" / "package.scala"
@@ -1419,6 +1453,7 @@ def listPythonFiles(pythonBase: File): Seq[(File, String)] = {
14191453
ThisBuild / parallelExecution := false
14201454

14211455
val createTargetClassesDir = taskKey[Unit]("create target classes dir")
1456+
val generatePythonVersion = taskKey[File]("Generate Python version.py file")
14221457

14231458
/*
14241459
******************

python/delta/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616

1717
from delta.tables import DeltaTable
1818
from delta.pip_utils import configure_spark_with_delta_pip
19+
from delta.version import __version__
1920

20-
__all__ = ['DeltaTable', 'configure_spark_with_delta_pip']
21+
__all__ = ['DeltaTable', 'configure_spark_with_delta_pip', '__version__']

python/delta/tests/test_version.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#
2+
# Copyright (2021) The Delta Lake Project Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
import os
18+
import unittest
19+
from packaging.version import Version
20+
21+
22+
class VersionAPITests(unittest.TestCase):
23+
24+
@classmethod
25+
def setUpClass(cls):
26+
cls.project_root = os.path.abspath(
27+
os.path.join(os.path.dirname(__file__), '..', '..', '..')
28+
)
29+
cls.version_sbt_path = os.path.join(cls.project_root, 'version.sbt')
30+
31+
def verify_version(self, version):
32+
self.assertIsNotNone(version)
33+
self.assertIsInstance(version, str)
34+
self.assertEqual(version.count("."), 2, "Version should have major.minor.patch format")
35+
# version should be parseable by packaging.version.Version
36+
Version(version)
37+
38+
def test_version_import_from_module(self):
39+
"""Test that __version__ can be imported from delta.version"""
40+
from delta.version import __version__
41+
self.verify_version(__version__)
42+
43+
def test_version_import_from_package(self):
44+
"""Test that __version__ can be imported from delta package"""
45+
from delta import __version__
46+
self.verify_version(__version__)
47+
48+
def test_version_consistency_across_imports(self):
49+
"""Test that version is consistent across import methods"""
50+
from delta.version import __version__ as version_from_module
51+
from delta import __version__ as version_from_package
52+
53+
self.assertEqual(version_from_module, version_from_package)
54+
55+
def test_version_sbt_exists(self):
56+
"""Verify version.sbt exists"""
57+
self.assertTrue(
58+
os.path.exists(self.version_sbt_path),
59+
f"version.sbt not found at {self.version_sbt_path}"
60+
)
61+
62+
def test_version_sbt_and_version_py_consistency(self):
63+
with open(self.version_sbt_path) as f:
64+
sbt_content = f.read()
65+
# Extract version from: ThisBuild / version := "x.y.z-SNAPSHOT" -> "x.y.z"
66+
sbt_version = sbt_content.split('"')[1].removesuffix("-SNAPSHOT")
67+
68+
from delta import __version__
69+
70+
self.assertEqual(
71+
__version__,
72+
sbt_version,
73+
f"version.py ({__version__}) does not match version.sbt ({sbt_version}). "
74+
f"Run: build/sbt sparkV1/generatePythonVersion"
75+
)
76+
77+
78+
if __name__ == '__main__':
79+
unittest.main()

python/delta/version.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Copyright (2021) The Delta Lake Project Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
# This file is auto-generated by the build.sbt generatePythonVersion task.
18+
# Do not edit manually - edit version.sbt instead and run:
19+
# build/sbt sparkV1/generatePythonVersion
20+
21+
__version__ = "4.1.0"

0 commit comments

Comments
 (0)