@@ -4,54 +4,60 @@ set -eoux pipefail
44
55pushd /opt/pip-tools.d
66
7- # First pip-compile gathers all reqs, but we are care only about VCS installs
8- # It's possible there are 2nd degree transitive dependencies that are VCS, so
9- # this is more robust to gather VCS requirements at the cost of pip-compiling
10- # twice
11- pip-compile -o requirements.pre $( ls requirements-* .in)
7+ # If requirements-pinned.txt exists, skip compilation
8+ if [[ -f " requirements-pinned.txt" ]]; then
9+ sed -E ' s/#sha256=[a-f0-9]+//g' requirements-pinned.txt > requirements.txt
10+ else
11+ # First pip-compile gathers all reqs, but we are care only about VCS installs
12+ # It's possible there are 2nd degree transitive dependencies that are VCS, so
13+ # this is more robust to gather VCS requirements at the cost of pip-compiling
14+ # twice
15+ pip-compile -o requirements.pre $( ls requirements-* .in)
1216
13- IFS=$' \n '
14- for line in $( cat requirements.pre | egrep ' ^[^#].+ @ git\+' || true) ; do
15- # VCS installs are of the form "PACKAGE @ git+..."
16- PACKAGE=$( echo " $line " | awk ' {print $1}' )
17- ref=$( yq e " .${PACKAGE} .latest_verified_commit" ${MANIFEST_FILE} )
18- if [[ " $line " == * " #subdirectory=" * ]]; then
19- # This is required b/c git-refs/commits cannot come after
20- # the subdirectory fragment.
21- # An example of an install that is of this form is:
22- # 'orbax-checkpoint @ git+https://github.com/google/orbax/#subdirectory=checkpoint'
23- echo " ${line} " | sed " s/#subdirectory=/@${ref} #subdirectory=/"
24- else
25- echo " ${line} @${ref} "
26- fi
27- done | tee requirements.vcs
28- unset IFS
17+ IFS=$' \n '
18+ for line in $( cat requirements.pre | egrep ' ^[^#].+ @ git\+' || true) ; do
19+ # VCS installs are of the form "PACKAGE @ git+..."
20+ PACKAGE=$( echo " $line " | awk ' {print $1}' )
21+ ref=$( yq e " .${PACKAGE} .latest_verified_commit" ${MANIFEST_FILE} )
22+ if [[ " $line " == * " #subdirectory=" * ]]; then
23+ # This is required b/c git-refs/commits cannot come after
24+ # the subdirectory fragment.
25+ # An example of an install that is of this form is:
26+ # 'orbax-checkpoint @ git+https://github.com/google/orbax/#subdirectory=checkpoint'
27+ echo " ${line} " | sed " s/#subdirectory=/@${ref} #subdirectory=/"
28+ else
29+ echo " ${line} @${ref} "
30+ fi
31+ done | tee requirements.vcs
32+ unset IFS
2933
30- # Second pip-compile includes one more requirements file that pins all vcs installs
31- # Uses a special env var to let our custom pip impl know to treat the following as
32- # equivalent:
33- #
34- # fiddle @ git+https://github.com/google/fiddle
35- # fiddle @ git+https://github.com/google/fiddle@cd4497e4c09bdf95dcccaa1e138c2c125d32d39f
36- #
37- # JAX_TOOLBOX_VCS_EQUIVALENCY is an environment variable enabling custom logic in pip
38- # that treats the above as equivalent and prefers the URI wit the SHA
39- JAX_TOOLBOX_VCS_EQUIVALENCY=true pip-compile -o requirements.txt requirements.vcs $( ls requirements-* .in)
34+ # Second pip-compile includes one more requirements file that pins all vcs installs
35+ # Uses a special env var to let our custom pip impl know to treat the following as
36+ # equivalent:
37+ #
38+ # fiddle @ git+https://github.com/google/fiddle
39+ # fiddle @ git+https://github.com/google/fiddle@cd4497e4c09bdf95dcccaa1e138c2c125d32d39f
40+ #
41+ # JAX_TOOLBOX_VCS_EQUIVALENCY is an environment variable enabling custom logic in pip
42+ # that treats the above as equivalent and prefers the URI wit the SHA
43+ JAX_TOOLBOX_VCS_EQUIVALENCY=true pip-compile -o requirements.txt requirements.vcs $( ls requirements-* .in)
4044
41- # If there are unpinned VCS dependencies, error since these should be included in the manifest
42- unpinned_vcs_dependencies=$( cat requirements.txt | egrep ' ^[^#].+ @ git\+' | egrep -v ' ^[^#].+ @ git\+.+@' || true)
43- if [[ $( echo -n " $unpinned_vcs_dependencies " | wc -l) -gt 0 ]]; then
44- echo " Unpinned VCS installs found in $( readlink -f requirements.txt) :"
45- echo " $unpinned_vcs_dependencies "
46- exit 1
47- fi
45+ # If there are unpinned VCS dependencies, error since these should be included in the manifest
46+ unpinned_vcs_dependencies=$( cat requirements.txt | egrep ' ^[^#].+ @ git\+' | egrep -v ' ^[^#].+ @ git\+.+@' || true)
47+ if [[ $( echo -n " $unpinned_vcs_dependencies " | wc -l) -gt 0 ]]; then
48+ echo " Unpinned VCS installs found in $( readlink -f requirements.txt) :"
49+ echo " $unpinned_vcs_dependencies "
50+ exit 1
51+ fi
4852
49- # Replace any tensorflow==X with tensorflow-cpu==X in requirements.txt only on amd64
50- if [ " $( uname -m) " = " x86_64" ]; then
51- sed -i ' s/^tensorflow==\([0-9.*]\+\)$/tensorflow-cpu==\1/' requirements.txt
52- else
53- echo " Skipping TF on $( uname -m) "
53+ # Replace any tensorflow==X with tensorflow-cpu==X in requirements.txt only on amd64
54+ if [[ " $( uname -m) " = " x86_64" ]]; then
55+ sed -i ' s/^tensorflow==\([0-9.*]\+\)$/tensorflow-cpu==\1/' requirements.txt
56+ else
57+ echo " Skipping TF on $( uname -m) "
58+ fi
5459fi
60+
5561# --no-deps is required since conflicts can still appear during pip-sync
5662pip-sync --pip-args ' --no-deps --src /opt' requirements.txt
5763
@@ -63,3 +69,6 @@ for post_install in $(ls /opt/pip-tools-post-install.d/*); do
6369 " ${post_install} "
6470 fi
6571done
72+
73+ echo " ######## Frozen requirements ########"
74+ pip freeze
0 commit comments