Skip to content

fix(gazelle): Fix the requirements arg to the gazelle python manifest generator.#2533

Merged
dougthor42 merged 4 commits intobazel-contrib:mainfrom
sputt:gazelle-python-manifest-fix
Jan 10, 2025
Merged

fix(gazelle): Fix the requirements arg to the gazelle python manifest generator.#2533
dougthor42 merged 4 commits intobazel-contrib:mainfrom
sputt:gazelle-python-manifest-fix

Conversation

@sputt
Copy link
Copy Markdown
Contributor

@sputt sputt commented Dec 24, 2024

Fix args passed into the gazelle manifest file generator if the requirements file is not a source file.

@sputt
Copy link
Copy Markdown
Contributor Author

sputt commented Dec 24, 2024

Before

SUBCOMMAND: # //private/tools:gazelle_python_manifest.genrule [action 'Executing genrule //private/tools:gazelle_python_manifest.genrule', configuration: c44a261b7e8f814b4f77f0e2cc503ebef701b283942d7e8ff5ae6f26c41513da, execution platform: @@platforms//host:host, mnemonic: Genrule]
(cd /private/var/tmp/_bazel_sputt/3b16e11ed38a9a587395e3bd748a9a16/execroot/_main && \
  exec env - \
    PATH=/Users/sputt/Library/Caches/bazelisk/downloads/sha256/02b117b97d0921ae4d4f4e11d27e2c0930381df416e373435d5d0419c6a26f24/bin:/Users/sputt/.vscode/extensions/ms-python.python-2024.22.0-darwin-arm64/python_files/deactivate/zsh:/Users/sputt/req-compile/venv/bin:/Library/Frameworks/Python.framework/Versions/3.12/bin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/sputt/.vscode/extensions/ms-python.python-2024.22.0-darwin-arm64/python_files/deactivate/zsh:/Users/sputt/req-compile/venv/bin:/Library/Frameworks/Python.framework/Versions/3.12/bin:/Library/Frameworks/Python.framework/Versions/3.11/bin \
  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_python_gazelle_plugin~/manifest/generate/generate_/generate --manifest-generator-hash=bazel-out/darwin_arm64-fastbuild/bin/external/rules_python_gazelle_plugin~/manifest/generate/generate_lib_sources_hash.hash --requirements=private/tools/gazelle_python_manifest_requirements.txt --pip-repository-name=req_compile_deps --modules-mapping=bazel-out/darwin_arm64-fastbuild/bin/private/tools/modules_mapping.json --output=bazel-out/darwin_arm64-fastbuild/bin/private/tools/gazelle_python_manifest.generated_manifest --update-target=//private/tools:gazelle_python_manifest.update')
# Configuration: c44a261b7e8f814b4f77f0e2cc503ebef701b283942d7e8ff5ae6f26c41513da
# Execution platform: @@platforms//host:host
ERROR: /Users/sputt/req-compile/private/tools/BUILD.bazel:16:24: Executing genrule //private/tools:gazelle_python_manifest.genrule failed: (Exit 1): bash failed: error executing Genrule command (from target //private/tools:gazelle_python_manifest.genrule) /bin/bash -c ... (remaining 1 argument skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
2024/12/24 11:07:24 ERROR: failed to write output: open private/tools/gazelle_python_manifest_requirements.txt: no such file or directory
Target //private/tools:gazelle_python_manifest.update failed to build
--requirements=private/tools/gazelle_python_manifest_requirements.txt

After

SUBCOMMAND: # //private/tools:gazelle_python_manifest.genrule [action 'Executing genrule //private/tools:gazelle_python_manifest.genrule', configuration: c44a261b7e8f814b4f77f0e2cc503ebef701b283942d7e8ff5ae6f26c41513da, execution platform: @@platforms//host:host, mnemonic: Genrule]
(cd /private/var/tmp/_bazel_sputt/3b16e11ed38a9a587395e3bd748a9a16/execroot/_main && \
  exec env - \
    PATH=/Users/sputt/Library/Caches/bazelisk/downloads/sha256/02b117b97d0921ae4d4f4e11d27e2c0930381df416e373435d5d0419c6a26f24/bin:/Users/sputt/.vscode/extensions/ms-python.python-2024.22.0-darwin-arm64/python_files/deactivate/zsh:/Users/sputt/req-compile/venv/bin:/Library/Frameworks/Python.framework/Versions/3.12/bin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/sputt/.vscode/extensions/ms-python.python-2024.22.0-darwin-arm64/python_files/deactivate/zsh:/Users/sputt/req-compile/venv/bin:/Library/Frameworks/Python.framework/Versions/3.12/bin:/Library/Frameworks/Python.framework/Versions/3.11/bin \
  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_python_gazelle_plugin~/manifest/generate/generate_/generate --manifest-generator-hash=bazel-out/darwin_arm64-fastbuild/bin/external/rules_python_gazelle_plugin~/manifest/generate/generate_lib_sources_hash.hash --requirements=bazel-out/darwin_arm64-fastbuild/bin/private/tools/gazelle_python_manifest_requirements.txt --pip-repository-name=req_compile_deps --modules-mapping=bazel-out/darwin_arm64-fastbuild/bin/private/tools/modules_mapping.json --output=bazel-out/darwin_arm64-fastbuild/bin/private/tools/gazelle_python_manifest.generated_manifest --update-target=//private/tools:gazelle_python_manifest.update')
# Configuration: c44a261b7e8f814b4f77f0e2cc503ebef701b283942d7e8ff5ae6f26c41513da
# Execution platform: @@platforms//host:host
--requirements=bazel-out/darwin_arm64-fastbuild/bin/private/tools/gazelle_python_manifest_requirements.txt

Copy link
Copy Markdown
Collaborator

@dougthor42 dougthor42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to provide a test case that gets fixed by this change?

I tested things locally and didn't see any glaring issues, but am also not entirely sure how to reproduce the issue.

@sputt
Copy link
Copy Markdown
Contributor Author

sputt commented Dec 27, 2024

Yes you must only provide a generated file as the requirements.txt, or have the macro produce one with the genrule, to produce the issue. rootpath is not correct as an arg to an action input, but happens to work when the file is a source file.

Here is the example from the req-compile project:

gazelle_python_manifest(
    name = "gazelle_python_manifest",
    modules_mapping = ":modules_map",
    pip_repository_name = "req_compile_deps",
    requirements = [
        "//3rdparty:requirements.linux.txt",
        "//private/tests/annotations:requirements.linux.txt",
        "//private/tests/platlib:requirements.linux.txt",
    ],
)

https://github.com/periareon/req-compile/blob/3ef72ef1849caf2412f4bb4f0a6dadbb17f5fbcc/private/tools/BUILD.bazel#L23

Copy link
Copy Markdown
Collaborator

@dougthor42 dougthor42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Holidays and all...

Anyway, I was able to reproduce the issue locally and verify the fix, thanks for the how-to. I'm not able to figure out an easy way to add a test for it, but oh well.

Please add an entry to the changelog and I'll give the LGTM.

@dougthor42 dougthor42 changed the title fix: Fix the requirements arg to the gazelle python manifest generator. fix(gazelle): Fix the requirements arg to the gazelle python manifest generator. Jan 4, 2025
@sputt sputt requested a review from rickeylev as a code owner January 10, 2025 05:51
Copy link
Copy Markdown
Collaborator

@dougthor42 dougthor42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sputt
Copy link
Copy Markdown
Contributor Author

sputt commented Jan 10, 2025

Thanks for the approval, a maintainer will need to merge

@dougthor42 dougthor42 added this pull request to the merge queue Jan 10, 2025
Merged via the queue into bazel-contrib:main with commit eae0985 Jan 10, 2025
@sputt sputt deleted the gazelle-python-manifest-fix branch January 16, 2025 03:17
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 this pull request may close these issues.

2 participants