| commit | 11cd3d9b800c4949c237b4e2f405b3e5312089d8 | [log] [tgz] |
|---|---|---|
| author | Jonathon Belotti <jonathon@canva.com> | Thu Jan 23 10:34:52 2020 +1100 |
| committer | Jonathon Belotti <jonathon@canva.com> | Thu Jan 23 10:36:05 2020 +1100 |
| tree | f245f249ffc701c596b822b29e6a7966be18bfee | |
| parent | fe4330c3fe5e53916855aacda18e79d235d96fac [diff] |
rules_python_external actaully DOES NOT require a transitively-closed requirements.txt
Contains Bazel rules to fetch and install Python dependencies from a requirements.txt file.
requirements.txtWhile rules_python_external does not require a transitively-closed requirements.txt file, it is recommended. But if you want to just have top-level packages listed, that works.
Transitively-closed requirements specs are very tedious to produce and maintain manually. To automate the process we recommend pip-compile from jazzband/pip-tools.
For example, pip-compile takes a requirements.in like this:
boto3~=1.9.227 botocore~=1.12.247 click~=7.0
These above are the third-party packages you can directly import.
pip-compile ‘compiles’ it so you get a transitively-closed requirements.txt like this, which should be passed to pip_install below:
boto3==1.9.253 botocore==1.12.253 click==7.0 docutils==0.15.2 # via botocore jmespath==0.9.4 # via boto3, botocore python-dateutil==2.8.1 # via botocore s3transfer==0.2.1 # via boto3 six==1.14.0 # via python-dateutil urllib3==1.25.8 # via botocore
WORKSPACErules_python_external_version = "{COMMIT_SHA}" http_archive( name = "rules_python_external", sha256 = "", # Fill in with correct sha256 of your COMMIT_SHA version strip_prefix = "rules_python_external-{version}".format(version = rules_python_external_version), url = "https://github.com/dillon-giacoppo/rules_python_external/archive/{version}.zip".format(version = rules_python_external_version), ) # Install the rule dependencies load("@rules_python_external//:repositories.bzl", "rules_python_external_dependencies") rules_python_external_dependencies() load("@rules_python_external//:defs.bzl", "pip_install") pip_install( name = "py_deps", requirements = "//:requirements.txt", )
Example BUILD file.
load("@py_deps//:requirements.bzl", "requirement") py_binary( name = "main", srcs = ["main.py"], deps = [ requirement("boto3"), # or @py_deps//pypi__boto3 ], )
Note that above you do not need to add transitively required packages to deps = [ ... ]
bazel test //...