Skip to content

Commit

Permalink
Add Python2 PEX support
Browse files Browse the repository at this point in the history
Python3 to follow next.
  • Loading branch information
borancar committed Dec 2, 2021
1 parent d9d4131 commit 928cd7b
Show file tree
Hide file tree
Showing 5 changed files with 497 additions and 0 deletions.
17 changes: 17 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,20 @@ http_archive(
)
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()

http_archive(
name = "io_bazel_rules_pex",
strip_prefix = "bazel_rules_pex-0.3.0",
urls = [
"https://github.com/benley/bazel_rules_pex/archive/refs/tags/0.3.0.tar.gz",
],
sha256 = "25b203ed474f1e8d4060a00dee1bcefb9ec487c817b868a315ccbe8ca3b08a9f",
patch_args = [
"-p1",
],
patches = [
"//third_party:pex.patch",
],
)
load("@io_bazel_rules_pex//pex:pex_rules.bzl", "pex_repositories")
pex_repositories()
12 changes: 12 additions & 0 deletions python_pdm_example/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@io_bazel_rules_pex//pex:pex_rules.bzl", "pex_binary", "pex_library", "pex_test", "pex_pytest")

pex_binary(
name = "app",
srcs = [
"app.py",
"__init__.py",
],
reqs = [
"flask",
],
)
13 changes: 13 additions & 0 deletions python_pdm_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,16 @@ fi

When inside the directory, just run `pdm install` and you're ready to run the
app with `python app.py`.

## Bazel PEX Python2

If you want to build a Python2 pex file, run:

```
bazel build //python_pdm_example:app --host_force_python=PY2
```

You can run the resulting file as:
```
bazel-bin/python_pdm_example/app
```
Empty file added python_pdm_example/__init__.py
Empty file.
Loading

0 comments on commit 928cd7b

Please sign in to comment.