From 0f9c6ea574918dda094cf5423fa3822112846c30 Mon Sep 17 00:00:00 2001 From: Mouad Benchchaoui Date: Wed, 14 Feb 2018 05:09:15 -0800 Subject: Make __init__.py files creation optional Introduce a new attribute to py_binary and py_test to control whether to create `__init__.py` or not. Fixes https://github.com/bazelbuild/rules_python/issues/55 Closes #4470. PiperOrigin-RevId: 185672243 --- examples/py/BUILD | 1 + examples/py/bin.py | 2 +- examples/py_native/BUILD | 3 +++ examples/py_native/bin.py | 2 +- examples/py_native/fail.py | 2 +- examples/py_native/test.py | 2 +- 6 files changed, 8 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/py/BUILD b/examples/py/BUILD index 39ef8c0452..314bc16ef5 100644 --- a/examples/py/BUILD +++ b/examples/py/BUILD @@ -8,6 +8,7 @@ py_library( py_binary( name = "bin", srcs = ["bin.py"], + legacy_create_init = False, deps = [":lib"], ) diff --git a/examples/py/bin.py b/examples/py/bin.py index f4a6666ddd..cdc01c4b65 100644 --- a/examples/py/bin.py +++ b/examples/py/bin.py @@ -1,3 +1,3 @@ -from examples.py import lib +import lib print("Fib(5)=%d" % lib.Fib(5)) diff --git a/examples/py_native/BUILD b/examples/py_native/BUILD index 9d52fd6848..aafa7b77c7 100644 --- a/examples/py_native/BUILD +++ b/examples/py_native/BUILD @@ -10,6 +10,7 @@ filegroup( py_binary( name = "bin", srcs = ["bin.py"], + legacy_create_init = False, deps = [ ":lib", "//examples/py_native/fibonacci", @@ -24,6 +25,7 @@ py_library( py_test( name = "test", srcs = ["test.py"], + legacy_create_init = False, deps = [ ":lib", "//examples/py_native/fibonacci", @@ -33,5 +35,6 @@ py_test( py_test( name = "fail", srcs = ["fail.py"], + legacy_create_init = False, deps = [":lib"], ) diff --git a/examples/py_native/bin.py b/examples/py_native/bin.py index 45c68b26e5..b7e1223988 100644 --- a/examples/py_native/bin.py +++ b/examples/py_native/bin.py @@ -1,7 +1,7 @@ # pylint: disable=superfluous-parens """A tiny example binary for the native Python rules of Bazel.""" -from examples.py_native.lib import GetNumber from fib import Fib +from lib import GetNumber print("The number is %d" % GetNumber()) print("Fib(5) == %d" % Fib(5)) diff --git a/examples/py_native/fail.py b/examples/py_native/fail.py index 98e35f4ee7..a505ac41aa 100644 --- a/examples/py_native/fail.py +++ b/examples/py_native/fail.py @@ -1,6 +1,6 @@ """A tiny example binary for the native Python rules of Bazel.""" import unittest -from examples.py_native.lib import GetNumber +from lib import GetNumber class TestGetNumber(unittest.TestCase): diff --git a/examples/py_native/test.py b/examples/py_native/test.py index f9543aa727..b860940a38 100644 --- a/examples/py_native/test.py +++ b/examples/py_native/test.py @@ -1,8 +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 +from lib import GetNumber class TestGetNumber(unittest.TestCase): -- cgit v1.2.3