Skip to content

Commit

Permalink
fIx constraints use in CI image after uv change (apache#37845)
Browse files Browse the repository at this point in the history
With the change to switch to uv, we skipped constraints being used
in CI image - in effect all PR were not using constraints, but they
were using not constraint dependencues but lowest-direct
mode of installation so direct dependencies would not be upgraded
in such case, only the transitive ones, so the risk of failure was
anyhow small even if someone released a new, breakong dependency.

The reason is that `uv` currently does not support installing
constraints from URL. We had been silently failing back to the
"no-constraints" way in such case (this is default mode if for any reason
constraint build fail in such case.

It introduced the risk that in case 3rd-party breaking dependency
was released it would also start breaking regular PRs,
not only the "canary" build.

We fix it by downloading constraints locally when they are remote and
using them from there.

While this is being worked on in astral-sh/uv#2081
and likely to land in uv 0.1.14, it's also a good idea to actually
download the constraints and keep them around - this might be handy
if you want to later use constraints to install "golden" set of
dependencies wihtout necessity to build the right URL - you can always
use `${HOME}/constraints.txt`.

This PR fixes it and also changes the fallback mechanism to perform the
lowest-direct upgrade only in case the constraint build fails, rather
than always run the lowest-dirct upgrade even if constraints install
works fine - this will make sure that most PRs are using exactly the
constraint version of the dependencies (at least the version of
constraints that were generated last time when pyproject.toml changed).
  • Loading branch information
potiuk authored and utkarsharma2 committed Apr 22, 2024
1 parent d8bd354 commit 59a2186
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 29 deletions.
37 changes: 27 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,18 @@ function common::get_constraints_location() {
python_version=$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
AIRFLOW_CONSTRAINTS_LOCATION="${constraints_base}/${AIRFLOW_CONSTRAINTS_MODE}-${python_version}.txt"
fi

if [[ ${AIRFLOW_CONSTRAINTS_LOCATION} =~ http.* ]]; then
echo
echo "${COLOR_BLUE}Downloading constraints from ${AIRFLOW_CONSTRAINTS_LOCATION} to ${HOME}/constraints.txt ${COLOR_RESET}"
echo
curl -sSf -o "${HOME}/constraints.txt" "${AIRFLOW_CONSTRAINTS_LOCATION}"
else
echo
echo "${COLOR_BLUE}Copying constraints from ${AIRFLOW_CONSTRAINTS_LOCATION} to ${HOME}/constraints.txt ${COLOR_RESET}"
echo
cp "${AIRFLOW_CONSTRAINTS_LOCATION}" "${HOME}/constraints.txt"
fi
}

function common::show_packaging_tool_version_and_location() {
Expand Down Expand Up @@ -730,7 +742,7 @@ function install_airflow_and_providers_from_docker_context_files(){
set -x
${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} "${packaging_flags[@]}" \
${ADDITIONAL_PIP_INSTALL_FLAGS} \
--constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" \
--constraint "${HOME}/constraints.txt" \
${reinstalling_apache_airflow_package} ${reinstalling_apache_airflow_providers_packages}
set +x
fi
Expand Down Expand Up @@ -826,19 +838,24 @@ function install_airflow() {
pip check
else
echo
echo "${COLOR_BLUE}Installing all packages with constraints and upgrade if needed${COLOR_RESET}"
echo "${COLOR_BLUE}Installing all packages with constraints or upgrade if needed${COLOR_RESET}"
echo
set -x
${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} ${AIRFLOW_INSTALL_EDITABLE_FLAG} \
# Install all packages with constraints
if ! ${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} ${AIRFLOW_INSTALL_EDITABLE_FLAG} \
${ADDITIONAL_PIP_INSTALL_FLAGS} \
"${AIRFLOW_INSTALLATION_METHOD}[${AIRFLOW_EXTRAS}]${AIRFLOW_VERSION_SPECIFICATION}" \
--constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" || true
common::install_packaging_tool
# then upgrade if needed without using constraints to account for new limits in pyproject.toml
${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} --upgrade ${RESOLUTION_LOWEST_DIRECT_FLAG} \
${ADDITIONAL_PIP_INSTALL_FLAGS} \
${AIRFLOW_INSTALL_EDITABLE_FLAG} \
"${AIRFLOW_INSTALLATION_METHOD}[${AIRFLOW_EXTRAS}]${AIRFLOW_VERSION_SPECIFICATION}"
--constraint "${HOME}/constraints.txt"; then
echo
echo "${COLOR_YELLOW}Likely pyproject.toml has new dependencies conflicting with constraints.${COLOR_RESET}"
echo
echo "${COLOR_BLUE}Falling back to no-constraints, lowest-direct resolution installation.${COLOR_RESET}"
echo
${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} --upgrade ${RESOLUTION_LOWEST_DIRECT_FLAG} \
${ADDITIONAL_PIP_INSTALL_FLAGS} \
${AIRFLOW_INSTALL_EDITABLE_FLAG} \
"${AIRFLOW_INSTALLATION_METHOD}[${AIRFLOW_EXTRAS}]${AIRFLOW_VERSION_SPECIFICATION}"
fi
common::install_packaging_tool
set +x
echo
Expand Down
35 changes: 26 additions & 9 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,18 @@ function common::get_constraints_location() {
python_version=$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
AIRFLOW_CONSTRAINTS_LOCATION="${constraints_base}/${AIRFLOW_CONSTRAINTS_MODE}-${python_version}.txt"
fi

if [[ ${AIRFLOW_CONSTRAINTS_LOCATION} =~ http.* ]]; then
echo
echo "${COLOR_BLUE}Downloading constraints from ${AIRFLOW_CONSTRAINTS_LOCATION} to ${HOME}/constraints.txt ${COLOR_RESET}"
echo
curl -sSf -o "${HOME}/constraints.txt" "${AIRFLOW_CONSTRAINTS_LOCATION}"
else
echo
echo "${COLOR_BLUE}Copying constraints from ${AIRFLOW_CONSTRAINTS_LOCATION} to ${HOME}/constraints.txt ${COLOR_RESET}"
echo
cp "${AIRFLOW_CONSTRAINTS_LOCATION}" "${HOME}/constraints.txt"
fi
}

function common::show_packaging_tool_version_and_location() {
Expand Down Expand Up @@ -666,19 +678,24 @@ function install_airflow() {
pip check
else
echo
echo "${COLOR_BLUE}Installing all packages with constraints and upgrade if needed${COLOR_RESET}"
echo "${COLOR_BLUE}Installing all packages with constraints or upgrade if needed${COLOR_RESET}"
echo
set -x
${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} ${AIRFLOW_INSTALL_EDITABLE_FLAG} \
# Install all packages with constraints
if ! ${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} ${AIRFLOW_INSTALL_EDITABLE_FLAG} \
${ADDITIONAL_PIP_INSTALL_FLAGS} \
"${AIRFLOW_INSTALLATION_METHOD}[${AIRFLOW_EXTRAS}]${AIRFLOW_VERSION_SPECIFICATION}" \
--constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" || true
common::install_packaging_tool
# then upgrade if needed without using constraints to account for new limits in pyproject.toml
${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} --upgrade ${RESOLUTION_LOWEST_DIRECT_FLAG} \
${ADDITIONAL_PIP_INSTALL_FLAGS} \
${AIRFLOW_INSTALL_EDITABLE_FLAG} \
"${AIRFLOW_INSTALLATION_METHOD}[${AIRFLOW_EXTRAS}]${AIRFLOW_VERSION_SPECIFICATION}"
--constraint "${HOME}/constraints.txt"; then
echo
echo "${COLOR_YELLOW}Likely pyproject.toml has new dependencies conflicting with constraints.${COLOR_RESET}"
echo
echo "${COLOR_BLUE}Falling back to no-constraints, lowest-direct resolution installation.${COLOR_RESET}"
echo
${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} --upgrade ${RESOLUTION_LOWEST_DIRECT_FLAG} \
${ADDITIONAL_PIP_INSTALL_FLAGS} \
${AIRFLOW_INSTALL_EDITABLE_FLAG} \
"${AIRFLOW_INSTALLATION_METHOD}[${AIRFLOW_EXTRAS}]${AIRFLOW_VERSION_SPECIFICATION}"
fi
common::install_packaging_tool
set +x
echo
Expand Down
12 changes: 12 additions & 0 deletions scripts/docker/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ function common::get_constraints_location() {
python_version=$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
AIRFLOW_CONSTRAINTS_LOCATION="${constraints_base}/${AIRFLOW_CONSTRAINTS_MODE}-${python_version}.txt"
fi

if [[ ${AIRFLOW_CONSTRAINTS_LOCATION} =~ http.* ]]; then
echo
echo "${COLOR_BLUE}Downloading constraints from ${AIRFLOW_CONSTRAINTS_LOCATION} to ${HOME}/constraints.txt ${COLOR_RESET}"
echo
curl -sSf -o "${HOME}/constraints.txt" "${AIRFLOW_CONSTRAINTS_LOCATION}"
else
echo
echo "${COLOR_BLUE}Copying constraints from ${AIRFLOW_CONSTRAINTS_LOCATION} to ${HOME}/constraints.txt ${COLOR_RESET}"
echo
cp "${AIRFLOW_CONSTRAINTS_LOCATION}" "${HOME}/constraints.txt"
fi
}

function common::show_packaging_tool_version_and_location() {
Expand Down
23 changes: 14 additions & 9 deletions scripts/docker/install_airflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,24 @@ function install_airflow() {
pip check
else
echo
echo "${COLOR_BLUE}Installing all packages with constraints and upgrade if needed${COLOR_RESET}"
echo "${COLOR_BLUE}Installing all packages with constraints or upgrade if needed${COLOR_RESET}"
echo
set -x
${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} ${AIRFLOW_INSTALL_EDITABLE_FLAG} \
# Install all packages with constraints
if ! ${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} ${AIRFLOW_INSTALL_EDITABLE_FLAG} \
${ADDITIONAL_PIP_INSTALL_FLAGS} \
"${AIRFLOW_INSTALLATION_METHOD}[${AIRFLOW_EXTRAS}]${AIRFLOW_VERSION_SPECIFICATION}" \
--constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" || true
common::install_packaging_tool
# then upgrade if needed without using constraints to account for new limits in pyproject.toml
${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} --upgrade ${RESOLUTION_LOWEST_DIRECT_FLAG} \
${ADDITIONAL_PIP_INSTALL_FLAGS} \
${AIRFLOW_INSTALL_EDITABLE_FLAG} \
"${AIRFLOW_INSTALLATION_METHOD}[${AIRFLOW_EXTRAS}]${AIRFLOW_VERSION_SPECIFICATION}"
--constraint "${HOME}/constraints.txt"; then
echo
echo "${COLOR_YELLOW}Likely pyproject.toml has new dependencies conflicting with constraints.${COLOR_RESET}"
echo
echo "${COLOR_BLUE}Falling back to no-constraints, lowest-direct resolution installation.${COLOR_RESET}"
echo
${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} --upgrade ${RESOLUTION_LOWEST_DIRECT_FLAG} \
${ADDITIONAL_PIP_INSTALL_FLAGS} \
${AIRFLOW_INSTALL_EDITABLE_FLAG} \
"${AIRFLOW_INSTALLATION_METHOD}[${AIRFLOW_EXTRAS}]${AIRFLOW_VERSION_SPECIFICATION}"
fi
common::install_packaging_tool
set +x
echo
Expand Down
2 changes: 1 addition & 1 deletion scripts/docker/install_from_docker_context_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function install_airflow_and_providers_from_docker_context_files(){
set -x
${PACKAGING_TOOL_CMD} install ${EXTRA_INSTALL_FLAGS} "${packaging_flags[@]}" \
${ADDITIONAL_PIP_INSTALL_FLAGS} \
--constraint "${AIRFLOW_CONSTRAINTS_LOCATION}" \
--constraint "${HOME}/constraints.txt" \
${reinstalling_apache_airflow_package} ${reinstalling_apache_airflow_providers_packages}
set +x
fi
Expand Down

0 comments on commit 59a2186

Please sign in to comment.