diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 561ac3c783..0e1146914c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -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 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 32c3255325..1bf1b1d516 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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" } diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 4141fd80d9..889072c91f 100644 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -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 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..c90dcc241c --- /dev/null +++ b/pyproject.toml @@ -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 diff --git a/setup.cfg b/setup.cfg index 7ca2e4df39..5b520dcb3d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 @@ -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 diff --git a/shell/format.sh b/shell/format.sh index 08750a0a29..be0da0303f 100755 --- a/shell/format.sh +++ b/shell/format.sh @@ -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 @@ -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} diff --git a/shell/lint.sh b/shell/lint.sh index 9a103dd11c..7455f6edc4 100755 --- a/shell/lint.sh +++ b/shell/lint.sh @@ -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