Skip to content

Commit

Permalink
Revert "remove py2 (#27)"
Browse files Browse the repository at this point in the history
This reverts commit 48a4be2.
  • Loading branch information
jacobbogdanov committed Jul 31, 2023
1 parent 7c3e550 commit 0c3893d
Show file tree
Hide file tree
Showing 16 changed files with 366 additions and 89 deletions.
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ http_archive(
"//thirdparty/pip:custom-targets.patch",
"//thirdparty/pip:prettier-errors.patch",
"//thirdparty/pip:requirements-per-platform.patch",
"//thirdparty/pip:compile2.patch",
"//thirdparty/pip:interpreter-per-platform.patch",
],
sha256 = "983eecdfac362d8e7eeb8761ef96e17a3f860aac002bb2bb529adfa39620ddc8",
Expand Down
6 changes: 4 additions & 2 deletions platforms/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ package(default_visibility = ["//visibility:public"])
for platform in PLATFORMS
]

# Create a config setting for each 2-tuple of (python version, system platform).
[
selects.config_setting_group(
name = "PY3_%s" % platform,
name = "%s_%s" % (py, platform),
match_all = [
"@rules_python//python:PY3",
"@rules_python//python:%s" % py,
":%s" % platform,
],
)
for py in ("PY2", "PY3")
for platform in PLATFORMS
]
21 changes: 20 additions & 1 deletion private/toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
load("@rules_python//python:defs.bzl", "py_runtime")
load(
"//python:versions.bzl",
"PYTHON2",
"PYTHON2_MINOR",
"PYTHON3",
"PYTHON3_MINOR",
)

package(default_visibility = ["//:__subpackages__"])

py_runtime(
name = "linux_x86_64_py2_runtime",
interpreter_path = "/usr/bin/%s" % PYTHON2,
python_version = "PY2",
)

py_runtime(
name = "linux_x86_64_py3_runtime",
interpreter_path = "/usr/bin/%s" % PYTHON3,
Expand All @@ -16,6 +24,7 @@ py_runtime(

py_runtime_pair(
name = "linux_x86_64_runtimes",
py2_runtime = ":linux_x86_64_py2_runtime",
py3_runtime = ":linux_x86_64_py3_runtime",
)

Expand All @@ -33,6 +42,12 @@ toolchain(
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
)

py_runtime(
name = "osx_x86_64_py2_runtime",
interpreter_path = "/opt/128technology/bazel/bin/%s" % PYTHON2,
python_version = "PY2",
)

py_runtime(
name = "osx_x86_64_py3_runtime",
interpreter_path = "/opt/128technology/bazel/bin/%s" % PYTHON3,
Expand All @@ -41,6 +56,7 @@ py_runtime(

py_runtime_pair(
name = "osx_x86_64_runtimes",
py2_runtime = ":osx_x86_64_py2_runtime",
py3_runtime = ":osx_x86_64_py3_runtime",
)

Expand All @@ -61,5 +77,8 @@ toolchain(
sh_binary(
name = "setup_macos",
srcs = ["setup_macos.sh"],
args = [PYTHON3_MINOR],
args = [
PYTHON2_MINOR,
PYTHON3_MINOR,
],
)
6 changes: 4 additions & 2 deletions private/toolchains/setup_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
set -e

if [ "$#" -lt 2 ]; then
echo "usage: setup_macos.sh <PY3_MINOR_VERSION>"
echo "usage: setup_macos.sh <PY2_MINOR_VERSION> <PY3_MINOR_VERSION>"
exit 1
fi

PY3_MINOR_VERSION="$1"
PY2_MINOR_VERSION="$1"
PY3_MINOR_VERSION="$2"

if [ ! -x "$(command -v pyenv)" ]; then
echo "pyenv command not found"
Expand Down Expand Up @@ -82,4 +83,5 @@ function on_exit {
}
trap "on_exit" EXIT

set_up_toolchain 2 $PY2_MINOR_VERSION
set_up_toolchain 3 $PY3_MINOR_VERSION
7 changes: 7 additions & 0 deletions python/compile/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ filegroup(
output_group = "python_zip_file",
visibility = ["//visibility:public"],
)

filegroup(
name = "compile2.zip",
srcs = ["@com_github_ali5h_rules_pip//src:compile2"],
output_group = "python_zip_file",
visibility = ["//visibility:public"],
)
18 changes: 15 additions & 3 deletions python/compile/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ def _compile_pip_requirements_impl(ctx):
)

py_toolchain = ctx.toolchains[_PY_TOOLCHAIN_TYPE]
py_runtime = py_toolchain.py3_runtime
pip_compile = ctx.executable._pip3_compile
pip_compile_files = ctx.files._pip3_compile
if ctx.attr.python_version == "PY3":
py_runtime = py_toolchain.py3_runtime
pip_compile = ctx.executable._pip3_compile
pip_compile_files = ctx.files._pip3_compile
else:
py_runtime = py_toolchain.py2_runtime
pip_compile = ctx.executable._pip2_compile
pip_compile_files = ctx.files._pip2_compile

if py_runtime.interpreter != None:
# NOTE: we don't use an in-built interpreter so this might not be exactly correct.
Expand Down Expand Up @@ -66,7 +71,14 @@ compile_pip_requirements = rule(
),
"data": attr.label_list(allow_files = True),
"requirements_txt": attr.string(default = "requirements.txt"),
"python_version": attr.string(default = "PY3", values = ("PY2", "PY3")),
"header": attr.string(default = "# This file is generated code. DO NOT EDIT."),
"_pip2_compile": attr.label(
default = Label("//python/compile:compile2.zip"),
allow_single_file = True,
cfg = "host",
executable = True,
),
"_pip3_compile": attr.label(
default = Label("//python/compile:compile.zip"),
allow_single_file = True,
Expand Down
78 changes: 47 additions & 31 deletions python/pytest/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,55 @@ def pytest_test(
**kwargs: anything else to pass to the underlying py_test rule
"""
args = list(args)
args.extend(["$(location %s)" % src_ for src_ in srcs])

pytest_deps = [
"@pip3//lxml",
"@pip3//pytest",
"@pip3//pytest_timeout",
"@pip3//pdbpp",
"@rules_128tech//rules_128tech/pytest_plugins:pytest_bazel_sharder",
]

if coverage:
args.extend(["--cov", "--no-cov-on-fail"])
pytest_deps.append("@pip3//pytest_cov")

if shuffle:
pytest_deps.append("@pip3//pytest_randomly")
args.extend(["$(location %s)" % src_ for src_ in srcs])

py_test(
name = name,
srcs = list(srcs) + [_MAIN],
main = _MAIN,
deps = depset(
pytest_deps,
transitive = [depset(deps)],
),
data = data,
python_version = python_version,
args = _get_color_args() +
args +
["-p", "rules_128tech.pytest_plugins.pytest_bazel_sharder"],
tags = ["pytest"] + tags,
**kwargs
)
if python_version == "PY2AND3":
version_names = [
("PY2", "py2_%s" % name),
("PY3", "py3_%s" % name),
]
else:
version_names = [(python_version, name)]

extra_deps = [depset(deps)]

for version, test_name in version_names:
version_args = args
pytest_deps = [
"@pip2and3//pytest",
"@rules_128tech//rules_128tech/pytest_plugins:pytest_bazel_sharder",
]

if version == "PY3":
pytest_deps.extend([
"@pip3//lxml",
"@pip3//pytest_timeout",
"@pip3//pdbpp",
])

if coverage:
version_args.extend(["--cov", "--no-cov-on-fail"])
pytest_deps.append("@pip3//pytest_cov")

if shuffle:
pytest_deps.append("@pip3//pytest_randomly")

version_deps = depset(pytest_deps, transitive = extra_deps)

py_test(
name = test_name,
srcs = list(srcs) + [_MAIN],
main = _MAIN,
deps = version_deps,
data = data,
python_version = version,
args = _get_color_args() +
version_args +
["-p", "rules_128tech.pytest_plugins.pytest_bazel_sharder"],
tags = ["pytest"] + tags,
**kwargs
)

def pytest_par(name, srcs, deps = [], args = [], **kwargs):
"""
Expand Down
4 changes: 3 additions & 1 deletion python/versions.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""
Common python version declarations
"""
PYTHON3_MINOR = "9"
PYTHON2_MINOR = "7"
PYTHON3_MINOR = "6"
PYTHON2 = "python2.%s" % PYTHON2_MINOR
PYTHON3 = "python3.%s" % PYTHON3_MINOR
13 changes: 13 additions & 0 deletions thirdparty/pip/2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("//python/compile:compile.bzl", "compile_pip_requirements")

compile_pip_requirements(
name = "compile",
python_version = "PY2",
requirements_in = ":requirements.in",
requirements_txt = select({
"//platforms:linux": "requirements-linux.txt",
"//platforms:osx": "requirements-osx.txt",
}),
)

exports_files(glob(["requirements*"]))
72 changes: 72 additions & 0 deletions thirdparty/pip/2/requirements-linux.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# This file is generated code. DO NOT EDIT.
atomicwrites==1.3.0 \
--hash=sha256:03472c30eb2c5d1ba9227e4c2ca66ab8287fbfbbda3888aa93dc2e28fc6811b4 \
--hash=sha256:75a9445bac02d8d058d5e1fe689654ba5a6556a1dfd8ce6ec55a0ed79866cfa6 \
# via pytest
attrs==19.3.0 \
--hash=sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c \
--hash=sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72 \
# via pytest
configparser==4.0.2 \
--hash=sha256:254c1d9c79f60c45dfde850850883d5aaa7f19a23f13561243a050d5a7c3fe4c \
--hash=sha256:c7d282687a5308319bf3d2e7706e575c635b0a470342641c93bea0ea3b5331df \
# via importlib-metadata
contextlib2==0.6.0.post1 \
--hash=sha256:01f490098c18b19d2bd5bb5dc445b2054d2fa97f09a4280ba2c5f3c394c8162e \
--hash=sha256:3355078a159fbb44ee60ea80abd0d87b80b78c248643b49aa6d94673b413609b \
# via importlib-metadata, zipp
funcsigs==1.0.2 \
--hash=sha256:330cc27ccbf7f1e992e69fef78261dc7c6569012cf397db8d3de0234e6c937ca \
--hash=sha256:a7bb0f2cf3a3fd1ab2732cb49eba4252c2af4240442415b4abce3b87022a8f50 \
# via pytest
importlib-metadata==1.4.0 \
--hash=sha256:bdd9b7c397c273bcc9a11d6629a38487cd07154fa255a467bf704cd2c258e359 \
--hash=sha256:f17c015735e1a88296994c0697ecea7e11db24290941983b08c9feb30921e6d8 \
# via pluggy
more-itertools==5.0.0 \
--hash=sha256:38a936c0a6d98a38bcc2d03fdaaedaba9f412879461dd2ceff8d37564d6522e4 \
--hash=sha256:c0a5785b1109a6bd7fac76d6837fd1feca158e54e521ccd2ae8bfe393cc9d4fc \
--hash=sha256:fe7a7cae1ccb57d33952113ff4fa1bc5f879963600ed74918f1236e212ee50b9 \
# via pytest
pathlib2==2.3.5 \
--hash=sha256:0ec8205a157c80d7acc301c0b18fbd5d44fe655968f5d947b6ecef5290fc35db \
--hash=sha256:6cd9a47b597b37cc57de1c05e56fb1a1c9cc9fab04fe78c29acd090418529868 \
# via importlib-metadata, pytest
pluggy==0.13.1 \
--hash=sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0 \
--hash=sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d \
# via pytest
py==1.8.1 \
--hash=sha256:5e27081401262157467ad6e7f851b7aa402c5852dbcb3dae06768434de5752aa \
--hash=sha256:c20fdd83a5dbc0af9efd622bee9a5564e278f6380fffcacc43ba6f43db2813b0 \
# via pytest
pytest==3.8.2 \
--hash=sha256:7e258ee50338f4e46957f9e09a0f10fb1c2d05493fa901d113a8dafd0790de4e \
--hash=sha256:9332147e9af2dcf46cd7ceb14d5acadb6564744ddff1fe8c17f0ce60ece7d9a2
scandir==1.10.0 \
--hash=sha256:2586c94e907d99617887daed6c1d102b5ca28f1085f90446554abf1faf73123e \
--hash=sha256:2ae41f43797ca0c11591c0c35f2f5875fa99f8797cb1a1fd440497ec0ae4b022 \
--hash=sha256:2b8e3888b11abb2217a32af0766bc06b65cc4a928d8727828ee68af5a967fa6f \
--hash=sha256:2c712840c2e2ee8dfaf36034080108d30060d759c7b73a01a52251cc8989f11f \
--hash=sha256:4d4631f6062e658e9007ab3149a9b914f3548cb38bfb021c64f39a025ce578ae \
--hash=sha256:67f15b6f83e6507fdc6fca22fedf6ef8b334b399ca27c6b568cbfaa82a364173 \
--hash=sha256:7d2d7a06a252764061a020407b997dd036f7bd6a175a5ba2b345f0a357f0b3f4 \
--hash=sha256:8c5922863e44ffc00c5c693190648daa6d15e7c1207ed02d6f46a8dcc2869d32 \
--hash=sha256:92c85ac42f41ffdc35b6da57ed991575bdbe69db895507af88b9f499b701c188 \
--hash=sha256:b24086f2375c4a094a6b51e78b4cf7ca16c721dcee2eddd7aa6494b42d6d519d \
--hash=sha256:cb925555f43060a1745d0a321cca94bcea927c50114b623d73179189a4e100ac \
# via pathlib2
six==1.14.0 \
--hash=sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a \
--hash=sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c \
# via more-itertools, pathlib2, pytest
zipp==1.1.0 \
--hash=sha256:15428d652e993b6ce86694c3cccf0d71aa7afdc6ef1807fa25a920e9444e0281 \
--hash=sha256:d9d2efe11d3a3fb9184da550d35bd1319dc8e30a63255927c82bb42fca1f4f7c \
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
setuptools==44.0.0 \
--hash=sha256:180081a244d0888b0065e18206950d603f6550721bd6f8c0a10221ed467dd78e \
--hash=sha256:e5baf7723e5bb8382fc146e33032b241efc63314211a3a120aaa55d62d2bb008 \
# via pytest
Loading

0 comments on commit 0c3893d

Please sign in to comment.