From 7f0ec7d4e1e8a7e3d7823f2a8c1ad08527799d00 Mon Sep 17 00:00:00 2001 From: Soban Javed Date: Tue, 7 Sep 2021 15:49:20 +0500 Subject: [PATCH] feat: add script to resolve common constraint This script will be used be each repo during make upgrade, if wants to override global constraints locally. --- edx_repo_tools/resolve-common-constraints.sh | 49 ++++++++++++++++++++ setup.py | 3 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 edx_repo_tools/resolve-common-constraints.sh diff --git a/edx_repo_tools/resolve-common-constraints.sh b/edx_repo_tools/resolve-common-constraints.sh new file mode 100644 index 00000000..b4f2fd48 --- /dev/null +++ b/edx_repo_tools/resolve-common-constraints.sh @@ -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 diff --git a/setup.py b/setup.py index 6c9e4540..f21b42c6 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='edx-repo-tools', - version='0.3.2', + version='0.3.3', description="This repo contains a number of tools Open edX uses for working with GitHub repositories.", long_description=long_description, license='Apache', @@ -52,6 +52,7 @@ 'conventional_commits = edx_repo_tools.conventional_commits.commitstats:main', 'replace_render_to_response = edx_repo_tools.codemods.django3.replace_render_to_response:main', 'add_django32_settings = edx_repo_tools.codemods.django3.add_new_django32_settings:main', + 'resolve_common_constraints = edx_repo_tools.resolve_common_constraints', ], }, package_data={