aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar David Chen <dzc@google.com>2016-02-10 12:52:11 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-02-10 16:34:46 +0000
commitea02b8a51fc924755971f78e392100b50d8dc5a2 (patch)
tree54ed40e7e37fa90ce0a4e7d44fb1566e7c147176 /examples
parent847a41816c08b846e09c62834f28fbbcb08d5d6d (diff)
Add imports attribute to Bazel native Python rules to allow adding directories to PYTHONPATH.
Fixes #702 RELNOTES: Add imports attribute to native Python rules. -- MOS_MIGRATED_REVID=114314430
Diffstat (limited to 'examples')
-rw-r--r--examples/py_native/BUILD10
-rw-r--r--examples/py_native/bin.py2
-rw-r--r--examples/py_native/fibonacci/BUILD6
-rw-r--r--examples/py_native/fibonacci/fib.py8
-rw-r--r--examples/py_native/test.py4
5 files changed, 28 insertions, 2 deletions
diff --git a/examples/py_native/BUILD b/examples/py_native/BUILD
index d6fdfa957b..5a82223cf8 100644
--- a/examples/py_native/BUILD
+++ b/examples/py_native/BUILD
@@ -7,7 +7,10 @@ filegroup(
py_binary(
name = "bin",
srcs = ["bin.py"],
- deps = [":lib"],
+ deps = [
+ ":lib",
+ "//examples/py_native/fibonacci",
+ ],
)
py_library(
@@ -18,7 +21,10 @@ py_library(
py_test(
name = "test",
srcs = ["test.py"],
- deps = [":lib"],
+ deps = [
+ ":lib",
+ "//examples/py_native/fibonacci",
+ ],
)
py_test(
diff --git a/examples/py_native/bin.py b/examples/py_native/bin.py
index f79379a237..7b656278f6 100644
--- a/examples/py_native/bin.py
+++ b/examples/py_native/bin.py
@@ -1,4 +1,6 @@
"""A tiny example binary for the native Python rules of Bazel."""
from examples.py_native.lib import GetNumber
+from fib import Fib
print "The number is %d" % GetNumber()
+print "Fib(5) == %d" % Fib(5)
diff --git a/examples/py_native/fibonacci/BUILD b/examples/py_native/fibonacci/BUILD
new file mode 100644
index 0000000000..c3ee9b0fea
--- /dev/null
+++ b/examples/py_native/fibonacci/BUILD
@@ -0,0 +1,6 @@
+py_library(
+ name = "fibonacci",
+ srcs = ["fib.py"],
+ imports = ["."],
+ visibility = ["//examples/py_native:__pkg__"],
+)
diff --git a/examples/py_native/fibonacci/fib.py b/examples/py_native/fibonacci/fib.py
new file mode 100644
index 0000000000..645a937a0e
--- /dev/null
+++ b/examples/py_native/fibonacci/fib.py
@@ -0,0 +1,8 @@
+"""An example binary to test the imports attribute of native Python rules."""
+
+
+def Fib(n):
+ if n == 0 or n == 1:
+ return 1
+ else:
+ return Fib(n-1) + Fib(n-2)
diff --git a/examples/py_native/test.py b/examples/py_native/test.py
index 811eee144e..f9543aa727 100644
--- a/examples/py_native/test.py
+++ b/examples/py_native/test.py
@@ -1,6 +1,8 @@
"""A tiny example binary for the native Python rules of Bazel."""
+
import unittest
from examples.py_native.lib import GetNumber
+from fib import Fib
class TestGetNumber(unittest.TestCase):
@@ -8,6 +10,8 @@ class TestGetNumber(unittest.TestCase):
def test_ok(self):
self.assertEquals(GetNumber(), 42)
+ def test_fib(self):
+ self.assertEquals(Fib(5), 8)
if __name__ == '__main__':
unittest.main()