Skip to content

Commit

Permalink
Auto-generate fully specified requirements (#1868)
Browse files Browse the repository at this point in the history
* Auto-generate fully specified requirements

* Generate hashes

* license year
  • Loading branch information
damccorm authored Sep 16, 2024
1 parent 29d5fa5 commit 02ad555
Show file tree
Hide file tree
Showing 9 changed files with 3,648 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
**/dependency-reduced-pom.xml
**/target/**/*

# Python requirements build files
**/__build__/**/*

# IntelliJ files
**/.idea/**/*
**/*.iml
Expand Down
19 changes: 19 additions & 0 deletions python/generate_all_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Google Inc. All Rights Reserved.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

SCRIPTPATH=$(dirname "$0")

sh $SCRIPTPATH/generate_dependencies.sh $SCRIPTPATH/../v1/src/main/python/base_requirements.txt $SCRIPTPATH/../v1/src/main/python/requirements.txt
sh $SCRIPTPATH/generate_dependencies.sh $SCRIPTPATH/../python/src/main/python/word-count-python/base_requirements.txt $SCRIPTPATH/../python/src/main/python/word-count-python/requirements.txt
sh $SCRIPTPATH/generate_dependencies.sh $SCRIPTPATH/../python/src/main/python/streaming-llm/base_requirements.txt $SCRIPTPATH/../python/src/main/python/streaming-llm/requirements.txt
75 changes: 75 additions & 0 deletions python/generate_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2024 Google Inc. All Rights Reserved.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

BASE_REQUIREMENTS_PATH=$1
TARGET_REQUIREMENTS_PATH=$2

if ! python3 --version > /dev/null 2>&1 ; then
echo "Please install a python3 interpreter. See s.apache.org/beam-python-dev-wiki for Python installation tips."
exit 1
fi

if ! python3 -m venv --help > /dev/null 2>&1 ; then
echo "Your python3 installation does not have a required venv module. See s.apache.org/beam-python-dev-wiki for Python installation tips."
exit 1
fi

set -ex

ENV_PATH="$PWD/__build__/python${PY_VERSION/./}_requirements_gen"
rm -rf "$ENV_PATH" 2>/dev/null || true
python3 -m venv "$ENV_PATH"
source "$ENV_PATH"/bin/activate
pip install --upgrade pip setuptools wheel
pip install pip-tools

# Install requirements from base file
pip install ${PIP_EXTRA_OPTIONS:+"$PIP_EXTRA_OPTIONS"} --no-cache-dir -r $BASE_REQUIREMENTS_PATH

echo "Checking for broken dependencies:"
pip check
echo "Installed dependencies:"
pip freeze

# Generate hashes for new requirements file
echo "Running pip-compile to generate hashes"
pip-compile $BASE_REQUIREMENTS_PATH -o $TARGET_REQUIREMENTS_PATH --generate-hashes

PY_IMAGE="py${PY_VERSION//.}"
cat <<EOT > "$TARGET_REQUIREMENTS_PATH"
# Copyright 2024 Google Inc. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Autogenerated requirements file for Apache Beam container image.
# From the templates base directory to update,
# run: sh python/generate_dependencies.sh $BASE_REQUIREMENTS_PATH $TARGET_REQUIREMENTS_PATH
# or: sh python/generate_all_dependencies.sh
# Do not edit manually, adjust the base requirements file, and regenerate the list.
$(cat $TARGET_REQUIREMENTS_PATH)
EOT

rm -rf "$ENV_PATH"
4 changes: 4 additions & 0 deletions python/src/main/python/streaming-llm/base_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apache-beam[gcp]
torch
transformers
torchvision
1,901 changes: 1,897 additions & 4 deletions python/src/main/python/streaming-llm/requirements.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apache-beam[gcp]
1,372 changes: 1,371 additions & 1 deletion python/src/main/python/word-count-python/requirements.txt

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions v1/src/main/python/base_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2020 Google Inc. All Rights Reserved.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

google-cloud
google-cloud-pubsub
Loading

0 comments on commit 02ad555

Please sign in to comment.