Skip to content

Commit

Permalink
Make contents of __init__.py equal across projects (#304)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Pieter Noordhuis <pieter.noordhuis@databricks.com>
Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
Co-authored-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
  • Loading branch information
pietern and Jesse Whitehouse authored Dec 26, 2023
1 parent 62eb1d4 commit 3f6834c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/databricks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
# This file should only contain the following line. Otherwise other sub-packages databricks.* namespace
# may not be importable.
# See: https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
#
# This file must only contain the following line, or other packages in the databricks.* namespace
# may not be importable. The contents of this file must be byte-for-byte equivalent across all packages.
# If they are not, parallel package installation may lead to clobbered and invalid files.
# Also see https://github.com/databricks/databricks-sdk-py/issues/343.
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
19 changes: 19 additions & 0 deletions tests/unit/test_init_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import hashlib


class TestInitFile:
"""
Micro test to confirm the contents of `databricks/__init__.py` does not change.
Also see https://github.com/databricks/databricks-sdk-py/issues/343#issuecomment-1866029118.
"""

def test_init_file_contents(self):
with open("src/databricks/__init__.py") as f:
init_file_contents = f.read()

# This hash is the expected hash of the contents of `src/databricks/__init__.py`.
# It must not change, or else parallel package installation may lead to clobbered and invalid files.
expected_sha1 = "2772edbf52e517542acf8c039479c4b57b6ca2cd"
actual_sha1 = hashlib.sha1(init_file_contents.encode("utf-8")).hexdigest()
assert expected_sha1 == actual_sha1

0 comments on commit 3f6834c

Please sign in to comment.