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

Adds Nightly package for keras-cv #2139

Merged
merged 2 commits into from
Nov 10, 2023
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
3 changes: 2 additions & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ name: Tests
on:
push:
pull_request:
workflow_call:
release:
types: [created]

permissions:
contents: read

jobs:
test:
keras2:
name: Test the code with tf.keras
runs-on: ubuntu-latest
steps:
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Nightly

on:
workflow_dispatch: # To Generate wheels on demand outside of schedule.
schedule:
- cron: '0 3 * * *' # run at 3 AM UTC / 8 PM PDT

permissions:
contents: read

jobs:
run-test-for-nightly:
uses: ./.github/workflows/actions.yml
nightly:
name: Build Wheel file and upload
needs: [run-test-for-nightly]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Get pip cache dir
id: pip-cache
run: |
python -m pip install --upgrade pip setuptools
echo "::set-output name=dir::$(pip cache dir)"
- name: pip cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
pip install twine
pip install -r requirements.txt --progress-bar off
- name: Build wheel file
run: |
python pip_build.py --nightly
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_NIGHTLY_API_TOKEN }}
packages-dir: dist/
verbose: true
2 changes: 1 addition & 1 deletion keras_cv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
from keras_cv.core import NormalFactorSampler
from keras_cv.core import UniformFactorSampler

__version__ = "0.6.4"
__version__ = "0.7.0"
38 changes: 31 additions & 7 deletions pip_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
```
"""
import argparse
import datetime
import glob
import os
import pathlib
Expand All @@ -49,14 +50,34 @@ def ignore_files(_, filenames):
return [f for f in filenames if "test" in f]


def build():
def export_version_string(version, is_nightly=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like our version string in __init__.py is the current release version. Maybe we should update that to 0.7.0 so it is pointing to the next major version we will release?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""Export Version and Package Name."""
if is_nightly:
date = datetime.datetime.now()
version += f".dev{date.strftime('%Y%m%d%H')}"
# Replaces `name="keras-cv"` in `setup.py` with `keras-cv-nightly`
with open("setup.py") as f:
setup_contents = f.read()
with open("setup.py", "w") as f:
setup_contents = setup_contents.replace(
'name="keras-cv"', 'name="keras-cv-nightly"'
)
f.write(setup_contents)

# Make sure to export the __version__ string
with open(os.path.join(package, "__init__.py")) as f:
init_contents = f.read()
with open(os.path.join(package, "__init__.py"), "w") as f:
f.write(init_contents + "\n\n" + f'__version__ = "{version}"\n')


def build(root_path, is_nightly=False):
if os.path.exists(build_directory):
raise ValueError(f"Directory already exists: {build_directory}")

whl_path = None
try:
# Copy sources (`keras_cv/` directory and setup files) to build dir
root_path = pathlib.Path(__file__).parent.resolve()
os.chdir(root_path)
os.mkdir(build_directory)
shutil.copytree(
Expand All @@ -75,10 +96,7 @@ def build():
# Make sure to export the __version__ string
from keras_cv.src import __version__ # noqa: E402

with open(os.path.join(package, "__init__.py")) as f:
init_contents = f.read()
with open(os.path.join(package, "__init__.py"), "w") as f:
f.write(init_contents + "\n\n" + f'__version__ = "{__version__}"\n')
export_version_string(__version__, is_nightly)

# Build the package
os.system("python3 -m build")
Expand Down Expand Up @@ -115,7 +133,13 @@ def install_whl(whl_fpath):
action="store_true",
help="Whether to install the generated wheel file.",
)
parser.add_argument(
"--nightly",
action="store_true",
help="Whether to generate nightly wheel file.",
)
args = parser.parse_args()
whl_path = build()
root_path = pathlib.Path(__file__).parent.resolve()
whl_path = build(root_path, args.nightly)
if whl_path and args.install:
install_whl(whl_path)