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

example/build_file_generation/ is broken #1160

Closed
ofey404 opened this issue Apr 10, 2023 · 3 comments · Fixed by #1164
Closed

example/build_file_generation/ is broken #1160

ofey404 opened this issue Apr 10, 2023 · 3 comments · Fixed by #1164

Comments

@ofey404
Copy link
Contributor

ofey404 commented Apr 10, 2023

🐞 bug report

Affected Rule

I'm new to rule_python, but the example cannot run.

https://github.com/bazelbuild/rules_python/tree/main/examples/build_file_generation

Is this a regression?

No.

Description

The example/build_file_generation/ can not run.

🔬 Minimal Reproduction

I save the spot in this commit of my fork:

ofey404@7a10e85

image

I use bazelisk with USE_BAZEL_VERSION=5.4.0.

I follow the instruction in README.md of example:

Or, try importing the `requests` library in `__init__.py`.
You'll see that `deps = ["@pip//pypi__requests"]` is automatically
added to the `py_library` target in the `BUILD` file.

But requests package is not found.

bazel run //:gazelle
INFO: Analyzed target //:gazelle (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:gazelle up-to-date:
  bazel-bin/gazelle-runner.bash
  bazel-bin/gazelle
INFO: Elapsed time: 0.297s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
gazelle: ERROR: failed to validate dependencies for target "@build_file_generation_example//:build_file_generation": "requests" at line 15 from "__init__.py" is an invalid dependency: possible solutions:
        1. Add it as a dependency in the requirements.txt file.
        2. Instruct Gazelle to resolve to a known dependency using the gazelle:resolve directive.
        3. Ignore it with a comment '# gazelle:ignore requests' in the Python file.

🔥 Exception or Error

At least the example should work, so that newcomers could learn how to use it.

🌍 Your Environment

Operating System:

cat /etc/os-release 
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

Output of bazel version:

bazel version
Bazelisk version: v1.13.2
Build label: 5.4.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Dec 15 16:14:25 2022 (1671120865)
Build timestamp: 1671120865
Build timestamp as int: 1671120865

Rules_python version:

latest.

git log HEAD
commit 7a10e85844bf8acdc9f24220a2d529975a9f5ca7 (HEAD -> main, ofey404/main)
Author: Ofey Chan <[email protected]>
Date:   Mon Apr 10 17:32:20 2023 +0800

    stage: reproduce error on example

commit b80b8fde601f3bee9a4174c4aef03a3811912b93 (origin/main, origin/HEAD)
Author: Mathieu Sabourin <[email protected]>
Date:   Fri Apr 7 23:52:41 2023 -0700

    fix: respect kind mapping (#1158)

Anything else relevant?

Nope

@chrislovecnm
Copy link
Collaborator

chrislovecnm commented Apr 10, 2023

We need to fix the documentation:

  1. add "requests" to the requirements file.
  2. run bazel run //:requirements.update
  3. run bazel run //:gazelle_python_manifest.update
  4. lastly bazel run //:gazelle

So to my knowledge, gazelle does not add anything to the "requirements" file. Then you have to update the "requirements.in" file, which is done with step number two. Next, you must update the gazelle_python.yaml file via step three. Then pip and gazelle are updated so that gazelle can update the BUILD file(s).

I am the above commands on the main branch with bazelisk and it is working locally.

@ofey404
Copy link
Contributor Author

ofey404 commented Apr 11, 2023

We need to fix the documentation

Thank you! It helps a lot.

I'd like to fix the README tonight.

@ofey404
Copy link
Contributor Author

ofey404 commented Apr 11, 2023

Besides, does rules_python support multiple requirements.txt in the same WORKSPACE?

I plan to use it in a python monorepo.

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

Successfully merging a pull request may close this issue.

2 participants