# -*- bazel -*-

load("@drake//tools/skylark:py.bzl", "py_binary")
load("@drake//tools/workspace:generate_file.bzl", "generate_file")

licenses(["notice"])  # MIT

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.
generate_file(
    name = "__init__.py",
    content = "from .pycodestyle import *",
    visibility = ["//visibility:private"],
)

py_binary(
    name = "pycodestyle",
    srcs = [
        "__init__.py",
        "pycodestyle.py",
    ],
    main = "pycodestyle.py",
    python_version = "PY3",
    srcs_version = "PY3",
)
