TriggerMail / rules_pyz

Bazel Python rules that package everything in an executable zip
Apache License 2.0
29 stars 19 forks source link

difference between pyz_binary and pyz_image #35

Open Globegitter opened 5 years ago

Globegitter commented 5 years ago

I was trying to get a legacy app working with these rules (I have not written it myself, it uses Django's manage.py) and to get things working I had to add pythonroot="." to my python libraries (otherwise libraries could not be imported). But now running the app in docker via the pyz3_image complained that it could not import a library, specifically the DJANGO_SETTINGS_MODULE. Now I additionally added this library without the pythonroot settings and now it works.

I am sorry I can not give more details at this stage I thought I would just report it and if I have more time to investigate I can add more here. I am wondering though if there is a slight difference in the directory layout, or maybe where the process is being executed compared to the runfiles dir locally?

evanj commented 5 years ago

Hrm... Interesting. Just to make sure I understand: the local pyz_image with this application did run, but running it via pyz3_image did not? If you can reproduce the error, could you attach the file list that is generated here? You should be able to run tar tvf bazel-genfiles/(package path)/(binary name).tar If you could include that file list here, it would help me understand the bug.

In general: this probably means it is either setting PYTHONPATH incorrectly, or it has packaged the files in the wrong locations.

ewhauser commented 5 years ago

I ran into the same problem with pyz3_image with this rule setup:

pyz_library(
    name = "lib",
    srcs = [
        "example.py"
    ],
    deps = [
        "//third_party/pypi:github3.py",
    ],
)

pyz_binary(
    name = "main",
    srcs = [
        "main.py",
    ],
    deps = [
        ":buildlib",
    ],
)

pyz3_image(
    name = "main_image",
    binary = ":main",
)

Adding pythonroot="." to the pyz_library solved my problem as well.

evanj commented 5 years ago

Ah thanks for this bug report. I think I might know what is going wrong here. For clarity, @ewhauser were these rules in the root of your WORKSPACE or at some other directory level? Thanks!

ewhauser commented 5 years ago

Mine were in a subdirectory. I had a lot of problems with the PYTHONPATH using pyz3_image. The particular app I was using this with worked w/Python 2 as well, so I switched to pyz2_image which did not have the same problem.

evanj commented 5 years ago

Hrm weird, thanks. I'll see if I can manage to reproduce this somehow ... If you see it again, a standalone git repository that demonstrates the issue means I can definitely figure out how to fix it :)