Skip to content

Commit 42bc2ad

Browse files
committed
Make contents of __init__.py equal across projects
1 parent 62eb1d4 commit 42bc2ad

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/databricks/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
2-
# This file should only contain the following line. Otherwise other sub-packages databricks.* namespace
3-
# may not be importable.
4-
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
1+
# See: https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
2+
#
3+
# This file must only contain the following line, or other packages in the databricks.* namespace
4+
# may not be importable. The contents of this file must be byte-for-byte equivalent across all packages.
5+
# If they are not, parallel package installation may lead to clobbered and invalid files.
6+
# Also see https://github.com/databricks/databricks-sdk-py/issues/343.
7+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)

tests/unit/test_init_file.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import hashlib
2+
import unittest
3+
4+
5+
class InitFileTests(unittest.TestCase):
6+
"""
7+
Micro test to confirm the contents of `databricks/__init__.py` does not change.
8+
9+
Also see https://github.com/databricks/databricks-sdk-py/issues/343#issuecomment-1866029118.
10+
"""
11+
12+
def test_init_file_contents(self):
13+
with open('src/databricks/__init__.py') as f:
14+
init_file_contents = f.read()
15+
16+
# This hash is the expected hash of the contents of `src/databricks/__init__.py`.
17+
# It must not change, or else parallel package installation may lead to clobbered and invalid files.
18+
expected_sha1 = '7f60afe4b2d493117af3e076a5c6ec7f792e2515'
19+
actual_sha1 = hashlib.sha1(init_file_contents.encode('utf-8')).hexdigest()
20+
self.assertEqual(expected_sha1, actual_sha1)
21+
22+
23+
if __name__ == '__main__':
24+
unittest.main()

0 commit comments

Comments
 (0)