pytorch3d/dev/linter.sh
Patrick Labatut eb512ffde3 Enable black + isort fbsource linter
Summary:
Enable `black` + `isort` (via `pyfmt`) i.e. `BLACK` fbsource linter.

NOTE: the `BLACK` fbsource linter (and `black` itself) is (by design) ***not*** configurable. This forces aligning the existing options used by the tools invoked in `dev/linter.sh` (for 3rd party developers) with `BLACK` fbsource linting. Without this reconciliation, the different linters (used internally or by 3rd party developers) would simply conflict with each other resulting in artificial back-and-forth changes (for instance line width which `BLACK` forces to 88 characters).

Reviewed By: nikhilaravi

Differential Revision: D20558374

fbshipit-source-id: 614fa00664f8eb9d2de7438c29b807dfbf36ad20
2020-03-29 14:51:02 -07:00

40 lines
1.1 KiB
Bash
Executable File

#!/bin/bash -e
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
# Run this script at project root by "./dev/linter.sh" before you commit
{
V=$(black --version|cut '-d ' -f3)
code='import distutils.version; assert "19.3" < distutils.version.LooseVersion("'$V'")'
python -c "${code}" 2> /dev/null
} || {
echo "Linter requires black 19.3b0 or higher!"
exit 1
}
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR=$(dirname "${DIR}")
echo "Running isort..."
isort -y -sp "${DIR}"
echo "Running black..."
black "${DIR}"
echo "Running flake..."
flake8 "${DIR}"
echo "Running clang-format ..."
clangformat=$(command -v clang-format-8 || echo clang-format)
find "${DIR}" -regex ".*\.\(cpp\|c\|cc\|cu\|cuh\|cxx\|h\|hh\|hpp\|hxx\|tcc\|mm\|m\)" -print0 | xargs -0 "${clangformat}" -i
# (cd "${DIR}"; command -v arc > /dev/null && arc lint) || true
# Run pyre internally only.
if [[ -f tests/TARGETS ]]
then
echo "Running pyre..."
echo "To restart/kill pyre server, run 'pyre restart' or 'pyre kill' in fbcode/"
( cd ~/fbsource/fbcode; pyre -l vision/fair/pytorch3d/ )
fi