Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

pre-commit.sh 1.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  1. #!/bin/sh
  2. #
  3. # Git pre-commit script that runs our unit tests as needed.
  4. #
  5. # To install:
  6. # ln -s ../../pre-commit.sh .git/hooks/pre-commit
  7. # Redirect output to stderr.
  8. exec 1>&2
  9. function log() {
  10. echo 'pre-commit:' $@
  11. }
  12. function dirModified() {
  13. # sets is_modified if files in directory $1 have been modified.
  14. changed_files="$(git diff --cached --name-only --diff-filter=ACM $1 | wc -l | tr -d '[:space:]')"
  15. if [ "$changed_files" != "0" ]; then
  16. is_modified=true
  17. else
  18. is_modified=false
  19. fi
  20. if [ "$is_modified" = true ]; then
  21. log Modifications detected in "$1"
  22. fi
  23. }
  24. # cd to root (may not need this)
  25. ROOT_DIR="$(git rev-parse --show-toplevel)"
  26. cd "$ROOT_DIR"
  27. log 'Running pre-commit checks, pass --no-verify to "git commit" to'
  28. log 'disable.'
  29. echo
  30. dirModified wandb
  31. wandb_modified="$is_modified"
  32. # Unset all the env variables that are set during git commit hooks,
  33. # which break the tests currently.
  34. unset GIT_DIR
  35. unset GIT_INDEX_FILE
  36. unset GIT_AUTHOR_DATE
  37. unset GIT_AUTHOR_NAME
  38. unset GIT_PREFIX
  39. unset GIT_AUTHOR_EMAIL
  40. if [ "$wandb_modified" = true ]; then
  41. log "Running wandb tests."
  42. pytest
  43. if [ $? -ne 0 ]; then
  44. wandb_failed=true
  45. fi
  46. fi
  47. failed=false
  48. if [ "$wandb_failed" = true ]; then
  49. log "wandb tests failed."
  50. log "\"cd $ROOT_DIR; pytest\" to run the tests."
  51. failed=true
  52. fi
  53. if [ "$failed" = true ]; then
  54. exit 1
  55. else
  56. log "pre-commit check success"
  57. fi
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...