Skip to content

Latest commit

 

History

History
174 lines (149 loc) · 4.12 KB

pip.md

File metadata and controls

174 lines (149 loc) · 4.12 KB

Import pip requirements into Bazel.

Repository Rules

Macros

## pip_repositories
pip_repositories()

Pull in dependencies needed for pulling in pip dependencies.

A placeholder method that will eventually pull in any dependencies needed to install pip dependencies.

pip3_import

pip3_import(name, requirements)

A rule for importing requirements.txt dependencies into Bazel.

This rule imports a requirements.txt file using the system python3, and generates a new requirements.bzl file. This is used via the WORKSPACE pattern:

pip3_import(
    name = "foo",
    requirements = ":requirements.txt",
)
load("@foo//:requirements.bzl", "pip_install")
pip_install()

You can then reference imported dependencies from your BUILD file with:

load("@foo//:requirements.bzl", "requirement")
py_library(
    name = "bar",
    ...
    deps = [
       "//my/other:dep",
       requirement("futures"),
       requirement("mock"),
    ],
)

Or alternatively:

load("@foo//:requirements.bzl", "all_requirements")
py_binary(
    name = "baz",
    ...
    deps = [
       ":foo",
    ] + all_requirements,
)

Attributes

name

Name; Required

A unique name for this rule.

requirements

Label; Required

The label of a requirements.txt file.

## pip_import
pip_import(name, requirements)

A rule for importing requirements.txt dependencies into Bazel.

This rule imports a requirements.txt file using the system python, and generates a new requirements.bzl file. This is used via the WORKSPACE pattern:

pip_import(
    name = "foo",
    requirements = ":requirements.txt",
)
load("@foo//:requirements.bzl", "pip_install")
pip_install()

You can then reference imported dependencies from your BUILD file with:

load("@foo//:requirements.bzl", "requirement")
py_library(
    name = "bar",
    ...
    deps = [
       "//my/other:dep",
       requirement("futures"),
       requirement("mock"),
    ],
)

Or alternatively:

load("@foo//:requirements.bzl", "all_requirements")
py_binary(
    name = "baz",
    ...
    deps = [
       ":foo",
    ] + all_requirements,
)

Attributes

name

Name; Required

A unique name for this rule.

requirements

Label; Required

The label of a requirements.txt file.