From 4a8e2bdc2d5f52ed6d54c794cfca3bbfafaf71f6 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 15 Oct 2021 15:50:47 +1000 Subject: [PATCH] download wheels using rules_python --- defs.bzl | 8 ++++---- late_deps.bzl | 4 ++-- pip/binary.bzl | 22 ++++------------------ pip/stubs/gatherstubs.py | 2 +- pylib/tests/run_mypy.py | 2 +- qt/tests/run_mypy.py | 2 +- 6 files changed, 13 insertions(+), 27 deletions(-) diff --git a/defs.bzl b/defs.bzl index 1042004ac..e12eee10a 100644 --- a/defs.bzl +++ b/defs.bzl @@ -7,9 +7,9 @@ load("//proto:protobuf.bzl", "setup_protobuf_binary") load("//proto:format.bzl", "setup_clang_format") load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install") load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories") -load("@com_github_ali5h_rules_pip//:defs.bzl", "pip_import") load("//pip/pyqt5:defs.bzl", "install_pyqt5") load("//pip/pyqt6:defs.bzl", "install_pyqt6") +load("@rules_python//python:pip.bzl", "pip_parse") anki_version = "2.1.49" @@ -33,10 +33,10 @@ def setup_deps(): native.register_toolchains("@python//:python3_toolchain") - pip_import( + pip_parse( name = "py_deps", - requirements = "@ankidesktop//pip:requirements.txt", - python_runtime = "@python//:python", + requirements_lock = "@ankidesktop//pip:requirements.txt", + python_interpreter_target = "@python//:python", ) install_pyqt5( diff --git a/late_deps.bzl b/late_deps.bzl index cee5563f3..65f217930 100644 --- a/late_deps.bzl +++ b/late_deps.bzl @@ -1,10 +1,10 @@ """Repo setup that can't happen until after defs.bzl:setup_deps() is run.""" -load("@py_deps//:requirements.bzl", "pip_install") +load("@py_deps//:requirements.bzl", "install_deps") load("@rules_rust//tools/rust_analyzer/raze:crates.bzl", "rules_rust_tools_rust_analyzer_fetch_remote_crates") load("@build_bazel_rules_nodejs//toolchains/esbuild:esbuild_repositories.bzl", "esbuild_repositories") def setup_late_deps(): - pip_install() + install_deps() rules_rust_tools_rust_analyzer_fetch_remote_crates() esbuild_repositories() diff --git a/pip/binary.bzl b/pip/binary.bzl index e8d8aedcb..fbf8bbe23 100644 --- a/pip/binary.bzl +++ b/pip/binary.bzl @@ -2,28 +2,14 @@ load("@bazel_skylib//rules:copy_file.bzl", "copy_file") load("@py_deps//:requirements.bzl", "requirement") def pip_binary(name, pkg = None): - "Expose a binary from pip as an executable for linting." + "Expose a binary from pip as an executable for linting. Does not work on Windows." if not pkg: pkg = name - binary_prefix = requirement(pkg).replace(":pkg", ":bin/" + name) - - copy_file( - name = name + "_bin", - src = select({ - "@platforms//os:windows": binary_prefix + ".exe", - "//conditions:default": binary_prefix, - }), - out = name + "_bin.py", - ) - - native.py_binary( + native.alias( name = name, - srcs = [":" + name + "_bin.py"], - main = ":" + name + "_bin.py", - deps = [ - requirement(pkg), - ], + actual = requirement(pkg).replace(":pkg", ":rules_python_wheel_entry_point_" + name), visibility = ["//visibility:public"], + tags = ["manual"], ) diff --git a/pip/stubs/gatherstubs.py b/pip/stubs/gatherstubs.py index ba0d45f7e..358233a75 100644 --- a/pip/stubs/gatherstubs.py +++ b/pip/stubs/gatherstubs.py @@ -17,7 +17,7 @@ def copy_folder(pkgname, path, outbase): shutil.copytree(path, os.path.join(outbase, f"{stubname}-stubs")) -name_re = re.compile("__types_(.+?)_\d") +name_re = re.compile("__types_(.+?)$") if __name__ == "__main__": outbase = os.path.abspath(sys.argv[1]) diff --git a/pylib/tests/run_mypy.py b/pylib/tests/run_mypy.py index fc5194a89..50f40731d 100644 --- a/pylib/tests/run_mypy.py +++ b/pylib/tests/run_mypy.py @@ -31,7 +31,7 @@ if __name__ == "__main__": # bazel passes in \\?\c:\... path; mypy can't handle it, so we # strip off prefix for entry in sys.path: - if "__mypy_" in entry: + if entry.endswith("__mypy"): typeshed = f"{entry[4:]}\\mypy\\typeshed" args.append("--custom-typeshed-dir") args.append(typeshed) diff --git a/qt/tests/run_mypy.py b/qt/tests/run_mypy.py index f324a1a82..9540781b0 100644 --- a/qt/tests/run_mypy.py +++ b/qt/tests/run_mypy.py @@ -39,7 +39,7 @@ if __name__ == "__main__": # bazel passes in \\?\c:\... path; mypy can't handle it, so we # strip off prefix for entry in sys.path: - if "__mypy_" in entry: + if entry.endswith("__mypy"): typeshed = entry[4:] + "\\mypy\\typeshed" args.append("--custom-typeshed-dir") args.append(typeshed)