rules_pycross icon indicating copy to clipboard operation
rules_pycross copied to clipboard

requirement helper function has incorrect workspace name?

Open njlr opened this issue 1 year ago • 0 comments

This works for me:

# ...
  deps = [
    "@poetry_lock_repo//deps:pytest",
  ],
)

But this does not:

load("@poetry_lock_repo//:requirements.bzl", "requirement")

# ...

  deps = [
    requirement("pytest"),
  ],
)

If I do the following:

print(requirement("pytest"))

I get:

@rules_pycross~~lock_file~poetry_lock_repo//deps:pytest

This doesn't match "@poetry_lock_repo//deps:pytest".

Is there a bug in the requirement helper function?

requirements.bzl

load("@@//tools/bazel/poetry:poetry_lock.bzl", "PINS", "repositories")

def requirement(pkg):
    # Convert given name into normalized package name.
    # https://packaging.python.org/en/latest/specifications/name-normalization/#name-normalization
    pkg = pkg.replace("_", "-").replace(".", "-").lower()
    for i in range(len(pkg)):
        if "--" in pkg:
            pkg = pkg.replace("--", "-")
        else:
            break
    return "@rules_pycross~~lock_file~poetry_lock_repo//deps:%s" % pkg

all_requirements = ["@rules_pycross~~lock_file~poetry_lock_repo//deps:%s" % v for v in PINS.values()]

install_deps = repositories

njlr avatar Dec 16 '24 15:12 njlr