Skip to content

Commit 7874819

Browse files
committed
Hack package build script to rename to keras-hub
This is a temporary way to test out the keras-hub branch. - Does a global rename of all symbols during package build. - Registers the "old" name on symbol export for saving compat. - Adds a github action to publish every commit to keras-hub as a new package. - Removes our descriptions on PyPI temporarily, until we want to message this more broadly.
1 parent 18f8880 commit 7874819

File tree

5 files changed

+64
-12
lines changed

5 files changed

+64
-12
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Publish Hub to PyPI
2+
3+
on:
4+
push:
5+
branches:
6+
- keras-hub
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
build-and-publish:
13+
name: Build and publish Hub to PyPI
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: 3.9
21+
- name: Get pip cache dir
22+
id: pip-cache
23+
run: |
24+
python -m pip install --upgrade pip setuptools
25+
echo "::set-output name=dir::$(pip cache dir)"
26+
- name: pip cache
27+
uses: actions/cache@v4
28+
with:
29+
path: ${{ steps.pip-cache.outputs.dir }}
30+
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
31+
restore-keys: |
32+
${{ runner.os }}-pip-
33+
- name: Install dependencies
34+
run: |
35+
pip install -r requirements.txt --progress-bar off
36+
- name: Build a binary wheel and a source tarball
37+
run: >-
38+
python pip_build.py
39+
- name: Publish distribution to PyPI
40+
uses: pypa/gh-action-pypi-publish@release/v1
41+
with:
42+
user: __token__
43+
password: ${{ secrets.PYPI_API_TOKEN_HUB }}

keras_nlp/src/api_export.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424

2525
def maybe_register_serializable(symbol):
2626
if isinstance(symbol, types.FunctionType) or hasattr(symbol, "get_config"):
27+
# We register twice, first with the old name, second with the new name,
28+
# so loading still works under the old name.
29+
# TODO replace compat_package_name with keras-nlp after rename.
30+
compat_name = "compat_package_name"
31+
keras.saving.register_keras_serializable(package=compat_name)(symbol)
2732
keras.saving.register_keras_serializable(package="keras_nlp")(symbol)
2833

2934

keras_nlp/src/utils/preset_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def list_presets(cls):
9999

100100
def list_subclasses(cls):
101101
"""Find all registered subclasses of a class."""
102-
custom_objects = keras.saving.get_custom_objects().values()
102+
# Deduplicate the lists, since we have to register object twice for compat.
103+
custom_objects = set(keras.saving.get_custom_objects().values())
103104
subclasses = []
104105
for x in custom_objects:
105106
if inspect.isclass(x) and x != cls and issubclass(x, cls):

pip_build.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import re
3737
import shutil
3838

39-
package = "keras_nlp"
39+
package = "keras_hub"
4040
build_directory = "tmp_build_dir"
4141
dist_directory = "dist"
4242
to_copy = ["setup.py", "setup.cfg", "README.md"]
@@ -48,15 +48,15 @@ def ignore_files(_, filenames):
4848

4949
def export_version_string(version, is_nightly=False):
5050
"""Export Version and Package Name."""
51+
date = datetime.datetime.now()
52+
version += f".dev{date.strftime('%Y%m%d%H%M%S')}"
5153
if is_nightly:
52-
date = datetime.datetime.now()
53-
version += f".dev{date.strftime('%Y%m%d%H')}"
54-
# Replaces `name="keras-nlp"` in `setup.py` with `keras-nlp-nightly`
54+
# Replaces `name="keras-hub"` in `setup.py` with `keras-hub-nightly`
5555
with open("setup.py") as f:
5656
setup_contents = f.read()
5757
with open("setup.py", "w") as f:
5858
setup_contents = setup_contents.replace(
59-
'name="keras-nlp"', 'name="keras-nlp-nightly"'
59+
'name="keras-hub"', 'name="keras-hub-nightly"'
6060
)
6161
f.write(setup_contents)
6262

@@ -78,11 +78,17 @@ def copy_source_to_build_directory(root_path):
7878
os.chdir(root_path)
7979
os.mkdir(build_directory)
8080
shutil.copytree(
81-
package, os.path.join(build_directory, package), ignore=ignore_files
81+
"keras_nlp", os.path.join(build_directory, package), ignore=ignore_files
8282
)
8383
for fname in to_copy:
8484
shutil.copy(fname, os.path.join(f"{build_directory}", fname))
8585
os.chdir(build_directory)
86+
# TODO: remove all of this when our code is actually renamed in the repo.
87+
os.system("grep -lR 'keras_nlp' . | xargs sed -i 's/keras_nlp/keras_hub/g'")
88+
os.system("grep -lR 'keras-nlp' . | xargs sed -i 's/keras-nlp/keras-hub/g'")
89+
os.system("grep -lR 'KerasNLP' . | xargs sed -i 's/KerasNLP/KerasHub/g'")
90+
os.system("grep -lR 'compat_package_name' . | xargs sed -i 's/compat_package_name/keras_nlp/g'")
91+
8692

8793

8894
def build(root_path, is_nightly=False):

setup.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ def get_version(rel_path):
4444

4545
setup(
4646
name="keras-nlp",
47-
description=(
48-
"Industry-strength Natural Language Processing extensions for Keras."
49-
),
50-
long_description=README,
51-
long_description_content_type="text/markdown",
47+
description="🚧🚧🚧 Work in progress. 🚧🚧🚧 More details soon!",
48+
long_description="🚧🚧🚧 Work in progress. 🚧🚧🚧 More details soon!",
5249
version=VERSION,
5350
url="https://github.com/keras-team/keras-nlp",
5451
author="Keras team",

0 commit comments

Comments
 (0)