8000 fix: checked-in requirements imports generated requirements · bazel-contrib/rules_python@699e3d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 699e3d1

Browse files
committed
fix: checked-in requirements imports generated requirements
Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
1 parent 6c8ae76 commit 699e3d1

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

.bazelci/presubmit.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,21 +237,29 @@ tasks:
237237
name: compile_pip_requirements integration tests on Ubuntu
238238
working_directory: tests/compile_pip_requirements
239239
platform: ubuntu2004
240+
run_targets:
241+
- "bazel run //:requirements.update"
240242
integration_test_compile_pip_requirements_debian:
241243
<<: *reusable_build_test_all
242244
name: compile_pip_requirements integration tests on Debian
243245
working_directory: tests/compile_pip_requirements
244246
platform: debian11
247+
run_targets:
248+
- "bazel run //:requirements.update"
245249
integration_test_compile_pip_requirements_macos:
246250
<<: *reusable_build_test_all
247251
name: compile_pip_requirements integration tests on macOS
248252
working_directory: tests/compile_pip_requirements
249253
platform: macos
254+
run_targets:
255+
- "bazel run //:requirements.update"
250256
integration_test_compile_pip_requirements_windows:
251257
<<: *reusable_build_test_all
252258
name: compile_pip_requirements integration tests on Windows
253259
working_directory: tests/compile_pip_requirements
254260
platform: windows
261+
run_targets:
262+
- "bazel run //:requirements.update"
255263

256264
integration_test_pip_repository_entry_points_ubuntu:
257265
<<: *reusable_build_test_all

python/pip_install/requirements.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def compile_pip_requirements(
103103

104104
tags = tags or []
105105
tags.append("requires-network")
106+
tags.append("no-remote")
107+
tags.append("no-sandbox")
106108
attrs = {
107109
"args": args,
108110
"data": data,
@@ -113,6 +115,8 @@ def compile_pip_requirements(
113115
"visibility": visibility,
114116
}
115117

118+
deps.append(Label("//python/runfiles"))
119+
116120
# cheap way to detect the bazel version
117121
_bazel_version_4_or_greater = "propeller_optimize" in dir(native)
118122

python/pip_install/tools/dependency_resolver/dependency_resolver.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
from piptools.scripts.compile import cli
2424

25+
from rules_python.python.runfiles import runfiles
26+
2527

2628
def _select_golden_requirements_file(
2729
requirements_txt, requirements_linux, requirements_darwin, requirements_windows
@@ -62,7 +64,9 @@ def _fix_up_requirements_in_path(absolute_prefix, output_file):
6264
)
6365
sys.exit(1)
6466

65-
parse_str_none = lambda s: None if s == "None" else s
67+
r = runfiles.Create()
68+
69+
parse_str_none = lambda s: None if s == "None" else r.Rlocation(s)
6670

6771
requirements_in = sys.argv.pop(1)
6872
requirements_txt = sys.argv.pop(1)
@@ -101,26 +105,6 @@ def _fix_up_requirements_in_path(absolute_prefix, output_file):
101105
)
102106
copyfile(requirements_txt, requirements_out)
103107

104-
elif "BUILD_WORKSPACE_DIRECTORY" in os.environ:
105-
# This value, populated when running under `bazel run`, is a path to the
106-
# "root of the workspace where the build was run."
107-
# This matches up with the values passed in via the macro using the 'rootpath' Make variable,
108-
# which for source files provides a path "relative to your workspace root."
109-
#
110-
# Changing to the WORKSPACE root avoids 'file not found' errors when the `.update` target is run
111-
# from different directories within the WORKSPACE.
112-
os.chdir(os.environ["BUILD_WORKSPACE_DIRECTORY"])
113-
else:
114-
err_msg = (
115-
"Expected to find BUILD_WORKSPACE_DIRECTORY (running under `bazel run`) or "
116-
"TEST_TMPDIR (running under `bazel test`) in environment."
117-
)
118-
print(
119-
err_msg,
120-
file=sys.stderr,
121-
)
122-
sys.exit(1)
123-
124108
update_command = os.getenv("CUSTOM_COMPILE_COMMAND") or "bazel run %s" % (
125109
update_target_label,
126110
)

tests/compile_pip_requirements/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ EOF
2222
compile_pip_requirements(
2323
name = "requirements",
2424
data = [
25+
"requirements.in",
2526
"requirements_extra.in",
2627
],
2728
extra_args = [
2829
"--allow-unsafe",
2930
"--resolver=backtracking",
3031
],
31-
requirements_in = "requirements.in",
32+
requirements_in = "requirements.txt",
3233
requirements_txt = "requirements_lock.txt",
3334
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-r requirements.in

0 commit comments

Comments
 (0)
0