bazel-contrib / bazel-contrib/rules_python

`compile_pip_requirements` `.update` does not work with local sub modules

Offen
#2,733 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
P4 type: pip
Vorherrschende Sprache
Starlark
Sterne
688
Forks
721
Ø Merge
15 Std. 7 Min.
Gemergte PRs (30 T.)
76

Beschreibung

# 🐞 bug report

### Affected Rule

The issue is caused by the rule: compile_pip_requirements

### Is this a regression?

No

### Description

When using a nested Bazel submodule, `compile_pip_requirements` fails to find and write `requirements.txt` as the path component containing the module is stripped out.

https://github.com/bazel-contrib/rules_python/pull/1124/files#diff-92abbbd273b0a63585ad40be538589b70bf6468143f0cf37152fc89b28afc526 added most of this logic (follow the `resolved_requirements_txt` var).

## 🔬 Minimal Reproduction

https://github.com/faximan/requirements-repro (see README.md)

## 🔥 Exception or Error



bazel --bazelrc=/dev/null run @subrepo//:requirements.update
Updating requirements.txt
Traceback (most recent call last):
File "/home/faximan/.cache/bazel/_bazel_faximan/9967d5615e05634f42c83c0e87c20173/execroot/_main/bazel-out/k8-fastbuild/bin/external/subrepo+/requirements.update.runfiles/_main/../rules_python+/python/private/pypi/dependency_resolver/dependency_resolver.py", line 238, in
main()
File "/home/faximan/.cache/bazel/_bazel_faximan/9967d5615e05634f42c83c0e87c20173/execroot/_main/bazel-out/k8-fastbuild/bin/external/subrepo+/requirements.update.runfiles/rules_python++internal_deps+pypi__click/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/faximan/.cache/bazel/_bazel_faximan/9967d5615e05634f42c83c0e87c20173/execroot/_main/bazel-out/k8-fastbuild/bin/external/subrepo+/requirements.update.runfiles/rules_python++internal_deps+pypi__click/click/core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/home/faximan/.cache/bazel/_bazel_faximan/9967d5615e05634f42c83c0e87c20173/execroot/_main/bazel-out/k8-fastbuild/bin/external/subrepo+/requirements.update.runfiles/rules_python++internal_deps+pypi__click/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/faximan/.cache/bazel/_bazel_faximan/9967d5615e05634f42c83c0e87c20173/execroot/_main/bazel-out/k8-fastbuild/bin/external/subrepo+/requirements.update.runfiles/rules_python++internal_deps+pypi__click/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/faximan/.cache/bazel/_bazel_faximan/9967d5615e05634f42c83c0e87c20173/execroot/_main/bazel-out/k8-fastbuild/bin/external/subrepo+/requirements.update.runfiles/_main/../rules_python+/python/private/pypi/dependency_resolver/dependency_resolver.py", line 176, in main
os.makedirs(os.path.dirname(requirements_file_relative), exist_ok=True)
File "", line 225, in makedirs
FileNotFoundError: [Errno 2] No such file or directory: ''

## 🌍 Your Environment

**Operating System:**

  

Linux

**Output of `bazel version`:**

  

8.1.1

**Rules_python version:**

  

1.3.0

**Anything else relevant?**
https://github.com/faximan/rules_python/pull/1 fixes the issue for me, but probably in the wrong way. I don't think writing directly to the runfiles tree is necessarily the right thing to do? It also currently leaves behind some `.__atomic-write` files.

Since I am not familiar with this codebase, behavior on Windows etc. I'm looking for someone else to take this over and propose a PR.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start with the compile_pip_requirements rule and the resolved_requirements_txt logic referenced in the issue, then inspect dependency_resolver.py around the requirements_file_relative handling. Reproduce the failure with the linked requirements-repro README.md and the requirements.update target. Done means a nested Bazel submodule can update requirements.txt without the empty-path error, while behavior for Windows and leftover .__atomic-write files is considered.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
build-system
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.