Skip to content

Commit 2613e12

Browse files
authored
Merge pull request #3263 from casperdcl/shfmt
lint:beautysh pre-commit hook
2 parents d864caf + b0b69ce commit 2613e12

17 files changed

+225
-228
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ repos:
99
hooks:
1010
- id: flake8
1111
language_version: python3
12+
- repo: https://github.com/lovesegfault/beautysh
13+
rev: master
14+
hooks:
15+
- id: beautysh
16+
language_version: python3
17+
args: [-i, '2'] # 2-space indentaion

scripts/build_package.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ set -e
44
set -x
55

66
if [ ! -d "dvc" ]; then
7-
echo "Please run this script from repository root" >&2
8-
exit 1
7+
echo "Please run this script from repository root" >&2
8+
exit 1
99
fi
1010

11-
echo 'PKG = "pip"' > dvc/utils/build.py
11+
echo 'PKG = "pip"' >dvc/utils/build.py
1212

1313
python setup.py sdist
1414
python setup.py bdist_wheel --universal
1515

1616
# Make sure we have a correct version
1717
if [[ -n "$TRAVIS_TAG" ]]; then
18-
pip uninstall -y dvc
19-
if which dvc; then
20-
echo "ERROR: dvc command still exists! Unable to verify dvc version." >&2
21-
exit 1
22-
fi
23-
pip install dist/dvc-*.whl
24-
if [[ "$(dvc --version)" != "$TRAVIS_TAG" ]]; then
25-
echo "ERROR: 'dvc --version'$(dvc -V) doesn't match '$TRAVIS_TAG'" >&2
26-
exit 1
27-
fi
28-
pip uninstall -y dvc
18+
pip uninstall -y dvc
19+
if which dvc; then
20+
echo "ERROR: dvc command still exists! Unable to verify dvc version." >&2
21+
exit 1
22+
fi
23+
pip install dist/dvc-*.whl
24+
if [[ "$(dvc --version)" != "$TRAVIS_TAG" ]]; then
25+
echo "ERROR: 'dvc --version'$(dvc -V) doesn't match '$TRAVIS_TAG'" >&2
26+
exit 1
27+
fi
28+
pip uninstall -y dvc
2929
fi

scripts/build_posix.sh

Lines changed: 93 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ set -e
44
set -x
55

66
if [[ "$(uname)" == 'Linux' ]]; then
7-
INSTALL_DIR=usr
8-
FPM_FLAGS=
7+
INSTALL_DIR=usr
8+
FPM_FLAGS=
99
else
10-
INSTALL_DIR=usr/local
11-
FPM_FLAGS='--osxpkg-identifier-prefix com.iterative'
12-
FPM_FLAGS+=' --after-install scripts/fpm/after-install.sh'
13-
FPM_FLAGS+=' --after-remove scripts/fpm/after-remove.sh'
10+
INSTALL_DIR=usr/local
11+
FPM_FLAGS='--osxpkg-identifier-prefix com.iterative'
12+
FPM_FLAGS+=' --after-install scripts/fpm/after-install.sh'
13+
FPM_FLAGS+=' --after-remove scripts/fpm/after-remove.sh'
1414
fi
1515

1616
BUILD_DIR=build
@@ -21,129 +21,121 @@ LIB_DIR=$BUILD_DIR/$INSTALL_DIR/lib
2121
FPM_PACKAGE_DIRS="usr"
2222
ZSH_CMPLT_DIR=usr/share/zsh/site-functions/_dvc
2323
if [[ "$(uname)" == 'Linux' ]]; then
24-
BASH_CMPLT_DIR=etc/bash_completion.d
25-
FPM_PACKAGE_DIRS="$FPM_PACKAGE_DIRS etc"
24+
BASH_CMPLT_DIR=etc/bash_completion.d
25+
FPM_PACKAGE_DIRS="$FPM_PACKAGE_DIRS etc"
2626
else
27-
BASH_CMPLT_DIR=usr/local/etc/bash_completion.d
27+
BASH_CMPLT_DIR=usr/local/etc/bash_completion.d
2828
fi
2929

30-
print_error()
31-
{
32-
echo -e "\e[31m$1\e[0m" >&2
30+
print_error() {
31+
echo -e "\e[31m$1\e[0m" >&2
3332
}
3433

3534
if [ ! -d "dvc" ]; then
36-
print_error "Please run this script from repository root"
37-
exit 1
35+
print_error "Please run this script from repository root"
36+
exit 1
3837
fi
3938

4039
trap 'print_error "FAIL"; exit 1' ERR
4140

42-
print_info()
43-
{
44-
echo -e "\e[32m$1\e[0m"
41+
print_info() {
42+
echo -e "\e[32m$1\e[0m"
4543
}
4644

47-
command_exists()
48-
{
49-
command -v $1 > /dev/null 2>&1
45+
command_exists() {
46+
command -v $1 >/dev/null 2>&1
5047
}
5148

52-
fpm_build()
53-
{
54-
print_info "Building $1..."
55-
VERSION=$(python -c "import dvc; from dvc import __version__; print(str(__version__))")
56-
fpm -s dir \
57-
-f \
58-
-t $1 \
59-
--description "$DESC" \
60-
$FPM_FLAGS \
61-
-n dvc \
62-
-v $VERSION \
63-
-C $BUILD_DIR \
64-
$FPM_PACKAGE_DIRS
49+
fpm_build() {
50+
print_info "Building $1..."
51+
VERSION=$(python -c "import dvc; from dvc import __version__; print(str(__version__))")
52+
fpm -s dir \
53+
-f \
54+
-t $1 \
55+
--description "$DESC" \
56+
$FPM_FLAGS \
57+
-n dvc \
58+
-v $VERSION \
59+
-C $BUILD_DIR \
60+
$FPM_PACKAGE_DIRS
6561
}
6662

67-
cleanup()
68-
{
69-
print_info "Cleaning up..."
70-
rm -rf build
63+
cleanup() {
64+
print_info "Cleaning up..."
65+
rm -rf build
7166
}
7267

73-
install_dependencies()
74-
{
75-
print_info "Installing fpm..."
76-
if command_exists dnf; then
77-
sudo dnf install ruby-devel gcc make rpm-build
78-
elif command_exists yum; then
79-
sudo yum install ruby-devel gcc make rpm-build
80-
elif command_exists apt-get; then
81-
sudo apt-get update -y
82-
sudo apt-get install ruby-dev build-essential rpm python-pip python-dev
83-
elif command_exists brew; then
84-
brew install ruby
85-
else
86-
echo "Unable to install fpm dependencies" && exit 1
87-
fi
88-
89-
gem install --no-document fpm
90-
91-
# https://github.com/iterative/dvc/issues/2970
92-
gem uninstall -i /Users/travis/.rvm/gems/ruby-2.4.3@global rubygems-bundler
93-
94-
print_info "Installing requirements..."
95-
pip install .[all]
96-
pip install -r scripts/build-requirements.txt
68+
install_dependencies() {
69+
print_info "Installing fpm..."
70+
if command_exists dnf; then
71+
sudo dnf install ruby-devel gcc make rpm-build
72+
elif command_exists yum; then
73+
sudo yum install ruby-devel gcc make rpm-build
74+
elif command_exists apt-get; then
75+
sudo apt-get update -y
76+
sudo apt-get install ruby-dev build-essential rpm python-pip python-dev
77+
elif command_exists brew; then
78+
brew install ruby
79+
else
80+
echo "Unable to install fpm dependencies" && exit 1
81+
fi
82+
83+
gem install --no-document fpm
84+
85+
# https://github.com/iterative/dvc/issues/2970
86+
gem uninstall -i /Users/travis/.rvm/gems/ruby-2.4.3@global rubygems-bundler
87+
88+
print_info "Installing requirements..."
89+
pip install .[all]
90+
pip install -r scripts/build-requirements.txt
9791
}
9892

99-
build_dvc()
100-
{
101-
print_info "Building dvc binary..."
102-
pyinstaller \
103-
--additional-hooks-dir $(pwd)/scripts/hooks dvc/__main__.py \
104-
--name dvc \
105-
--distpath $LIB_DIR \
106-
--specpath $BUILD_DIR
107-
108-
$LIB_DIR/dvc/dvc --help
109-
110-
# NOTE: in osxpkg fpm replaces symlinks with actual file that it
111-
# points to, so we need to use after-install hook. See FPM_FLAGS
112-
# above.
113-
if [[ "$(uname)" == 'Linux' ]]; then
114-
mkdir -p $BIN_DIR
115-
pushd $BIN_DIR
116-
ln -s ../lib/dvc/dvc dvc
117-
popd
118-
$BIN_DIR/dvc --help
119-
fi
120-
121-
# NOTE: temporarily not adding scripts to mac package. See [1]
122-
# [1] https://github.com/iterative/dvc/issues/2585
123-
if [[ "$(uname)" == 'Linux' ]]; then
124-
mkdir -p $BUILD_DIR/$BASH_CMPLT_DIR
125-
cp scripts/completion/dvc.bash $BUILD_DIR/$BASH_CMPLT_DIR/dvc
126-
127-
mkdir -p $BUILD_DIR/$ZSH_CMPLT_DIR
128-
cp scripts/completion/dvc.zsh $BUILD_DIR/$ZSH_CMPLT_DIR
129-
fi
93+
build_dvc() {
94+
print_info "Building dvc binary..."
95+
pyinstaller \
96+
--additional-hooks-dir $(pwd)/scripts/hooks dvc/__main__.py \
97+
--name dvc \
98+
--distpath $LIB_DIR \
99+
--specpath $BUILD_DIR
100+
101+
$LIB_DIR/dvc/dvc --help
102+
103+
# NOTE: in osxpkg fpm replaces symlinks with actual file that it
104+
# points to, so we need to use after-install hook. See FPM_FLAGS
105+
# above.
106+
if [[ "$(uname)" == 'Linux' ]]; then
107+
mkdir -p $BIN_DIR
108+
pushd $BIN_DIR
109+
ln -s ../lib/dvc/dvc dvc
110+
popd
111+
$BIN_DIR/dvc --help
112+
fi
113+
114+
# NOTE: temporarily not adding scripts to mac package. See [1]
115+
# [1] https://github.com/iterative/dvc/issues/2585
116+
if [[ "$(uname)" == 'Linux' ]]; then
117+
mkdir -p $BUILD_DIR/$BASH_CMPLT_DIR
118+
cp scripts/completion/dvc.bash $BUILD_DIR/$BASH_CMPLT_DIR/dvc
119+
120+
mkdir -p $BUILD_DIR/$ZSH_CMPLT_DIR
121+
cp scripts/completion/dvc.zsh $BUILD_DIR/$ZSH_CMPLT_DIR
122+
fi
130123
}
131124

132-
build()
133-
{
134-
cleanup
135-
echo "PKG = \"$1\"" > dvc/utils/build.py
136-
build_dvc
137-
fpm_build $1
125+
build() {
126+
cleanup
127+
echo "PKG = \"$1\"" >dvc/utils/build.py
128+
build_dvc
129+
fpm_build $1
138130
}
139131

140132
install_dependencies
141133

142134
if [[ "$(uname)" == 'Linux' ]]; then
143-
build rpm
144-
build deb
135+
build rpm
136+
build deb
145137
else
146-
build osxpkg
138+
build osxpkg
147139
fi
148140

149141
cleanup

scripts/build_snap.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ sudo snap install --dangerous --classic dvc_*.snap
1818
if [[ -n "$TRAVIS_TAG" ]]; then
1919
# Make sure we have a correct version
2020
if [[ "$(dvc --version)" != "$TRAVIS_TAG" ]]; then
21-
echo "ERROR: 'dvc --version'$(dvc -V) doesn't match '$TRAVIS_TAG'" >&2
22-
exit 1
21+
echo "ERROR: 'dvc --version'$(dvc -V) doesn't match '$TRAVIS_TAG'" >&2
22+
exit 1
2323
fi
2424
fi
2525
# ensure basic commands can run

scripts/ci/before_install.sh

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,53 @@ set -e
66
scriptdir="$(dirname $0)"
77

88
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
9-
ulimit -a
10-
sudo sysctl -w kern.maxproc=2048
11-
sudo sysctl -w kern.maxprocperuid=2048
12-
echo '\nulimit -u 2048' >> ~/.bash_profile
13-
ulimit -a
9+
ulimit -a
10+
sudo sysctl -w kern.maxproc=2048
11+
sudo sysctl -w kern.maxprocperuid=2048
12+
echo '\nulimit -u 2048' >>~/.bash_profile
13+
ulimit -a
1414
fi
1515

16-
echo > env.sh
16+
echo >env.sh
1717

1818
if [[ "$TRAVIS_BUILD_STAGE_NAME" == "Test" ]]; then
19-
if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then
20-
# NOTE: ssh keys for ssh test to be able to ssh to the localhost
21-
ssh-keygen -t rsa -N "" -f mykey
22-
mkdir -p ~/.ssh
23-
cp mykey ~/.ssh/id_rsa
24-
cp mykey.pub ~/.ssh/id_rsa.pub
25-
cat mykey.pub >> ~/.ssh/authorized_keys
26-
ssh-keyscan localhost >> ~/.ssh/known_hosts
27-
ssh localhost ls &> /dev/null
28-
ssh-keyscan 127.0.0.1 >> ~/.ssh/known_hosts
29-
ssh 127.0.0.1 ls &> /dev/null
30-
ssh-keyscan 0.0.0.0 >> ~/.ssh/known_hosts
31-
ssh 0.0.0.0 ls &> /dev/null
32-
fi
33-
34-
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
35-
bash "$scriptdir/install_azurite.sh"
36-
bash "$scriptdir/install_oss.sh"
37-
bash "$scriptdir/install_hadoop.sh"
38-
fi
39-
40-
if [[ "$TRAVIS_OS_NAME" == "osx" && "$TRAVIS_PULL_REQUEST" == "false" ]]; then
41-
brew install openssl
42-
$scriptdir/retry.sh brew cask install google-cloud-sdk
43-
fi
19+
if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then
20+
# NOTE: ssh keys for ssh test to be able to ssh to the localhost
21+
ssh-keygen -t rsa -N "" -f mykey
22+
mkdir -p ~/.ssh
23+
cp mykey ~/.ssh/id_rsa
24+
cp mykey.pub ~/.ssh/id_rsa.pub
25+
cat mykey.pub >>~/.ssh/authorized_keys
26+
ssh-keyscan localhost >>~/.ssh/known_hosts
27+
ssh localhost ls &>/dev/null
28+
ssh-keyscan 127.0.0.1 >>~/.ssh/known_hosts
29+
ssh 127.0.0.1 ls &>/dev/null
30+
ssh-keyscan 0.0.0.0 >>~/.ssh/known_hosts
31+
ssh 0.0.0.0 ls &>/dev/null
32+
fi
33+
34+
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
35+
bash "$scriptdir/install_azurite.sh"
36+
bash "$scriptdir/install_oss.sh"
37+
bash "$scriptdir/install_hadoop.sh"
38+
fi
39+
40+
if [[ "$TRAVIS_OS_NAME" == "osx" && "$TRAVIS_PULL_REQUEST" == "false" ]]; then
41+
brew install openssl
42+
$scriptdir/retry.sh brew cask install google-cloud-sdk
43+
fi
4444
fi
4545

4646
if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
47-
$scriptdir/retry.sh choco install python --version 3.7.5
48-
echo 'PATH="/c/Python37:/c/Python37/Scripts:$PATH"' >> env.sh
47+
$scriptdir/retry.sh choco install python --version 3.7.5
48+
echo 'PATH="/c/Python37:/c/Python37/Scripts:$PATH"' >>env.sh
4949
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
50-
ln -s -f /usr/local/bin/python3 /usr/local/bin/python
51-
ln -s -f /usr/local/bin/pip3 /usr/local/bin/pip
50+
ln -s -f /usr/local/bin/python3 /usr/local/bin/python
51+
ln -s -f /usr/local/bin/pip3 /usr/local/bin/pip
5252
fi
5353

5454
if [[ -n "$TRAVIS_TAG" ]]; then
55-
echo "export SNAP_CHANNEL=stable" >> env.sh
55+
echo "export SNAP_CHANNEL=stable" >>env.sh
5656
else
57-
echo "export SNAP_CHANNEL=edge" >> env.sh
57+
echo "export SNAP_CHANNEL=edge" >>env.sh
5858
fi

scripts/ci/check_patch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -x
44
set -e
55

6-
pip install Pygments collective.checkdocs pre-commit
6+
pip install Pygments collective.checkdocs pre-commit
77

88
# stop the build if there are any readme formatting errors
99
python setup.py checkdocs

0 commit comments

Comments
 (0)