linter.sh 1.13 KB
Newer Older
facebook-github-bot's avatar
facebook-github-bot committed
1
#!/bin/bash -e
2
# Copyright (c) Meta Platforms, Inc. and affiliates.
Patrick Labatut's avatar
Patrick Labatut committed
3
4
5
6
# 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

# Run this script at project root by "./dev/linter.sh" before you commit

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

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
13
14
15
16
17
18
19
20
if [[ -f "${DIR}/tests/TARGETS" ]]
then
  pyfmt "${DIR}"
else
# run usort externally only
  echo "Running usort..."
  usort  "${DIR}"
fi
facebook-github-bot's avatar
facebook-github-bot committed
21
22

echo "Running black..."
23
black "${DIR}"
facebook-github-bot's avatar
facebook-github-bot committed
24
25

echo "Running flake..."
26
flake8 "${DIR}" || true
facebook-github-bot's avatar
facebook-github-bot committed
27
28

echo "Running clang-format ..."
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
29
30
31
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
32
# Run arc and pyre internally only.
33
if [[ -f "${DIR}/tests/TARGETS" ]]
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
34
then
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
35
36
  (cd "${DIR}"; command -v arc > /dev/null && arc lint) || true

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
37
38
39
40
  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