Repository: keras-team/keras-nlp
Pull request #8 (2021-12-16 00:59:43)

Tooling and setup for keras-nlp
This adds additional tooling and setup for ther keras-nlp project, mainly copied over from the keras-tuner configs.


Patch:
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
new file mode 100644
index 00000000..561ac3c7
--- /dev/null
+++ b/.devcontainer/Dockerfile
@@ -0,0 +1,4 @@
+FROM tensorflow/tensorflow:latest
+RUN apt-get -y update
+RUN apt-get -y install git vim
+COPY setup.sh /setup.sh
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
new file mode 100644
index 00000000..32c32553
--- /dev/null
+++ b/.devcontainer/devcontainer.json
@@ -0,0 +1,5 @@
+{
+    "dockerFile": "Dockerfile",
+    "postCreateCommand": "sh /setup.sh",
+    "extensions": ["ms-python.python"]
+}
diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh
new file mode 100644
index 00000000..4141fd80
--- /dev/null
+++ b/.devcontainer/setup.sh
@@ -0,0 +1,3 @@
+pip install -e ".[tests]"
+echo "sh shell/lint.sh" > .git/hooks/pre-commit
+chmod a+x .git/hooks/pre-commit
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 00000000..b4ddf6fa
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,30 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: ''
+labels: bug
+assignees: ''
+
+---
+
+**Describe the bug**
+<!---
+A clear and concise description of what the bug is.
+-->
+
+**To Reproduce**
+<!---
+Provide a link to a [Colab Notebook](https://research.google.com/colaboratory/), which reproduces the bug.
+-->
+
+**Expected behavior**
+<!---
+A clear and concise description of what you expected to happen.
+-->
+
+**Additional context**
+<!---
+Add any other context about the problem here.
+-->
+
+**Would you like to help us fix it?**
diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md
new file mode 100644
index 00000000..48d5f81f
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/custom.md
@@ -0,0 +1,10 @@
+---
+name: Custom issue template
+about: Describe this issue template's purpose here.
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
new file mode 100644
index 00000000..d0436494
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -0,0 +1,28 @@
+---
+name: Feature request
+about: Suggest an idea for this project
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+**Is your feature request related to a problem? Please describe.**
+<!---
+A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
+-->
+
+**Describe the solution you'd like**
+<!---
+A clear and concise description of what you want to happen.
+-->
+
+**Describe alternatives you've considered**
+<!---
+A clear and concise description of any alternative solutions or features you've considered.
+-->
+
+**Additional context**
+<!---
+Add any other context or screenshots about the feature request here.
+-->
diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml
new file mode 100644
index 00000000..cd852986
--- /dev/null
+++ b/.github/workflows/actions.yml
@@ -0,0 +1,66 @@
+name: Tests
+
+on:
+  push:
+  pull_request:
+  release:
+    types: [created]
+jobs:
+  build:
+    name: Run tests
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [windows-latest, ubuntu-latest]
+    steps:
+      - uses: actions/checkout@v2
+      - name: Set up Python 3.7
+        uses: actions/setup-python@v1
+        with:
+          python-version: 3.7
+      - 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: |
+          pip install tensorflow
+          pip install -e ".[tests]" --progress-bar off --upgrade
+      - name: Test with pytest
+        run: |
+          pytest --cov=keras_nlp --cov-report xml:coverage.xml
+  format:
+    name: Check the code format
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: Set up Python 3.7
+        uses: actions/setup-python@v1
+        with:
+          python-version: 3.7
+      - 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: |
+          pip install tensorflow
+          pip install -e ".[tests]" --progress-bar off --upgrade
+      - name: Lint
+        run: bash shell/lint.sh
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
new file mode 100644
index 00000000..47759d54
--- /dev/null
+++ b/.github/workflows/nightly.yml
@@ -0,0 +1,37 @@
+name: Test TF Nightly
+
+on:
+  schedule:
+    - cron: '0 0 * * *'
+  push:
+    branches: [ master ]
+
+jobs:
+  build:
+    name: Run tests
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: Set up Python 3.7
+        uses: actions/setup-python@v1
+        with:
+          python-version: 3.7
+      - 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: |
+          pip install tf-nightly --progress-bar off --upgrade
+          pip install -e ".[tests]" --progress-bar off --upgrade
+      - name: Test with pytest
+        run: |
+          pytest --cov=keras_nlp --cov-report xml:coverage.xml
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..588785e9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,13 @@
+# Python temp files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# Vim temp files
+*.swp
+*.swo
+
+keras_nlp.egg-info/
+
+.coverage
+.coverage.*
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 00000000..985e3b3b
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+    "python.testing.pytestEnabled": true
+}
diff --git a/keras_nlp/LICENSE b/keras_nlp/LICENSE
index 8ab8e7ea..7dde2477 100644
--- a/keras_nlp/LICENSE
+++ b/keras_nlp/LICENSE
@@ -1,4 +1,4 @@
-Copyright 2021, KerasCV authors. All rights reserved.
+Copyright 2021, KerasNLP authors. All rights reserved.
 
                                  Apache License
                            Version 2.0, January 2004
@@ -188,7 +188,7 @@ Copyright 2021, KerasCV authors. All rights reserved.
       same "printed page" as the copyright notice for easier
       identification within third-party archives.
 
-   Copyright 2021, KerasCV authors.
+   Copyright 2021, KerasNLP authors.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
diff --git a/keras_nlp/__init__.py b/keras_nlp/__init__.py
new file mode 100644
index 00000000..4e635679
--- /dev/null
+++ b/keras_nlp/__init__.py
@@ -0,0 +1,15 @@
+# Copyright 2021 The KerasNLP 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.
+
+__version__ = "master"
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 00000000..cd495ee5
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,52 @@
+[metadata]
+version = attr: keras_nlp.__version__
+
+[tool:pytest]
+filterwarnings =
+    error
+    ignore::DeprecationWarning
+    ignore::ImportWarning
+    ignore::RuntimeWarning
+    ignore::PendingDeprecationWarning
+    ignore::FutureWarning
+
+addopts=-vv
+
+# Do not run tests in the build folder
+norecursedirs= build
+
+[isort]
+known_first_party = keras_nlp,tests
+default_section = THIRDPARTY
+line_length = 80
+
+[coverage:report]
+exclude_lines =
+    pragma: no cover
+    @abstract
+    raise NotImplementedError
+omit = *_test.py
+
+[flake8]
+
+ignore =
+    # Conflicts with black
+    E203
+    # defaults flake8 ignores
+    E121,E123,E126,E226,E24,E704,W503,W504
+    # Function name should be lowercase
+    N802
+    # lowercase ... imported as non lowercase
+    # Useful to ignore for "import keras.backend as K"
+    N812
+    # do not use bare 'except'
+    E722
+
+exclude =
+    *_pb2.py
+    *_pb2_grpc.py
+
+#imported but unused in __init__.py, that's ok.
+per-file-ignores = **/__init__.py:F401
+
+max-line-length = 80
diff --git a/setup.py b/setup.py
index 2a2bdfaf..baa2638d 100644
--- a/setup.py
+++ b/setup.py
@@ -19,8 +19,9 @@ from setuptools import setup
 
 setup(
     name="keras-nlp",
-    description = 
-        "Industry-strength Natural Language Processing extensions for Keras.",
+    description=(
+        "Industry-strength Natural Language Processing extensions for Keras."
+    ),
     url="https://github.com/keras-team/keras-nlp",
     author="Keras team",
     author_email="keras-nlp@google.com",
@@ -29,7 +30,15 @@ setup(
     # download of the gpu version or the cpu version.
     # users should install it manually.
     install_requires=["packaging", "tensorflow", "numpy"],
-    extras_require={"tests": ["flake8", "isort", "black",],},
+    extras_require={
+        "tests": [
+            "black",
+            "flake8",
+            "isort",
+            "pytest",
+            "pytest-cov",
+        ],
+    },
     classifiers=[
         "Programming Language :: Python",
         "Programming Language :: Python :: 3.7",
diff --git a/shell/copyright.txt b/shell/copyright.txt
new file mode 100644
index 00000000..de522978
--- /dev/null
+++ b/shell/copyright.txt
@@ -0,0 +1,14 @@
+# Copyright 2021 The KerasNLP 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.
+
diff --git a/shell/format.sh b/shell/format.sh
new file mode 100755
index 00000000..44a08711
--- /dev/null
+++ b/shell/format.sh
@@ -0,0 +1,13 @@
+isort --sl .
+black --line-length 80 .
+
+for i in $(find keras_nlp tests -name '*.py') # or whatever other pattern...
+do
+  if ! grep -q Copyright $i
+  then
+    echo $i
+    cat shell/copyright.txt $i >$i.new && mv $i.new $i
+  fi
+done
+
+flake8 .
diff --git a/shell/lint.sh b/shell/lint.sh
new file mode 100755
index 00000000..e46a464b
--- /dev/null
+++ b/shell/lint.sh
@@ -0,0 +1,26 @@
+isort --sl -c .
+if ! [ $? -eq 0 ]
+then
+  echo "Please run \"sh shell/format.sh\" to format the code."
+  exit 1
+fi
+flake8 .
+if ! [ $? -eq 0 ]
+then
+  echo "Please fix the code style issue."
+  exit 1
+fi
+black --check --line-length 80 .
+if ! [ $? -eq 0 ]
+then
+  echo "Please run \"sh shell/format.sh\" to format the code."
+    exit 1
+fi
+for i in $(find keras_nlp tests -name '*.py') # or whatever other pattern...
+do
+  if ! grep -q Copyright $i
+  then
+    echo "Please run \"sh shell/format.sh\" to format the code."
+    exit 1
+  fi
+done


Test patch:
diff --git a/keras_nlp/integration_tests/__init__.py b/keras_nlp/integration_tests/__init__.py
new file mode 100644
index 00000000..e6f8e2a8
--- /dev/null
+++ b/keras_nlp/integration_tests/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2021 The KerasNLP 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.
diff --git a/keras_nlp/integration_tests/import_test.py b/keras_nlp/integration_tests/import_test.py
new file mode 100644
index 00000000..49794f99
--- /dev/null
+++ b/keras_nlp/integration_tests/import_test.py
@@ -0,0 +1,20 @@
+# Copyright 2021 The KerasNLP 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 keras_nlp
+
+
+# Basic test to make sure the library can be imported.
+def test_import():
+    assert keras_nlp.__version__