Skip to content

Commit b717d1a

Browse files
committed
Remove the hack used while importing third party python libraries.
* The `__init__.py` hack no longer seems to be necessary to import third party python libraries by name: Bazel appends the appropriate paths to `sys.path` automatically based on the package deps. * In fact, `__init__.py` is not used at all under Bazel or within Bazel built wheels as it is not listed in any deps and hence does not appear under any module's runfiles.
1 parent 035a05d commit b717d1a

2 files changed

Lines changed: 8 additions & 69 deletions

File tree

WORKSPACE

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,8 @@ new_git_repository(
148148

149149
git_repository(
150150
# We can't use the name "pybind11_abseil" for the repository, as this would
151-
# break the `sys.path` hack that we use for importing third-party Python
152-
# modules. See the comment under "Python libraries" below for a detailed
153-
# explanation.
151+
# break the mechanism Bazel uses for importing third-party Python modules.
152+
# See the comment under "Python libraries" below for a detailed explanation.
154153
name = "pybind11_abseil_repo",
155154
commit = "1caf1890443e8e303bf88850d3c27d5422903168",
156155
remote = "https://github.com/pybind/pybind11_abseil.git",
@@ -171,13 +170,12 @@ _pybind11_python_configure(
171170

172171
# Python libraries
173172

174-
# We need to manipulate sys.path to make these libraries work as if they were imported
175-
# through PIP or the system package manager. When adding a new Python repository here,
176-
# 1. the name of the repository should be different from the name used when importing it
177-
# in Python, to avoid confusing the module loader; by convention, we add `_repo` at
178-
# the end of the name.
179-
# 2. the names of the repositories must be added to the list of third-party repositories
180-
# in `gematria/__init__.py` to make sure that they are added to sys.path.
173+
# Bazel copies the contents of these libraries' repositories to the runfiles
174+
# directories of targets that depend on them to make them work as if they were
175+
# imported through PIP or the system package manager. When adding a new Python
176+
# repository here, the name of the repository should be different from the name
177+
# used when importing it in Python, to avoid confusing the module loader; by
178+
# convention, we add `_repo` at the end of the name.
181179

182180
git_repository(
183181
name = "sonnet_repo",

gematria/__init__.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)