-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathrepository.bzl
109 lines (90 loc) · 3.2 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- mode: python -*-
# vi: set ft=python :
"""
Provides NumPy from a wheel file.
Example:
WORKSPACE:
load("@drake//tools/workspace/numpy:repo.bzl", "numpy_repository")
numpy_repository(
name = "foo",
)
BUILD:
py_library(
name = "foobar",
deps = ["@foo//:numpy"],
srcs = ["bar.py"],
)
Arguments:
name: A unique name for this rule.
"""
load("@drake//tools/workspace:os.bzl", "determine_os")
# Generated from Git revision 7d247f4 from numpy/numpy#10898.
# See `./packaging/README.md` for instructions to generate these binaries.
# PR DRAFT(eric.cousineau): Upload these to S3 or when they pass review.
wheels = {
"ubuntu_16.04": {
"url": "https://github.com/EricCousineau-TRI/experimental/raw/e84664659a7ceeac016f626b4d77f5a89c4cad62/numpy/numpy-1.15.0.dev0%2B7d247f4-cp27-cp27mu-linux_x86_64.whl", # noqa
"sha256": "643f7e11c5f0213ae171d91e5759da51e4f39a0a9ba912f42189b3004507c21c", # noqa
},
"mac": {
"url": "https://github.com/EricCousineau-TRI/experimental/raw/3211d6dd6aee9e8dd70a19ef86b961a2de3bf821/numpy/numpy-1.15.0.dev0%2B7d247f4-cp27-cp27m-macosx_10_13_x86_64.whl", # noqa
"sha256": "1b3cee66ff92e2e0dc1c97d167b5b13873c3e97a87829a1c7830964ab48b2648", # 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",
)
file_content = """# -*- python -*-
# DO NOT EDIT: generated by numpy_repository()
load("@drake//tools/install:install.bzl", "install")
licenses([
"notice", # BSD-2-Clause AND BSD-3-Clause AND MIT AND Python-2.0
"unencumbered", # Public-Domain
])
# Interpret `numpy` sources as data to simplify handling.
filegroup(
name = "data",
srcs = glob(["numpy/**/*"]),
visibility = ["//visibility:private"],
)
py_library(
name = "numpy_py",
imports = ["."],
visibility = ["//visibility:public"],
data = [":data"],
)
install(
name = "install",
data = [":data"],
data_dest = "lib/python2.7/site-packages",
visibility = ["//visibility:public"],
)
"""
repository_ctx.file("BUILD.bazel", content = file_content,
executable = False)
numpy_repository = repository_rule(
_impl,
)