Skip to content

Commit

Permalink
Add a shim package for keras_nlp
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdangerw committed Sep 19, 2024
1 parent ebf79d3 commit e95bca6
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 7 deletions.
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.
41 changes: 41 additions & 0 deletions keras_nlp/keras_nlp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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

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

# Add everything in /api/ to the module search path.
import keras_hub
__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"))
]
78 changes: 78 additions & 0 deletions keras_nlp/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# 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
if os.path.exists(PARENT / "keras_hub" / "version_utils.py"):
VERSION = get_version(PARENT / "keras_hub" / "version_utils.py")
else:
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",)),
)

0 comments on commit e95bca6

Please sign in to comment.