Skip to content

Commit a932095

Browse files
authored
Keras nlp shim (#1853)
* Add a shim package for keras_nlp * Fix pip_build.py to build shim package * Fix up our publishing process to publish keras-hub and keras-nlp * Fix lint
1 parent 9676061 commit a932095

File tree

10 files changed

+230
-120
lines changed

10 files changed

+230
-120
lines changed

.github/workflows/nightly.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ jobs:
4141
- name: Build wheel file
4242
run: |
4343
python pip_build.py --nightly
44-
- name: Publish to PyPI
44+
- name: Publish KerasHub Nightly to PyPI
4545
uses: pypa/gh-action-pypi-publish@release/v1
4646
with:
47+
password: ${{ secrets.PYPI_NIGHTLY_API_TOKEN_HUB }}
48+
verbose: true
49+
- name: Publish KerasNLP Nightly to PyPI
50+
uses: pypa/gh-action-pypi-publish@release/v1
51+
with:
52+
packages-dir: keras_nlp/dist/
4753
password: ${{ secrets.PYPI_NIGHTLY_API_TOKEN }}
48-
packages-dir: dist/
4954
verbose: true

.github/workflows/publish-hub-to-pypi.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/publish-to-pypi.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ jobs:
3333
- name: Build a binary wheel and a source tarball
3434
run: >-
3535
python pip_build.py
36-
- name: Publish distribution to PyPI
36+
- name: Publish KerasHub to PyPI
3737
if: startsWith(github.ref, 'refs/tags')
3838
uses: pypa/gh-action-pypi-publish@release/v1
3939
with:
40-
user: __token__
40+
password: ${{ secrets.PYPI_API_TOKEN_HUB }}
41+
verbose: true
42+
- name: Publish KerasNLP to PyPI
43+
uses: pypa/gh-action-pypi-publish@release/v1
44+
with:
45+
packages-dir: keras_nlp/dist/
4146
password: ${{ secrets.PYPI_API_TOKEN }}
47+
verbose: true

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ __pycache__/
77
*.swp
88
*.swo
99

10-
keras_hub.egg-info/
10+
*.egg-info/
1111
dist/
1212

1313
.coverage

keras_hub/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
"""DO NOT EDIT.
15-
16-
This file was autogenerated. Do not edit it by hand,
17-
since your modifications would be overwritten.
18-
"""
19-
2014
import os
2115

2216
# sentencepiece segfaults on some version of tensorflow if tf is imported first.

keras_nlp/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# KerasNLP: Multi-framework NLP Models
2+
3+
KerasNLP has renamed to KerasHub! Read the announcement
4+
[here](https://github.com/keras-team/keras-nlp/issues/1831).
5+
6+
This directory contains a shim package for `keras-nlp` so that the old style
7+
`pip install keras-nlp` and `import keras_nlp` continue to work.

keras_nlp/keras_nlp/__init__.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2024 The KerasHub Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import os
15+
16+
# Add everything in /api/ to the module search path.
17+
import keras_hub
18+
19+
# Import everything from /api/ into keras.
20+
from keras_hub.api import * # noqa: F403
21+
from keras_hub.api import __version__ # Import * ignores names start with "_".
22+
23+
__path__.extend(keras_hub.__path__) # noqa: F405
24+
# Don't pollute namespace.
25+
del keras_hub
26+
del os
27+
28+
29+
# Never autocomplete `.src` or `.api` on an imported keras object.
30+
def __dir__():
31+
keys = dict.fromkeys((globals().keys()))
32+
keys.pop("src")
33+
keys.pop("api")
34+
return list(keys)
35+
36+
37+
# Don't import `.src` or `.api` during `from keras import *`.
38+
__all__ = [
39+
name
40+
for name in globals().keys()
41+
if not (name.startswith("_") or name in ("src", "api"))
42+
]

keras_nlp/setup.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2024 The KerasHub Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Setup script."""
16+
17+
import os
18+
import pathlib
19+
20+
from setuptools import find_packages
21+
from setuptools import setup
22+
23+
24+
def read(rel_path):
25+
here = os.path.abspath(os.path.dirname(__file__))
26+
with open(os.path.join(here, rel_path)) as fp:
27+
return fp.read()
28+
29+
30+
def get_version(rel_path):
31+
for line in read(rel_path).splitlines():
32+
if line.startswith("__version__"):
33+
delim = '"' if '"' in line else "'"
34+
return line.split(delim)[1]
35+
raise RuntimeError("Unable to find version string.")
36+
37+
38+
HERE = pathlib.Path(__file__).parent
39+
README = (HERE / "README.md").read_text()
40+
PARENT = HERE.parent
41+
VERSION = get_version(PARENT / "keras_hub" / "src" / "version_utils.py")
42+
43+
setup(
44+
name="keras-nlp",
45+
description=(
46+
"Industry-strength Natural Language Processing extensions for Keras."
47+
),
48+
long_description=README,
49+
long_description_content_type="text/markdown",
50+
version=VERSION,
51+
url="https://github.com/keras-team/keras-nlp",
52+
author="Keras team",
53+
author_email="[email protected]",
54+
license="Apache License 2.0",
55+
install_requires=[
56+
f"keras-hub=={VERSION}",
57+
],
58+
# Supported Python versions
59+
python_requires=">=3.9",
60+
classifiers=[
61+
"Development Status :: 3 - Alpha",
62+
"Programming Language :: Python :: 3",
63+
"Programming Language :: Python :: 3.9",
64+
"Programming Language :: Python :: 3.10",
65+
"Programming Language :: Python :: 3.11",
66+
"Programming Language :: Python :: 3 :: Only",
67+
"Operating System :: Unix",
68+
"Operating System :: Microsoft :: Windows",
69+
"Operating System :: MacOS",
70+
"Intended Audience :: Science/Research",
71+
"Topic :: Scientific/Engineering",
72+
"Topic :: Software Development",
73+
],
74+
packages=find_packages(exclude=("*_test.py",)),
75+
)

0 commit comments

Comments
 (0)