-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Allow hyphen in package path #6841
Comments
Modules with hyphens in their name or package path can't be imported using the normal |
The opinion of our internal Python team seems to be that, at least for Google's monorepo, hyphens are unnatural enough in Python that we should not allow them. So the question is whether there's a compelling case for permitting them for other Bazel users, even though to use them you'd have to resort to weirdness like |
My codebase has a lot of packages with hyphenated names. These packages typically contain IDL sources from which we generate bindings for multiple languages, including Python. Under our pre-Bazel build, the Python sources would either be aggregated or output directories appended to the Python search path. As I understand it, Bazel helps with the latter via # //src/foo-idl:BUILD
emitter_rule(
name = "foo-srcs",
srcs = ["foo.idl"],
outs = [
"python/com_example_foo/__init__.py",
"python/com_example_foo/Foo.py,
]
)
py_library(
name = "foo-idl-py",
srcs = [":foo-srcs"],
imports = ["python"],
) # //src/bar:BUILD
py_binary(
name = "bar",
srcs = ["bar.py"],
deps = ["//src/foo-idl:foo-idl-py"],
) # //src/bar:bar.py
from com_example_foo import Foo
... |
We don't generally allow hyphens in Google's monorepo. This is important for ensuring that Python code can live in any package, even when the package was not necessarily originally designed with Python in mind (e.g. a C++ project that later had auto-generated Python bindings added to it). As a member of our Python team put it,
In Bazel we don't have this restriction, so (as you've discovered) users already have the problem that they can't put Python code in arbitrary packages. I don't think we're going to clamp down on prohibiting hyphens everywhere just for the sake of Python, so the opposite proposal (your PR #8010) is to relax this restriction for Bazel and make it the user's responsibility to provide |
Please see this comment for the precise wording of the proposed change. |
For a For a If there are Bazel users living in a world where they don't fully qualify their imports and rely on Python putting the dirname of the main .py file into Python's |
I'm running into problems using py_proto_library where protos were defined for other languages using hyphen packages. Is there a work around? protocolbuffers/protobuf#7061 looks like it could help solve the issue for protos. |
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 1+ 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 ( |
This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team ( |
We prohibit
-
in the package path of python code (though not in source filenames). The reasons seem historic and google-specific, so we should probably eliminate this restriction.The text was updated successfully, but these errors were encountered: