From 3264f9e0a4db19dcf3b8bedd982892f82d0f71b5 Mon Sep 17 00:00:00 2001 From: sampathweb <1437573+sampathweb@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:35:30 -0600 Subject: [PATCH 1/2] Add Nightly package --- .github/workflows/actions.yml | 3 ++- .github/workflows/nightly.yml | 49 +++++++++++++++++++++++++++++++++++ pip_build.py | 38 ++++++++++++++++++++++----- 3 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/nightly.yml diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 6f1f1328b3..c251e32280 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -3,6 +3,7 @@ name: Tests on: push: pull_request: + workflow_call: release: types: [created] @@ -10,7 +11,7 @@ permissions: contents: read jobs: - test: + keras2: name: Test the code with tf.keras runs-on: ubuntu-latest steps: diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000000..677a641658 --- /dev/null +++ b/.github/workflows/nightly.yml @@ -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 diff --git a/pip_build.py b/pip_build.py index d625dea418..24ad3799dd 100644 --- a/pip_build.py +++ b/pip_build.py @@ -28,6 +28,7 @@ ``` """ import argparse +import datetime import glob import os import pathlib @@ -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): + """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( @@ -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") @@ -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) From aaa62ad58c11273bc7e6d75cd5b8161d36d0495a Mon Sep 17 00:00:00 2001 From: sampathweb <1437573+sampathweb@users.noreply.github.com> Date: Fri, 10 Nov 2023 13:23:50 -0600 Subject: [PATCH 2/2] update version --- keras_cv/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keras_cv/__init__.py b/keras_cv/__init__.py index dded6ded8d..e5fa243940 100644 --- a/keras_cv/__init__.py +++ b/keras_cv/__init__.py @@ -42,4 +42,4 @@ from keras_cv.core import NormalFactorSampler from keras_cv.core import UniformFactorSampler -__version__ = "0.6.4" +__version__ = "0.7.0"