Skip to content

Commit

Permalink
Fix PYTHONPATH issues under Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanHowell committed Oct 11, 2019
1 parent a3e5104 commit dee369b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 8 deletions.
41 changes: 38 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,36 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_python",
strip_prefix = "rules_python-54d1cb35cd54318d59bf38e52df3e628c07d4bbc",
urls = ["https://github.com/bazelbuild/rules_python/archive/54d1cb35cd54318d59bf38e52df3e628c07d4bbc.tar.gz"],
sha256 = "43c007823228f88d6afe1580d00f349564c97e103309a234fa20a5a10a9ff85b",
sha256 = "e220053c4454664c09628ffbb33f245e65f5fe92eb285fbd0bc3a26f173f99d0",
strip_prefix = "rules_python-5aa465d5d91f1d9d90cac10624e3d2faf2057bd5",
urls = ["https://github.com/bazelbuild/rules_python/archive/5aa465d5d91f1d9d90cac10624e3d2faf2057bd5.tar.gz"],
)

# This call should always be present.
load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

# Docker rules for testing

http_archive(
name = "io_bazel_rules_docker",
sha256 = "413bb1ec0895a8d3249a01edf24b82fd06af3c8633c9fb833a0cb1d4b234d46d",
strip_prefix = "rules_docker-0.12.0",
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.12.0/rules_docker-v0.12.0.tar.gz"],
)

load(
"@io_bazel_rules_docker//repositories:repositories.bzl",
_container_repositories = "repositories",
)

_container_repositories()

load("@io_bazel_rules_docker//repositories:deps.bzl", _container_deps = "deps")

_container_deps()

# Split remarshal out, most consumers will not need it
local_repository(
name = "remarshal",
Expand All @@ -29,3 +50,17 @@ poetry(
lockfile = "//test:poetry.lock",
pyproject = "//test:pyproject.toml",
)

# Base image for Docker tests
load(
"@io_bazel_rules_docker//container:container.bzl",
"container_pull",
)

container_pull(
name = "python_debian",
digest = "sha256:fc754aafacf5ad737f1e313cbd3f7cfedf08cbc713927a9e27683b7210a0aabd",
registry = "index.docker.io",
repository = "library/python",
tag = "3.7.4-slim-buster",
)
3 changes: 2 additions & 1 deletion rules_poetry/poetry.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ pip_install(
py_library(
name = "{name}_library",
srcs = [],
srcs = glob(["{pkg}/**/*.py"]),
data = glob(["{pkg}/**/*"], exclude=["**/*.py", "**/* *", "BUILD", "WORKSPACE"]),
imports = ["{pkg}"],
deps = {dependencies},
visibility = ["//visibility:public"],
Expand Down
19 changes: 18 additions & 1 deletion test/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_python//python:defs.bzl", "py_test")
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
load("@io_bazel_rules_docker//lang:image.bzl", "app_layer")
load("@test_poetry//:dependencies.bzl", "dependency")

py_test(
Expand All @@ -21,3 +22,19 @@ py_test(
],
)

py_binary(
name = "timezone",
srcs = ["timezone.py"],
python_version = "PY3",
deps = [
dependency("pytz"),
],
)

# can't use the py3_image rule until I figure out how to register a CC toolchain that works in Docker
app_layer(
name = "timezone.image",
base = "@python_debian//image",
binary = ":timezone",
tags = ["manual"],
)
6 changes: 3 additions & 3 deletions test/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license = "MIT"
python = "^3.7"
numpy = "^1.17"
pandas = "^0.25.1"
pytz = "^2019.3"

[tool.poetry.dev-dependencies]
coverage = "^4.5"
Expand Down
3 changes: 3 additions & 0 deletions test/timezone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pytz

print(pytz.utc)

0 comments on commit dee369b

Please sign in to comment.