linter.sh 1.38 KB
Newer Older
facebook-github-bot's avatar
facebook-github-bot committed
1
#!/bin/bash -e
Patrick Labatut's avatar
Patrick Labatut committed
2
3
4
5
6
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
facebook-github-bot's avatar
facebook-github-bot committed
7
8
9
10
11
12

# 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'")'
13
14
15
16
  PYTHON=false
  command -v python > /dev/null && PYTHON=python
  command -v python3 > /dev/null && PYTHON=python3
  ${PYTHON} -c "${code}" 2> /dev/null
facebook-github-bot's avatar
facebook-github-bot committed
17
18
19
20
21
22
} || {
  echo "Linter requires black 19.3b0 or higher!"
  exit 1
}

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
23
DIR=$(dirname "${DIR}")
facebook-github-bot's avatar
facebook-github-bot committed
24
25
26
27
28

echo "Running isort..."
isort -y -sp "${DIR}"

echo "Running black..."
29
black "${DIR}"
facebook-github-bot's avatar
facebook-github-bot committed
30
31

echo "Running flake..."
32
flake8 "${DIR}" || true
facebook-github-bot's avatar
facebook-github-bot committed
33
34

echo "Running clang-format ..."
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
35
36
37
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

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
38
# Run arc and pyre internally only.
39
if [[ -f "${DIR}/tests/TARGETS" ]]
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
40
then
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
41
42
  (cd "${DIR}"; command -v arc > /dev/null && arc lint) || true

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
43
44
45
46
  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