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

Read TF version from poetry.lock #9785

Merged
merged 2 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions .github/workflows/ci-model-regression-on-schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ jobs:

- name: Get TensorFlow version
run: |-
# Read TF version, trim special characters ^~><+
TF_VERSION=$(grep "tensorflow =" pyproject.toml | sed 's/^[^"]*"\([^"]*\),.*/\1/' | sed 's/[\^~><=]//g')
# Keep the first 3 characters, e.g. we keep 2.3 if TF_VERSION is 2.3.4
TF_VERSION=${TF_VERSION::3}
# Read TF version from poetry.lock file
pip install toml
TF_VERSION=$(scripts/read_tenforflow_version.sh)
echo "TensorFlow version: $TF_VERSION"
echo TF_VERSION=$TF_VERSION >> $GITHUB_ENV

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci-model-regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ jobs:

- name: Get TensorFlow version
run: |-
# Read TF version, trim special characters ^~><+
TF_VERSION=$(grep "tensorflow =" pyproject.toml | sed 's/^[^"]*"\([^"]*\),.*/\1/' | sed 's/[\^~><=]//g')
# Read TF version from poetry.lock file
pip install toml
TF_VERSION=$(scripts/read_tenforflow_version.sh)
# Keep the first 3 characters, e.g. we keep 2.3 if TF_VERSION is 2.3.4
TF_VERSION=${TF_VERSION::3}
echo "TensorFlow version: $TF_VERSION"
Expand Down
22 changes: 22 additions & 0 deletions scripts/read_tenforflow_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python

"""Extract the TensorFlow version from poetry.lock. Used in e.g. github workflows."""

import pathlib
import sys
import toml

poetry_path = 'poetry.lock'

if __name__ == "__main__":
if pathlib.Path(poetry_path).is_file():
# Get the list of dict that contains all information about packages
package_list = toml.load(poetry_path).get('package')
# Extract tensorflow version
tf_version = next(filter(lambda x: x.get('name') == 'tensorflow', package_list)).get('version')
print(tf_version)
sys.exit(0)

else:
print(f'File {poetry_path} does not exist.')
sys.exit(1)