Skip to content

Commit

Permalink
throw an error if we couldn't find one version that works for all dep…
Browse files Browse the repository at this point in the history
…endencies when generating the constraints file

Signed-off-by: Shubh Bapna <[email protected]>
  • Loading branch information
shubhbapna committed Oct 3, 2024
1 parent db8129d commit 332d5d9
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
- bootstrap_extras
- bootstrap_build_tags
- bootstrap_prerelease
- bootstrap_constraints
- build
- build_order
- build_steps
Expand Down
3 changes: 3 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pull_request_rules:
- check-success=e2e (3.11, 1.75, bootstrap_extras, ubuntu-latest)
- check-success=e2e (3.11, 1.75, bootstrap_build_tags, ubuntu-latest)
- check-success=e2e (3.11, 1.75, bootstrap_prerelease, ubuntu-latest)
- check-success=e2e (3.11, 1.75, bootstrap_constraints, ubuntu-latest)
- check-success=e2e (3.11, 1.75, build, ubuntu-latest)
- check-success=e2e (3.11, 1.75, build_order, ubuntu-latest)
- check-success=e2e (3.11, 1.75, build_settings, ubuntu-latest)
Expand All @@ -53,6 +54,8 @@ pull_request_rules:
- check-success=e2e (3.12, 1.75, bootstrap_build_tags, ubuntu-latest)
- check-success=e2e (3.12, 1.75, bootstrap_prerelease, macos-latest)
- check-success=e2e (3.12, 1.75, bootstrap_prerelease, ubuntu-latest)
- check-success=e2e (3.12, 1.75, bootstrap_constraints, macos-latest)
- check-success=e2e (3.12, 1.75, bootstrap_constraints, ubuntu-latest)
- check-success=e2e (3.12, 1.75, build, macos-latest)
- check-success=e2e (3.12, 1.75, build, ubuntu-latest)
- check-success=e2e (3.12, 1.75, build_order, macos-latest)
Expand Down
1 change: 0 additions & 1 deletion e2e/bootstrap_constraint.txt

This file was deleted.

54 changes: 54 additions & 0 deletions e2e/test_bootstrap_constraints.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
# -*- indent-tabs-mode: nil; tab-width: 2; sh-indentation: 2; -*-

# Tests full bootstrap and installation of a complex package, without
# worrying about isolating the tools from upstream sources or
# restricting network access during the build. This allows us to test
# the overall logic of the build tools separately from the isolated
# build pipelines.

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$SCRIPTDIR/common.sh"

# passing settings to bootstrap but should have 0 effect on it
fromager \
--log-file="$OUTDIR/bootstrap.log" \
--error-log-file="$OUTDIR/fromager-errors.log" \
--sdists-repo="$OUTDIR/sdists-repo" \
--wheels-repo="$OUTDIR/wheels-repo" \
--work-dir="$OUTDIR/work-dir" \
--settings-dir="$SCRIPTDIR/changelog_settings" \
bootstrap 'stevedore==5.2.0' 'stevedore==4.0.0' || true

pass=true

# Check for log message that the override is loaded
if ! grep -q "Could not produce a pip compatible constraints file" "$OUTDIR/bootstrap.log"; then
echo "FAIL: did not throw an error when generating an incorrect constraints file" 1>&2
pass=false
fi

$pass

if [ ! -f "$OUTDIR/work-dir/constraints.txt" ]; then
echo "Did not find $OUTDIR/work-dir/constraints.txt" 1>&2
pass=false
fi

$pass

EXPECTED_LINES="
pbr==6.1.0
# ERROR
stevedore==4.0.0
stevedore==5.2.0
"

for pattern in $EXPECTED_LINES; do
if ! grep -q "${pattern}" "$OUTDIR/work-dir/constraints.txt"; then
echo "Did not find $pattern in constraints file" 1>&2
pass=false
fi
done

$pass
15 changes: 10 additions & 5 deletions src/fromager/commands/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,21 @@ def bootstrap(

constraints_filename = wkctx.work_dir / "constraints.txt"
logger.info(f"writing installation dependencies to {constraints_filename}")
with open(wkctx.work_dir / "constraints.txt", "w") as f:
write_constraints_file(graph=wkctx.dependency_graph, output=f)
with open(constraints_filename, "w") as f:
if not write_constraints_file(graph=wkctx.dependency_graph, output=f):
raise ValueError(
f"Could not produce a pip compatible constraints file. Please review {constraints_filename} for more details"
)


def write_constraints_file(
graph: dependency_graph.DependencyGraph,
output: typing.TextIO,
) -> None:
) -> bool:
# Look for potential conflicts by tracking how many different versions of
# each package are needed.
conflicts = graph.get_install_dependency_versions()

ret = True
for dep_name, nodes in sorted(conflicts.items()):
versions = [node.version for node in nodes]
if len(versions) == 0:
Expand Down Expand Up @@ -222,10 +225,12 @@ def write_constraints_file(
break
else:
# No single version could be used, so go ahead and print all the
# versions with a warning message.
# versions with a warning message
ret = False
output.write(
f"# ERROR: no single version of {dep_name} met all requirements\n"
)
logging.error("%s: no single version meets all requirements", dep_name)
for dv in sorted(versions):
output.write(f"{dep_name}=={dv}\n")
return ret

0 comments on commit 332d5d9

Please sign in to comment.