Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
FROM tensorflow/tensorflow:latest
RUN apt-get -y update
RUN apt-get -y install git vim
FROM mcr.microsoft.com/vscode/devcontainers/python:3.8
COPY setup.sh /setup.sh
32 changes: 30 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
{
"dockerFile": "Dockerfile",
"postCreateCommand": "sh /setup.sh",
"extensions": ["ms-python.python"]
"customizations": {
"vscode": {
"settings": {
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.pylintEnabled": false,
"python.testing.pytestEnabled": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"editor.rulers": [
80
]
},
"extensions": [
"ms-python.python",
"ms-python.isort",
"ms-python.flake8",
"ms-python.black-formatter"
]
}
},
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"postCreateCommand": "sh /setup.sh"
}
4 changes: 3 additions & 1 deletion .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pip install -e ".[tests]"
pip install --upgrade pip
pip install -r requirements.txt
pip install -e .
echo "sh shell/lint.sh" > .git/hooks/pre-commit
chmod a+x .git/hooks/pre-commit
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool.black]
line-length = 80

[tool.isort]
profile = "black"
force_single_line = "True"
known_first_party = ["keras_nlp", "tests"]
default_section = "THIRDPARTY"
line_length = 80
8 changes: 1 addition & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ addopts=-vv
# Do not run tests in the `build` folders
norecursedirs = build

[isort]
known_first_party = keras_nlp,tests
default_section = THIRDPARTY
line_length = 80
profile = black

[coverage:report]
exclude_lines =
pragma: no cover
Expand Down Expand Up @@ -50,4 +44,4 @@ exclude =
#imported but unused in __init__.py, that's ok.
per-file-ignores = **/__init__.py:F401

max-line-length = 80
max-line-length = 200
6 changes: 3 additions & 3 deletions shell/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
base_dir=$(dirname $(dirname $0))
targets="${base_dir}/*.py ${base_dir}/examples/ ${base_dir}/keras_nlp/ ${base_dir}/tools/"

isort --sp "${base_dir}/setup.cfg" --sl ${targets}
black --line-length 80 ${targets}
isort --sp "${base_dir}/pyproject.toml" ${targets}
black --config "${base_dir}/pyproject.toml" ${targets}

for i in $(find ${targets} -name '*.py'); do
if ! grep -q Copyright $i; then
Expand All @@ -13,4 +13,4 @@ for i in $(find ${targets} -name '*.py'); do
fi
done

flake8 --config "${base_dir}/setup.cfg" --max-line-length=200 ${targets}
flake8 --config "${base_dir}/setup.cfg" ${targets}
6 changes: 3 additions & 3 deletions shell/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
base_dir=$(dirname $(dirname $0))
targets="${base_dir}/*.py ${base_dir}/examples/ ${base_dir}/keras_nlp/ ${base_dir}/tools/"

isort --sp "${base_dir}/setup.cfg" --sl -c ${targets}
isort --sp "${base_dir}/pyproject.toml" -c ${targets}
if ! [ $? -eq 0 ]; then
echo "Please run \"./shell/format.sh\" to format the code."
exit 1
fi

flake8 --config "${base_dir}/setup.cfg" --max-line-length=200 ${targets}
flake8 --config "${base_dir}/setup.cfg" ${targets}
if ! [ $? -eq 0 ]; then
echo "Please fix the code style issue."
exit 1
fi

black --check --line-length 80 ${targets}
black --config "${base_dir}/pyproject.toml" --check ${targets}
if ! [ $? -eq 0 ]; then
echo "Please run \"./shell/format.sh\" to format the code."
exit 1
Expand Down