Skip to content
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

[FR]: Ability to add to PYTHONPATH globally. #476

Open
keunhong opened this issue Dec 12, 2024 · 1 comment
Open

[FR]: Ability to add to PYTHONPATH globally. #476

keunhong opened this issue Dec 12, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@keunhong
Copy link

What is the current behavior?

We have an src directory which contains all of our main python packages. It doesn't seem like there is a good way to add src globally to the PYTHONPATH in order to import src/company as from company import module.

Describe the feature

I would like some mechanism to add src to the PYTHONPATH. I tried to set the imports attribute in py_binary etc., but this seems to only support relative paths.

@keunhong keunhong added the enhancement New feature or request label Dec 12, 2024
@keunhong
Copy link
Author

Looks like this may work as a workaround.

Implement a wrapper py_rules.bzl

load("@aspect_rules_py//py:defs.bzl", base_py_binary = "py_binary", base_py_library = "py_library", base_py_test = "py_test")

def py_binary(name, srcs, deps, **kwargs):
    base_py_binary(
        name = name,
        srcs = srcs,
        deps = deps + ["//src"],
        **kwargs
    )

def py_library(name, srcs, deps, **kwargs):
    base_py_library(
        name = name,
        srcs = srcs,
        deps = deps + ["//src"],
        **kwargs
    )

def py_test(name, srcs, deps, **kwargs):
    base_py_test(
        name = name,
        srcs = srcs,
        deps = deps + ["//src"],
        **kwargs
    )

and then define a rule in the root

load("@aspect_rules_py//py:defs.bzl", "py_library")

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

py_library(
    name = "src",
    imports = ["."],
)

and then use the wrapper everywhere in the repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant