Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel should put external repos after stdlib on PYTHONPATH #5899

Closed
rickeylev opened this issue Aug 15, 2018 · 4 comments
Closed

Bazel should put external repos after stdlib on PYTHONPATH #5899

rickeylev opened this issue Aug 15, 2018 · 4 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-Python Native rules for Python type: bug

Comments

@rickeylev
Copy link
Contributor

Description of the problem / feature request:

Bazel prepends external dependencies to PYTHONPATH before the stdlib.
This makes external dep modules hide stdlib modules, which is generally a bad thing.

As an example, consider trying to use the enum module with code that is Python 2 and Python 3 compatible. The enum34 package provides the enum module in py2. However, its only a subset of later Python 3 enum features; i.e., its not a drop-in replacement for enum in Python 3.4+

So you create a new_http_archive rule and get the "enum" directory onto sys.path, which now looks something like:
['/some-bazel-path/enum34_archive', 'python3.6/stdlib.zip", "python3.6/site-packages']

Now if you import enum, it'll take the enum module from the enum34_archive entry, which breaks all sorts of things.

Instead, it should really be putting the repos after the stdlib, probably where site-packages would normally go.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

The simplest way is to run a Python 3 binary that depends on the enum34 package.

# WORKSPACE
new_http_archive(
    name = "enum34_archive",
    urls = [
"https://pypi.python.org/packages/bf/3e/31d502c25302814a7c2f1d3959d2a3b3f78e509002ba91aea64993936876/enum34-1.1.6.tar.gz"
        ],
    sha256 = "8ad8c4783bf61ded74527bffb48ed9b54166685e4230386a9ed9b1279e2df5b1",
    strip_prefix="enum34-1.1.6",
    build_file = "enum34.BUILD"
)

# enum34.BUILD:
py_library(
    name = "enum",
    srcs = ["enum/__init__.py"],
    srcs_version = "PY2AND3",
    visibility = ["//visibility:public"],
)

py_binary(
  name = "foo"
  srcs = ["foo.py"]
  deps = ["@enum_archive//:enum"]
)

Then import various stdlib modules in foo.py.

Then run bazel with python3 (I was using 3.6)

bazel build --python_path=/usr/bin/python3.6 :foo
bazel-bin/foo

And it should fail out in some stdlib modules that rely on enum

What operating system are you running Bazel on?

Linux

What's the output of bazel info release?

release 0.16.1

Have you found anything relevant by searching the web?

#2867, while not about this bug, includes some PYTHONPATH output that shows that bazel is putting paths before the stdlib.

@aiuto aiuto added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged labels Aug 15, 2018
@dslomov dslomov added team-Rules-Server Issues for serverside rules included with Bazel type: bug and removed team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. labels Sep 10, 2018
@dslomov
Copy link
Contributor

dslomov commented Sep 10, 2018

@brandjon

@brandjon
Copy link
Member

brandjon commented Apr 5, 2019

See #7959 for related sys.path issues.

@github-actions
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 3 years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Feb 28, 2023
@github-actions
Copy link

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team (@bazelbuild/triage). Thanks!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-Python Native rules for Python type: bug
Projects
None yet
Development

No branches or pull requests

4 participants