-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathrepository.bzl
75 lines (64 loc) · 2.44 KB
/
repository.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- mode: python -*-
# vi: set ft=python :
"""
Provides NumPy from a wheel file.
Example:
WORKSPACE:
load("@drake//tools/workspace/numpy:repo.bzl", "numpy_py_repository")
numpy_py_repository(
name = "foo",
)
BUILD:
py_library(
name = "foobar",
deps = ["@foo//:numpy_py"],
srcs = ["bar.py"],
)
Arguments:
name: A unique name for this rule.
"""
load("@drake//tools/workspace:os.bzl", "determine_os")
# See: https://pypi.org/project/numpy/#files
wheels = {
"ubuntu_16.04": {
"url": "https://files.pythonhosted.org/packages/40/c5/f1ed15dd931d6667b40f1ab1c2fe1f26805fc2b6c3e25e45664f838de9d0/numpy-1.15.2-cp27-cp27mu-manylinux1_x86_64.whl", # noqa
"sha256": "82f00a1e2695a0e5b89879aa25ea614530b8ebdca6d49d4834843d498e8a5e92", # noqa
},
"mac": {
"url": "https://files.pythonhosted.org/packages/d6/47/447d4e08e18c4f0e7f935db24d8afcfc9026a84002c0e5d85103c14baaf1/numpy-1.15.2-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl", # noqa
"sha256": "b5ff7dae352fd9e1edddad1348698e9fea14064460a7e39121ef9526745802e6", # noqa
},
}
def _impl(repository_ctx):
# Do not name this `numpy`, as Bazel will confuse `PYTHONPATH`:
# If `numpy` is located in the repo root, `random` will be shadowed by
# `numpy.random`, causing everything to fail.
# If installed elsewhere, Bazel will put an autogenerated `__init__.py` at
# external directory's root, leak the wrong path, and shadow the real
# `numpy`. See https://github.com/bazelbuild/bazel/issues/3998
if repository_ctx.name == "numpy":
fail("Do not name this repository `numpy`. Please name it " +
"`numpy_py` or something else.")
os_result = determine_os(repository_ctx)
if os_result.error != None:
fail(os_result.error)
wheel = None
if os_result.is_macos:
wheel = wheels["mac"]
elif os_result.is_ubuntu:
key = "ubuntu_" + os_result.ubuntu_release
wheel = wheels.get(key)
if wheel == None:
fail("Unsupported platform")
repository_ctx.download_and_extract(
url = wheel["url"],
sha256 = wheel["sha256"],
type = "zip",
)
repository_ctx.symlink(
Label("@drake//tools/workspace/numpy:package.BUILD.bazel"),
"BUILD.bazel",
)
numpy_py_repository = repository_rule(
_impl,
)