tubular / rules_pygen

Rules for generating native Bazel Python libraries from requirements.txt
Apache License 2.0
15 stars 1 forks source link

Feature Request: support whl files checked into SCM #13

Open nickbreen opened 3 years ago

nickbreen commented 3 years ago

We do an airgapped build where the CI server has no internet access. We check in the whl files into SCM.

When specifying a requirements.txt with local file references the rules generator logs warnings and then fails with FileNotFound:

# requirements.txt
yarl-1.4.2-cp36-cp36m-manylinux1_x86_64.whl

WARNING: Requirement 'yarl-1.4.2-cp36-cp36m-manylinux1_x86_64.whl' looks like a filename, but the file does not exist

I think that the missing feature is a parameter for :generate to provide a directory (and possibly specify it multiple times) of whl files that can be resolved against when the requirements.txt file has a filename specification.

nickbreen commented 3 years ago

This can be achieved with a file: relative URL.

http_archive(
    name = _name("aiohttp"),
    build_file_content = _build_file_content(["aiohttp"]),
    sha256 = "ae55bac364c405caa23a4f2d6cfecc6a0daada500274ffca4a9230e7129eac59",
    type = "zip",
    url = "file:lib/3rd-party-python/aiohttp/3.6.2/aiohttp-3.6.2-cp36-cp36m-manylinux1_x86_64.whl",
)

def _build_file_content(imports = ["."]):
    if type(imports) != "list":
        fail("imports must be a list, got: " + type(imports))

    imports_str = ",".join(['"%s"' % i for i in imports])
    return '''
py_library(
    name = "pkg",
    srcs = glob(["**/*.py"]),
    data = glob(["**/*"], exclude = ["**/*.py", "WORKSPACE", "BUILD.*"]),
    imports = [%s],
    visibility = ["//visibility:public"],
)
''' % imports_str