Skip to content

Commit

Permalink
Keras nlp shim (#1853)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mattdangerw authored Sep 20, 2024
1 parent 9676061 commit a932095
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 120 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ jobs:
- name: Build wheel file
run: |
python pip_build.py --nightly
- name: Publish to PyPI
- name: Publish KerasHub Nightly to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_NIGHTLY_API_TOKEN_HUB }}
verbose: true
- name: Publish KerasNLP Nightly to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: keras_nlp/dist/
password: ${{ secrets.PYPI_NIGHTLY_API_TOKEN }}
packages-dir: dist/
verbose: true
43 changes: 0 additions & 43 deletions .github/workflows/publish-hub-to-pypi.yml

This file was deleted.

10 changes: 8 additions & 2 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ jobs:
- name: Build a binary wheel and a source tarball
run: >-
python pip_build.py
- name: Publish distribution to PyPI
- name: Publish KerasHub to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN_HUB }}
verbose: true
- name: Publish KerasNLP to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: keras_nlp/dist/
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ __pycache__/
*.swp
*.swo

keras_hub.egg-info/
*.egg-info/
dist/

.coverage
Expand Down
6 changes: 0 additions & 6 deletions keras_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""DO NOT EDIT.
This file was autogenerated. Do not edit it by hand,
since your modifications would be overwritten.
"""

import os

# sentencepiece segfaults on some version of tensorflow if tf is imported first.
Expand Down
7 changes: 7 additions & 0 deletions keras_nlp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# KerasNLP: Multi-framework NLP Models

KerasNLP has renamed to KerasHub! Read the announcement
[here](https://github.com/keras-team/keras-nlp/issues/1831).

This directory contains a shim package for `keras-nlp` so that the old style
`pip install keras-nlp` and `import keras_nlp` continue to work.
42 changes: 42 additions & 0 deletions keras_nlp/keras_nlp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2024 The KerasHub Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os

# Add everything in /api/ to the module search path.
import keras_hub

# Import everything from /api/ into keras.
from keras_hub.api import * # noqa: F403
from keras_hub.api import __version__ # Import * ignores names start with "_".

__path__.extend(keras_hub.__path__) # noqa: F405
# Don't pollute namespace.
del keras_hub
del os


# Never autocomplete `.src` or `.api` on an imported keras object.
def __dir__():
keys = dict.fromkeys((globals().keys()))
keys.pop("src")
keys.pop("api")
return list(keys)


# Don't import `.src` or `.api` during `from keras import *`.
__all__ = [
name
for name in globals().keys()
if not (name.startswith("_") or name in ("src", "api"))
]
75 changes: 75 additions & 0 deletions keras_nlp/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2024 The KerasHub Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Setup script."""

import os
import pathlib

from setuptools import find_packages
from setuptools import setup


def read(rel_path):
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, rel_path)) as fp:
return fp.read()


def get_version(rel_path):
for line in read(rel_path).splitlines():
if line.startswith("__version__"):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
raise RuntimeError("Unable to find version string.")


HERE = pathlib.Path(__file__).parent
README = (HERE / "README.md").read_text()
PARENT = HERE.parent
VERSION = get_version(PARENT / "keras_hub" / "src" / "version_utils.py")

setup(
name="keras-nlp",
description=(
"Industry-strength Natural Language Processing extensions for Keras."
),
long_description=README,
long_description_content_type="text/markdown",
version=VERSION,
url="https://github.com/keras-team/keras-nlp",
author="Keras team",
author_email="[email protected]",
license="Apache License 2.0",
install_requires=[
f"keras-hub=={VERSION}",
],
# Supported Python versions
python_requires=">=3.9",
classifiers=[
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
"Operating System :: Unix",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
"Topic :: Software Development",
],
packages=find_packages(exclude=("*_test.py",)),
)
Loading

0 comments on commit a932095

Please sign in to comment.