# -*- python -*-

load("@drake//tools:drake.bzl", "drake_generate_file")

package(default_visibility = ["//visibility:public"])

# Downstream users of python modules expect to say 'import pycodestyle'.
# However, the sandbox looks like::
#
#   <LABEL>.runfiles/
#     pycodestyle/
#       __init__.py # Generated by Bazel; empty
#       pycodestyle.py
#
# Because <LABEL>.runfiles is earlier in the $PYTHONPATH, users wind up
# importing an empty module. Adding 'imports' (either here, or to users) does
# not seem to help.
#
# Instead, we repair this situation by creating a custom __init__.py that
# overrides the Bazel empty default and imports the contents of the "real"
# module.
drake_generate_file(
    name = "init_genrule",
    out = "__init__.py",
    content = "from .pycodestyle import *",
    visibility = ["//visibility:private"],
)

py_binary(
    name = "pycodestyle",
    srcs = [
        "pycodestyle.py",
        ":init_genrule",
    ],
    main = "pycodestyle.py",
    srcs_version = "PY2AND3",
)
