Skip to content

Commit

Permalink
Remove dbx_importer support.
Browse files Browse the repository at this point in the history
Summary:
dbx_importer support was only needed on py2. On python py3.7+
benjamin's PEP 552 takes care of this for us.
GitOrigin-RevId: 334211cd090aaa3d98e111cf8268443a846e981a
  • Loading branch information
armooo authored and jhance committed Mar 3, 2022
1 parent f3fa2c4 commit 995f87b
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 333 deletions.
24 changes: 0 additions & 24 deletions build_tools/py/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,6 @@ filegroup(
visibility = ["//visibility:public"],
)

# All Python 2.7 dbx_py_binarys implicitly depend on this target in
# order to 1) provide the import hook that loads our custom pycs 2)
# pick up Bazel's magic builtin __init__.py generation behavior.
py_binary(
name = "dbx_importer",
srcs = [":dbx_importer_lib"],
python_version = "PY2",
)

py_library(
name = "dbx_importer_lib",
srcs = ["dbx_importer.py"],
srcs_version = "PY2ONLY",
)

dbx_internal_bootstrap_py_binary(
name = "dbx_compile",
srcs = ["dbx_compile.py"],
main = "dbx_compile.py",
deps = [
":dbx_importer",
],
)

dbx_internal_bootstrap_py_binary(
name = "py3_compile",
srcs = ["py3_compile.py"],
Expand Down
24 changes: 0 additions & 24 deletions build_tools/py/BUILD.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,6 @@ filegroup(
visibility = ["//visibility:public"],
)

# All Python 2.7 dbx_py_binarys implicitly depend on this target in
# order to 1) provide the import hook that loads our custom pycs 2)
# pick up Bazel's magic builtin __init__.py generation behavior.
py_binary(
name = "dbx_importer",
srcs = [":dbx_importer_lib"],
python_version = "PY2",
)

py_library(
name = "dbx_importer_lib",
srcs = ["dbx_importer.py"],
srcs_version = "PY2ONLY",
)

dbx_internal_bootstrap_py_binary(
name = "dbx_compile",
srcs = ["dbx_compile.py"],
main = "dbx_compile.py",
deps = [
":dbx_importer",
],
)

dbx_internal_bootstrap_py_binary(
name = "py3_compile",
srcs = ["py3_compile.py"],
Expand Down
30 changes: 3 additions & 27 deletions build_tools/py/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ sys.path.extend([
runfiles + {path_sep} + p
for p in ({relative_piplib_python_path})
])
{dbx_importer}
import os
try:
fd = os.open('/proc/self/comm', os.O_WRONLY)
Expand All @@ -119,13 +118,6 @@ with open(filepath, 'rb') as f:
exec(code, module.__dict__)
"""

_setup_dbx_importer = """
sys.path.insert(0, runfiles + '/../{workspace}')
from build_tools.py import dbx_importer
del sys.path[0]
dbx_importer.install()
"""

def allow_dynamic_links(ctx):
if hasattr(ctx.attr, "dynamic_libraries") and ctx.attr.dynamic_libraries:
return True
Expand Down Expand Up @@ -312,7 +304,6 @@ def emit_py_binary(

if internal_bootstrap:
extra_pythonpath = depset(direct = [pythonpath])
dbx_importer = ""
else:
# Only collect dependencies from dbx_py_library and
# dbx_py_pypi* rules for non-bootstrap binaries. Those
Expand All @@ -329,16 +320,7 @@ def emit_py_binary(
deps = deps,
data = data,
)
if py_toolchain.dbx_importer:
# The importer is only used on py2 non-bootstrap builds
# (bootstrap builds don't read dropbox's pyc).
extra_pythonpath = depset(transitive = [extra_pythonpath], direct = [pythonpath, workspace_root_to_pythonpath(py_toolchain.dbx_importer.label.workspace_root)])
dbx_importer = _setup_dbx_importer.format(
workspace = py_toolchain.dbx_importer.label.workspace_name,
)
else:
extra_pythonpath = depset(transitive = [extra_pythonpath], direct = [pythonpath])
dbx_importer = ""
extra_pythonpath = depset(transitive = [extra_pythonpath], direct = [pythonpath])

piplib_contents_set = piplib_contents[build_tag]
all_piplib_contents = piplib_contents_set.to_list()
Expand Down Expand Up @@ -468,7 +450,6 @@ __path__.extend([os.path.join(os.environ['RUNFILES'], d) for d in (%s,)])
proc_title = repr(ctx.label.name[:15]),
relative_user_python_path = user_python_path,
relative_piplib_python_path = piplib_python_path,
dbx_importer = dbx_importer,
path_sep = repr("\\" if is_windows(ctx) else "/"),
),
)
Expand Down Expand Up @@ -529,13 +510,8 @@ __path__.extend([os.path.join(os.environ['RUNFILES'], d) for d in (%s,)])
for d in data:
runfiles = runfiles.merge(d[DefaultInfo].default_runfiles)

if py_toolchain and py_toolchain.dbx_importer:
# Manually add dbx_import.py. This also implicitly picks up Bazel's magically automatic
# __init__.py insertion behavior, which is why we add it unconditionally.
runfiles = runfiles.merge(py_toolchain.dbx_importer[DefaultInfo].default_runfiles)
else:
# Add blank_py_binary to trigger Bazel's automatic __init__.py insertion behavior.
runfiles = runfiles.merge(ctx.attr._blank_py_binary[DefaultInfo].default_runfiles)
# Add blank_py_binary to trigger Bazel's automatic __init__.py insertion behavior.
runfiles = runfiles.merge(ctx.attr._blank_py_binary[DefaultInfo].default_runfiles)

write_runfiles_tmpl(
ctx,
Expand Down
21 changes: 0 additions & 21 deletions build_tools/py/dbx_compile.py

This file was deleted.

230 changes: 0 additions & 230 deletions build_tools/py/dbx_importer.py

This file was deleted.

Loading

0 comments on commit 995f87b

Please sign in to comment.