Repository navigation
Expand file tree
/
Copy pathsetenv.sh
More file actions
executable file
·134 lines (106 loc) · 4.73 KB
/
Copy pathsetenv.sh
File metadata and controls
executable file
·134 lines (106 loc) · 4.73 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#
# Configure the local (thin) client built with `thin_client.../build.py`.
#
# NOTE: This file needs to be sourced and not executed. For this reason doesn't
# use bash and doesn't have +x permissions.
#
# Print the script path.
SCRIPT_PATH=$(realpath "${BASH_SOURCE[0]:-$0}")
echo "##> $SCRIPT_PATH"
GIT_ROOT_DIR=$(git rev-parse --show-toplevel)
echo "GIT_ROOT_DIR=$GIT_ROOT_DIR"
# #############################################################################
# Thin client utils.
# #############################################################################
SOURCE_PATH=$(find $GIT_ROOT_DIR -name "thin_client_utils.sh" -type f 2>/dev/null | head -1)
# Check if file was found.
if [ -n "$SOURCE_PATH" ]; then
echo "Thin client utils found at: $SOURCE_PATH"
else
echo -e "ERROR: File 'thin_client_utils.sh' not found in current directory" >&2
kill -INT $$
fi;
source $SOURCE_PATH
# #############################################################################
# Repo config.
# #############################################################################
echo "##> Parsing repo config"
echo $(pwd)
eval $(parse_yaml repo_config.yaml "REPO_CONF_")
# Print all REPO_CONF_ variables.
set | grep "^REPO_CONF_" | while read line; do
echo "$line"
done
# TODO(heanh): Remove this once all repos are migrated to the new config.
# Allow backward compatibility with old repo config that use integer value.
if [ "$REPO_CONF_runnable_dir_info_use_helpers_as_nested_module" = "1" ]; then
REPO_CONF_runnable_dir_info_use_helpers_as_nested_module=True
fi
# #############################################################################
# Thin environment.
# #############################################################################
if [ "$REPO_CONF_runnable_dir_info_use_helpers_as_nested_module" = "True" ]; then
# We can reuse the thin environment of `helpers` or create a new one.
VENV_TAG=$REPO_CONF_runnable_dir_info_venv_tag
else
VENV_TAG="helpers"
fi
# - Activate environment
activate_venv $VENV_TAG
# #############################################################################
# helpers_root path.
# #############################################################################
if [ "$REPO_CONF_runnable_dir_info_use_helpers_as_nested_module" = "True" ]; then
HELPERS_ROOT_DIR=$(find ${GIT_ROOT_DIR} \( -path '*/.git' -o -path '*/.mypy_cache' \) -prune -o -name "helpers_root" -print | head -n 1)
else
HELPERS_ROOT_DIR="${GIT_ROOT_DIR}"
fi
echo "HELPERS_ROOT_DIR=$HELPERS_ROOT_DIR"
dassert_dir_exists $HELPERS_ROOT_DIR
if [ "$REPO_CONF_runnable_dir_info_use_helpers_as_nested_module" = "True" ]; then
# Set vars for helpers_root.
set_path "${HELPERS_ROOT_DIR}/dev_scripts_helpers"
fi
# #############################################################################
# dev_scripts_XYZ path.
# #############################################################################
CURR_DIR=$(pwd)
DEV_SCRIPT_DIR="${CURR_DIR}/dev_scripts_${REPO_CONF_runnable_dir_info_dir_suffix}"
echo "DEV_SCRIPT_DIR=$DEV_SCRIPT_DIR"
dassert_dir_exists $DEV_SCRIPT_DIR
# Set basic vars.
set_path $DEV_SCRIPT_DIR
# #############################################################################
# PYTHONPATH.
# #############################################################################
set_pythonpath $HELPERS_ROOT_DIR
# #############################################################################
# File permission.
# #############################################################################
# Give permissions to read / write to user and group.
umask 002
# Remove write permissions for symlinked files to prevent accidental
# modifications before starting to develop.
# TODO(gp): This creates more problems than it solves.
#set_symlink_permissions .
#################################################################################
# Install pre-commit hooks.
#################################################################################
# We want to install git hooks by default unless the user has explicitly
# disabled them in the repo config.
if [ "$REPO_CONF_repo_info_enable_git_commit_hook" = "False" ]; then
echo "Skipping git hooks installation because enable_git_commit_hook=False"
$HELPERS_ROOT_DIR/dev_scripts_helpers/git/git_hooks/install_hooks.py --action remove
else
echo "Installing git hooks"
$HELPERS_ROOT_DIR/dev_scripts_helpers/git/git_hooks/install_hooks.py --action install
fi
# #############################################################################
# Project configuration.
# #############################################################################
# Set CSFY environment variables.
set_csfy_env_vars
# Set specific configuration of the project.
configure_specific_project
print_env_signature
echo -e "${INFO}: ${SCRIPT_PATH} successful"