diff --git a/docs/rules.md b/docs/rules.md index 4fd2b5d8..cf9ed190 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -26,7 +26,7 @@ py_wheel(name, src) ## py_binary
-py_binary(name, srcs, main, kwargs)
+py_binary(name, srcs, main, imports, kwargs)
 
Wrapper macro for the py_binary rule, setting a default for imports. @@ -43,6 +43,7 @@ you can `bazel run [name].venv` to produce this, then use it in the editor. | name | name of the rule | none | | srcs | python source files | [] | | main | the entry point. If absent, then the first entry in srcs is used. | None | +| imports |

-

| ["."] | | kwargs | see [py_binary attributes](./py_binary) | none | @@ -51,7 +52,7 @@ you can `bazel run [name].venv` to produce this, then use it in the editor. ## py_library
-py_library(name, kwargs)
+py_library(name, imports, kwargs)
 
Wrapper macro for the py_library rule, setting a default for imports @@ -62,6 +63,7 @@ Wrapper macro for the py_library rule, setting a default for imports | Name | Description | Default Value | | :------------- | :------------- | :------------- | | name | name of the rule | none | +| imports |

-

| ["."] | | kwargs | see [py_library attributes](./py_library) | none | @@ -70,7 +72,7 @@ Wrapper macro for the py_library rule, setting a default for imports ## py_test
-py_test(name, main, srcs, kwargs)
+py_test(name, main, srcs, imports, kwargs)
 
Identical to py_binary, but produces a target that can be used with `bazel test`. @@ -83,6 +85,7 @@ Identical to py_binary, but produces a target that can be used with `bazel test` | name |

-

| none | | main |

-

| None | | srcs |

-

| [] | +| imports |

-

| ["."] | | kwargs |

-

| none | diff --git a/py/defs.bzl b/py/defs.bzl index bc7ad788..cda345cd 100644 --- a/py/defs.bzl +++ b/py/defs.bzl @@ -5,7 +5,7 @@ load("//py/private:py_binary.bzl", _py_binary = "py_binary", _py_test = "py_test load("//py/private:py_library.bzl", _py_library = "py_library") load("//py/private:py_wheel.bzl", "py_wheel_lib") -def py_library(name, **kwargs): +def py_library(name, imports = ["."], **kwargs): """Wrapper macro for the py_library rule, setting a default for imports Args: @@ -14,11 +14,11 @@ def py_library(name, **kwargs): """ _py_library( name = name, - imports = kwargs.pop("imports", []) + ["."], + imports = imports, **kwargs ) -def py_binary(name, srcs = [], main = None, **kwargs): +def py_binary(name, srcs = [], main = None, imports = ["."], **kwargs): """Wrapper macro for the py_binary rule, setting a default for imports. It also creates a virtualenv to constrain the interpreter and packages used at runtime, @@ -34,32 +34,32 @@ def py_binary(name, srcs = [], main = None, **kwargs): name = name, srcs = srcs, main = main if main != None else srcs[0], - imports = kwargs.pop("imports", ["."]), + imports = imports, **kwargs ) _py_venv( name = "%s.venv" % name, deps = kwargs.pop("deps", []), - imports = kwargs.pop("imports", ["."]), + imports = imports, srcs = srcs, tags = ["manual"], ) -def py_test(name, main = None, srcs = [], **kwargs): +def py_test(name, main = None, srcs = [], imports = ["."], **kwargs): "Identical to py_binary, but produces a target that can be used with `bazel test`." _py_test( name = name, srcs = srcs, main = main if main != None else srcs[0], - imports = kwargs.pop("imports", ["."]), + imports = imports, **kwargs ) _py_venv( name = "%s.venv" % name, deps = kwargs.pop("deps", []), - imports = kwargs.pop("imports", ["."]), + imports = imports, srcs = srcs, tags = ["manual"], )