Dillon Giacoppo | 12bfbdf | 2020-01-02 09:26:42 +1100 | [diff] [blame] | 1 | workspace(name = "example_repo") |
| 2 | |
| 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
| 4 | |
| 5 | http_archive( |
| 6 | name = "rules_python", |
Jonathon Belotti | 3baa266 | 2020-09-08 21:08:43 +1000 | [diff] [blame] | 7 | url = "https://github.com/bazelbuild/rules_python/releases/download/0.0.3/rules_python-0.0.3.tar.gz", |
| 8 | sha256 = "e46612e9bb0dae8745de6a0643be69e8665a03f63163ac6610c210e80d14c3e4", |
Dillon Giacoppo | 12bfbdf | 2020-01-02 09:26:42 +1100 | [diff] [blame] | 9 | ) |
Gergely Fábián | ed2f644 | 2020-06-03 08:36:12 +0200 | [diff] [blame] | 10 | |
Dillon Giacoppo | 12bfbdf | 2020-01-02 09:26:42 +1100 | [diff] [blame] | 11 | load("@rules_python//python:repositories.bzl", "py_repositories") |
Gergely Fábián | ed2f644 | 2020-06-03 08:36:12 +0200 | [diff] [blame] | 12 | |
Dillon Giacoppo | 12bfbdf | 2020-01-02 09:26:42 +1100 | [diff] [blame] | 13 | py_repositories() |
| 14 | |
Alex Eagle | 6ed1fe5 | 2020-08-31 08:09:18 -0700 | [diff] [blame] | 15 | load("@rules_python//experimental/rules_python_external:defs.bzl", "pip_install") |
Gergely Fábián | ed2f644 | 2020-06-03 08:36:12 +0200 | [diff] [blame] | 16 | |
Dillon Giacoppo | 12bfbdf | 2020-01-02 09:26:42 +1100 | [diff] [blame] | 17 | pip_install( |
Gergely Fábián | 2c78da5 | 2020-07-09 08:45:01 +0200 | [diff] [blame] | 18 | # (Optional) You can provide extra parameters to pip. |
| 19 | # Here, make pip output verbose (this is usable with `quiet = False`). |
| 20 | #extra_pip_args = ["-v"], |
| 21 | |
| 22 | # (Optional) You can exclude custom elements in the data section of the generated BUILD files for pip packages. |
| 23 | # Exclude directories with spaces in their names in this example (avoids build errors if there are such directories). |
| 24 | #pip_data_exclude = ["**/* */**"], |
| 25 | |
| 26 | # (Optional) You can provide a python_interpreter (path) or a python_interpreter_target (a Bazel target, that |
Gergely Fábián | ed2f644 | 2020-06-03 08:36:12 +0200 | [diff] [blame] | 27 | # acts as an executable). The latter can be anything that could be used as Python interpreter. E.g.: |
| 28 | # 1. Python interpreter that you compile in the build file (as above in @python_interpreter). |
| 29 | # 2. Pre-compiled python interpreter included with http_archive |
| 30 | # 3. Wrapper script, like in the autodetecting python toolchain. |
Dillon Giacoppo | cdc0305 | 2020-08-16 19:48:49 +1000 | [diff] [blame] | 31 | #python_interpreter_target = "@python_interpreter//:python_bin", |
Gergely Fábián | 2c78da5 | 2020-07-09 08:45:01 +0200 | [diff] [blame] | 32 | |
| 33 | # (Optional) You can set quiet to False if you want to see pip output. |
| 34 | #quiet = False, |
| 35 | |
Dillon Giacoppo | 0aaa43b | 2020-01-02 11:39:56 +1100 | [diff] [blame] | 36 | # Uses the default repository name "pip" |
Dillon Giacoppo | 12bfbdf | 2020-01-02 09:26:42 +1100 | [diff] [blame] | 37 | requirements = "//:requirements.txt", |
| 38 | ) |
Gergely Fábián | ed2f644 | 2020-06-03 08:36:12 +0200 | [diff] [blame] | 39 | |
Dillon Giacoppo | cdc0305 | 2020-08-16 19:48:49 +1000 | [diff] [blame] | 40 | # You could optionally use an in-build, compiled python interpreter as a toolchain, |
| 41 | # and also use it to execute pip. |
| 42 | # |
| 43 | # Special logic for building python interpreter with OpenSSL from homebrew. |
| 44 | # See https://devguide.python.org/setup/#macos-and-os-x |
| 45 | #_py_configure = """ |
| 46 | #if [[ "$OSTYPE" == "darwin"* ]]; then |
| 47 | # ./configure --prefix=$(pwd)/bazel_install --with-openssl=$(brew --prefix openssl) |
| 48 | #else |
| 49 | # ./configure --prefix=$(pwd)/bazel_install |
| 50 | #fi |
| 51 | #""" |
| 52 | # |
| 53 | # NOTE: you need to have the SSL headers installed to build with openssl support (and use HTTPS). |
| 54 | # E.g. on Ubuntu: `sudo apt install libssl-dev` |
| 55 | #http_archive( |
| 56 | # name = "python_interpreter", |
| 57 | # build_file_content = """ |
| 58 | #exports_files(["python_bin"]) |
| 59 | #filegroup( |
| 60 | # name = "files", |
| 61 | # srcs = glob(["bazel_install/**"], exclude = ["**/* *"]), |
| 62 | # visibility = ["//visibility:public"], |
| 63 | #) |
| 64 | #""", |
| 65 | # patch_cmds = [ |
| 66 | # "mkdir $(pwd)/bazel_install", |
| 67 | # _py_configure, |
| 68 | # "make", |
| 69 | # "make install", |
| 70 | # "ln -s bazel_install/bin/python3 python_bin", |
| 71 | # ], |
| 72 | # sha256 = "dfab5ec723c218082fe3d5d7ae17ecbdebffa9a1aea4d64aa3a2ecdd2e795864", |
| 73 | # strip_prefix = "Python-3.8.3", |
| 74 | # urls = ["https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz"], |
| 75 | #) |
| 76 | |
Gergely Fábián | ed2f644 | 2020-06-03 08:36:12 +0200 | [diff] [blame] | 77 | # Optional: |
| 78 | # Register the toolchain with the same python interpreter we used for pip in pip_install(). |
Dillon Giacoppo | cdc0305 | 2020-08-16 19:48:49 +1000 | [diff] [blame] | 79 | #register_toolchains("//:my_py_toolchain") |
| 80 | # End of in-build Python interpreter setup. |