Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add script to resolve common constraint #193

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions edx_lint/files/resolve-common-constraints.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Fetching latest copy of common constraints from edx-lint repo
wget -O "requirements/common_constraints.txt" https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt || touch "requirements/common_constraints.txt"

common_constraints=()
local_constraints=()
updated_common_constraints=()

while IFS= read -r line; do
if [ -n "$line" ] && [ "${line:0:1}" != "#" ];
then
# Read common constraints from common constraints file
common_constraints+=("$line")
fi
done < requirements/common_constraints.txt

while IFS= read -r line; do
if [ -n "$line" ] && [ "${line:0:1}" != "#" ] && [ "${line:0:1}" != "-" ];
then
# Read local constraints from constraints file for comparison
local_constraints+=("$line")
fi
done < requirements/constraints.txt


for common in "${common_constraints[@]}"
do
# Extract package name from constraint
common_package=$(echo "$common" | sed 's/\([a-zA-Z0-9-]*\).*/\1/')
found=false
for local in "${local_constraints[@]}"
do
# Extract package name from constraint
local_package=$(echo "$local" | sed 's/\([a-zA-Z0-9-]*\).*/\1/')
if [ "$common_package" = "$local_package" ];
then
# Update the flag if local pin is found on same package
found=true
break
fi
done
if [ "$found" = false ];
then
updated_common_constraints+=("$common")
fi
done

# Adding filtered common constraints into a file before running pip-compile and add reference of this file in constraints file.
printf "%s\n" "${updated_common_constraints[@]}" > requirements/common_constraints.txt
echo "-c common_constraints.txt" >> requirements/constraints.txt