Skip to content

Commit

Permalink
fix: checked-in requirements imports generated requirements
Browse files Browse the repository at this point in the history
Signed-off-by: Thulio Ferraz Assis <[email protected]>
  • Loading branch information
f0rmiga committed Feb 8, 2023
1 parent 6c8ae76 commit ee2b59a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
8 changes: 8 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,29 @@ tasks:
name: compile_pip_requirements integration tests on Ubuntu
working_directory: tests/compile_pip_requirements
platform: ubuntu2004
run_targets:
- "//:requirements.update"
integration_test_compile_pip_requirements_debian:
<<: *reusable_build_test_all
name: compile_pip_requirements integration tests on Debian
working_directory: tests/compile_pip_requirements
platform: debian11
run_targets:
- "//:requirements.update"
integration_test_compile_pip_requirements_macos:
<<: *reusable_build_test_all
name: compile_pip_requirements integration tests on macOS
working_directory: tests/compile_pip_requirements
platform: macos
run_targets:
- "//:requirements.update"
integration_test_compile_pip_requirements_windows:
<<: *reusable_build_test_all
name: compile_pip_requirements integration tests on Windows
working_directory: tests/compile_pip_requirements
platform: windows
run_targets:
- "//:requirements.update"

integration_test_pip_repository_entry_points_ubuntu:
<<: *reusable_build_test_all
Expand Down
4 changes: 4 additions & 0 deletions python/pip_install/requirements.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def compile_pip_requirements(

tags = tags or []
tags.append("requires-network")
tags.append("no-remote")
tags.append("no-sandbox")
attrs = {
"args": args,
"data": data,
Expand All @@ -113,6 +115,8 @@ def compile_pip_requirements(
"visibility": visibility,
}

deps.append(Label("//python/runfiles"))

# cheap way to detect the bazel version
_bazel_version_4_or_greater = "propeller_optimize" in dir(native)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

from piptools.scripts.compile import cli

from rules_python.python.runfiles import runfiles


def _select_golden_requirements_file(
requirements_txt, requirements_linux, requirements_darwin, requirements_windows
Expand Down Expand Up @@ -62,7 +64,9 @@ def _fix_up_requirements_in_path(absolute_prefix, output_file):
)
sys.exit(1)

parse_str_none = lambda s: None if s == "None" else s
r = runfiles.Create()

parse_str_none = lambda s: None if s == "None" else r.Rlocation(s)

requirements_in = sys.argv.pop(1)
requirements_txt = sys.argv.pop(1)
Expand Down Expand Up @@ -101,26 +105,6 @@ def _fix_up_requirements_in_path(absolute_prefix, output_file):
)
copyfile(requirements_txt, requirements_out)

elif "BUILD_WORKSPACE_DIRECTORY" in os.environ:
# This value, populated when running under `bazel run`, is a path to the
# "root of the workspace where the build was run."
# This matches up with the values passed in via the macro using the 'rootpath' Make variable,
# which for source files provides a path "relative to your workspace root."
#
# Changing to the WORKSPACE root avoids 'file not found' errors when the `.update` target is run
# from different directories within the WORKSPACE.
os.chdir(os.environ["BUILD_WORKSPACE_DIRECTORY"])
else:
err_msg = (
"Expected to find BUILD_WORKSPACE_DIRECTORY (running under `bazel run`) or "
"TEST_TMPDIR (running under `bazel test`) in environment."
)
print(
err_msg,
file=sys.stderr,
)
sys.exit(1)

update_command = os.getenv("CUSTOM_COMPILE_COMMAND") or "bazel run %s" % (
update_target_label,
)
Expand Down
3 changes: 2 additions & 1 deletion tests/compile_pip_requirements/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ EOF
compile_pip_requirements(
name = "requirements",
data = [
"requirements.in",
"requirements_extra.in",
],
extra_args = [
"--allow-unsafe",
"--resolver=backtracking",
],
requirements_in = "requirements.in",
requirements_in = "requirements.txt",
requirements_txt = "requirements_lock.txt",
)
1 change: 1 addition & 0 deletions tests/compile_pip_requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-r requirements.in

0 comments on commit ee2b59a

Please sign in to comment.