Skip to content

[FR]: Rename hyphens to underscores #688

@gabrielrussoc

Description

@gabrielrussoc

What is the current behavior?

If you have a package like

my-package/lib.py

and you wrap it like

py_library(
  name = "lib",
  srcs = ["my-package/lib.py"],
)

You can't import it as my-package.lib because - is not allowed by Python. This is not necessarily a rules_py limitation, it's just how Python works.

Describe the feature

At Databricks we have been using some homegrown Python rules for years and a long time ago we have implemented logic to map - to _. This essentially resulted in a lot of Python code ending up inside directories that contain hyphens.

Now that we are trying to use aspect_rules_py, we hit issues where we can't import our code anymore (at least not without hacks) due to hyphens. Renaming is of course an option, but for a large existing codebase, it's proving to be a lot harder than I expected.

Would you be willing to support some opt-in feature to rename such packages? We can discuss the API, perhaps some target-level option like:

py_library(
  name = "lib",
  rename_hyphens = True,
)

I'm happy to contribute, the main motivation here is to understand whether this would be accepted and if yes, what the API should look like

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions