Skip to content

Python 3 support for external libraries  #3010

@MarkIennaco

Description

@MarkIennaco

I have a copy of matplotlib compiled for PY3 declared as an external library for my repo.
(the url is local for testing purposes)

new_http_archive(
  name = 'python_matplotlib_repo',
  build_file = 'debian/python_matplotlib.BUILD',
  sha256 = '519bb90fe31b6de9fa3748a9f3aa3167f66c2cd6afb62c50f7b08d8e77a6cda6',
  url = 'http://miennaco-debian/matplotlib-2.0.0-1-cp34-cp34m-manylinux1_x86_64.whl',
  type = 'zip',
)

The contents of the BUILD file is:

py_library(
    name = 'matplotlib',
    visibility = ['//visibility:public'],
    srcs = glob(['matplotlib/**/*.py']),
    data = [
        ':matplotlib_data',
    ],
    deps = [
        '@python_cycler_repo//:cycler',
        '@python_pyparsing_repo//:pyparsing',
    ],
    srcs_version = 'PY3',
)

filegroup(
    name = 'matplotlib_data',
    srcs = glob([
        'matplotlib/mpl-data/**/*',
        'matplotlib/**/*.so',
        'matplotlib/.libs/*',
    ]),
)

When I try to build a target that depends on the library:

 bazel test vehicle/logging/analysis:timing_report_plotter_testERROR: /home/miennaco/.cache/bazel/_bazel_miennaco/af311f486463d9a61a3fdd9b3eb0bcd4/external/python_matplotlib_repo/BUILD.bazel:1:1: in py_library rule @python_matplotlib_repo//:matplotlib: Rule '@python_matplotlib_repo//:matplotlib' need to be converted to Python 2 (not yet implemented).
ERROR: Analysis of target '//vehicle/logging/analysis:timing_report_plotter_test' failed; build aborted.
INFO: Elapsed time: 0.450s
ERROR: Couldn't start the build. Unable to run tests.

The target in question has:

  srcs_version = 'PY3',
  default_python_version = 'PY3',

But bazel insists on building the library with python 2.

Adding --force_python PY3 to the build allows this target to built (but breaks all the python 2 projects in the repository)

Environment info

Metadata

Metadata

Assignees

Labels

P3We're not considering working on this, but happy to review a PR. (No assignee)team-Rules-PythonNative rules for Pythontype: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions