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

Complete working example using a package from pypi #1741

Open
weegreenblobbie opened this issue Feb 1, 2024 · 8 comments
Open

Complete working example using a package from pypi #1741

weegreenblobbie opened this issue Feb 1, 2024 · 8 comments

Comments

@weegreenblobbie
Copy link

🐞 bug report

Description

I'm trying to create a project that uses restructured text and I want to use the
rstfmt package. I can install this manually on windows but I thought I'd try to
use bazel to make this easier for future users.

I tried following the pip_parse examples but it's not complete. No python
interpreter is specified and I can't figure out how to make it work. Can we add
a complete, working example? If specific versions of bazel is required please
specify as a comment in the example.

🌍 Your Environment

Operating System:

  
Window 10
  

Output of bazel version:

  
bazel version
Bazelisk version: v1.19.0
Build label: 7.0.2
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Thu Jan 25 16:15:43 2024 (1706199343)
Build timestamp: 1706199343
Build timestamp as int: 1706199343
  

Rules_python version:

  
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "rules_python",
    integrity = "sha256-1x0sZ+C86YbhxadzG0aTImhnxFv+C3xeAGciilNvxYA=",
    strip_prefix = "rules_python-0.29.0",
    url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.29.0.tar.gz",
)
  

Anything else relevant?

I'm invoking bazel in a user mode power shell.

@jvolkman
Copy link
Contributor

jvolkman commented Feb 8, 2024

What problem are you having? The interpreter is defined here.

@weegreenblobbie
Copy link
Author

weegreenblobbie commented Apr 27, 2024 via email

@weegreenblobbie
Copy link
Author

weegreenblobbie commented Apr 27, 2024

After resetting the contents of requirements*.txt, I get a different error as documented here:

weegreenblobbie/example_rules_python@3b42abf

bazel run //tools:main
ERROR: no such package '@@pypi//requests': BUILD file not found in directory 'requests' of external repository @https://github.com/pypi. Add a BUILD file to a directory to mark it as a package.

I'm happy to update docs once I understand what I'm doing wrong.

Nick

@pat-jpnk
Copy link

pat-jpnk commented May 6, 2024

Here is a working example: https://github.com/pat-jpnk/bazel_pip_example

In your code you need to call if __name__ == "__main__" - you are calling __main__ == "__main__" on accident.

@aignas aignas closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
@weegreenblobbie
Copy link
Author

Still doesn't work: weegreenblobbie/example_rules_python@d43ac0c

Does bazel + rules_python assume the python interpreter is already installed in the the system's PATH?

@weegreenblobbie
Copy link
Author

Please reopen.

@aignas aignas reopened this May 15, 2024
@aignas
Copy link
Collaborator

aignas commented May 15, 2024

Yes, you need a system interpreter for now (#691) and you need to use something like uv pip compile (with extra flags) or the built in rule that is documented in //python:pip.bzl.

Your example from the first glance looks OK, though.

@weegreenblobbie
Copy link
Author

Using @pat-jpnk's examples I'm still failing on Windows after install python 3.11 from python.org:

I updated to python 3.11 in the WORKSPACE file:

PS C:\Users\weegr\code\bazel_pip_example> bazel run //:requirements.update
INFO: Analyzed target //:requirements.update (59 packages loaded, 4254 targets configured).
INFO: Found 1 target...
Target //:requirements.update up-to-date:
  bazel-bin/requirements.update.zip
  bazel-bin/requirements.update.exe
INFO: Elapsed time: 15.082s, Critical Path: 6.31s
INFO: 7 processes: 5 internal, 2 local.
INFO: Build completed successfully, 7 total actions
INFO: Running command line: bazel-bin/requirements.update.exe pip_example/pypi/requirements.in pip_example/pypi/requirements_lock.txt //:requirements.update '--resolver=backtracking' --allow-unsafe --generate-hashes
Updating pypi/requirements_lock.txt
WARNING: --strip-extras is becoming the default in version 8.0.0. To silence this warning, either use --strip-extras to opt into the new default or use --no-strip-extras to retain the existing behavior.
Error: Could not open file 'pypi/requirements_lock.txt': No such file or directory

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

No branches or pull requests

4 participants