Skip to content

Commit

Permalink
Allow overridden requirements parses to use unannotated requirements …
Browse files Browse the repository at this point in the history
…files. (#92)
  • Loading branch information
sputt authored Sep 30, 2024
1 parent 3c09c38 commit 0f234b1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4,344 deletions.
6 changes: 4 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ build --test_output=errors
coverage --combined_report=lcov

# Stream BES reports to BuildBuddy.
common:bes --bes_results_url=https://req-compile.buildbuddy.io/invocation/
common:bes --bes_backend=grpcs://req-compile.buildbuddy.io
# common:bes --bes_results_url=https://req-compile.buildbuddy.io/invocation/
# common:bes --bes_backend=grpcs://req-compile.buildbuddy.io
# Disable BES while we troubleshoot the API key.
common:bes --bes_backend=

# BuildBuddy suggested flags.
common --noslim_profile --experimental_profile_include_target_label --experimental_profile_include_primary_output
Expand Down
2,390 changes: 0 additions & 2,390 deletions private/examples/multiplatform_py_test/MODULE.bazel.lock

Large diffs are not rendered by default.

99 changes: 53 additions & 46 deletions private/reqs_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -177,62 +177,67 @@ def parse_constraint(data, repository_name, lockfile, wheel_dirs):
"""
url = None
whl = None
if len(data) < 3:
fail("The data given did not match the minimum expected length in {}:\n{}".format(
repository_name,
"\n".join(data),
))
via = None

if "==" not in data[0]:
fail("Unexpected line in constraints file: {}".format(data))

package, _, version = data[0].partition("==")
version = version.strip(" \\")

if not data[1].startswith("--hash=sha256:"):
fail("Unexpected data found where a sha256 hash value was expected for {}:\n{}".format(
package,
data[1],
))
sha256 = data[1][len("--hash=sha256:"):]

via = []
for entry in data[2:-1]:
text = entry.replace("# via", "#")
pkg, _, _ = text.strip(" #").partition(" ")
pkg, _, _ = pkg.partition("[")
if not pkg:
continue
if len(data) > 1:
if not data[1].startswith("--hash=sha256:"):
fail("Unexpected data found where a sha256 hash value was expected for {}:\n{}".format(
package,
data[1],
))
sha256 = data[1][len("--hash=sha256:"):]
else:
sha256 = ""

if len(data) > 2:
via = []
for entry in data[2:-1]:
text = entry.replace("# via", "#")
pkg, _, _ = text.strip(" #").partition(" ")
pkg, _, _ = pkg.partition("[")
if not pkg:
continue

# Skip any file paths. We only care to track packages
if "/" in pkg or "\\" in pkg:
continue
# Skip any file paths. We only care to track packages
if "/" in pkg or "\\" in pkg:
continue

via.append(sanitize_package_name(pkg))
via.append(sanitize_package_name(pkg))

url = data[-1].strip(" #")
if not url.startswith(("http://", "https://", "file://")):
if wheel_dirs and url.startswith(*wheel_dirs):
# If the path is a relative parent, then we use the existing
# lockfile label to create a clean label. This logic assumes
# the wheeldir will be in a package (but not a package itself).
if url.startswith(("..", "./../")):
url_parents = url.count("../")
if len(data) > 3:
url = data[-1].strip(" #")
if not url.startswith(("http://", "https://", "file://")):
if wheel_dirs and url.startswith(*wheel_dirs):
# If the path is a relative parent, then we use the existing
# lockfile label to create a clean label. This logic assumes
# the wheeldir will be in a package (but not a package itself).
if url.startswith(("..", "./../")):
url_parents = url.count("../")

repository, _, path = str(lockfile).partition("//")
lockfile_dir, _, _ = path.partition(":")
repository, _, path = str(lockfile).partition("//")
lockfile_dir, _, _ = path.partition(":")

new_package = "/".join(lockfile_dir.split("/")[:-url_parents])
new_package = "/".join(lockfile_dir.split("/")[:-url_parents])

split = url.split("/")
wheel = "{}/{}".format(split[-2], split[-1])
split = url.split("/")
wheel = "{}/{}".format(split[-2], split[-1])

whl = "{}//{}:{}".format(repository, new_package, wheel)
whl = "{}//{}:{}".format(repository, new_package, wheel)
else:
whl = str(lockfile.same_package_label(url))
url = None
else:
whl = str(lockfile.same_package_label(url))
url = None
else:
fail("Unexpected data found where url was expected for {} ({}):\n{}".format(
repository_name,
data[0].rstrip("\\ "),
data[-1],
))
fail("Unexpected data found where url was expected for {} ({}):\n{}".format(
repository_name,
data[0].rstrip("\\ "),
data[-1],
))

return {
"annotations": {},
Expand All @@ -242,7 +247,7 @@ def parse_constraint(data, repository_name, lockfile, wheel_dirs):
"sha256": sha256,
"url": url,
"version": version,
"via": sorted(via),
"via": sorted(via) if via != None else None,
"whl": whl,
}

Expand Down Expand Up @@ -309,6 +314,8 @@ def parse_lockfile(
}

for pkg, data in packages.items():
if data["via"] == None:
continue
for via in data["via"]:
# It may be the case that an entry in `via` is the name
# of a "requirements.in" file. Unfortunately the file name
Expand Down
17 changes: 1 addition & 16 deletions private/tests/override_module_repos/overridee/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
################################################################################
## AUTOGENERATED: This file is autogenerated by req-compile.
##
## Python: 3.11.7
## Platform: Linux
##
## To regenerate this file, use the following command:
##
## bazel run "@//private/tests/cross_platform:requirements.linux.update"
##
################################################################################

platformdirs==4.2.2 \
--hash=sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee
# via via rules_req_compile/private/tests/override_module_repos/overridee/requirements.in
# https://files.pythonhosted.org/packages/68/13/2aa1f0e1364feb2c9ef45302f387ac0bd81484e9c9a4c5688a322fbdfd08/platformdirs-4.2.2-py3-none-any.whl#sha256=2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee
platformdirs==4.2.2
Loading

0 comments on commit 0f234b1

Please sign in to comment.