Skip to content

Commit c963f75

Browse files
authored
Merge pull request #562 from ahn1340/pep8_enforce
Pep8 enforce
2 parents 278f88a + de3192f commit c963f75

File tree

5 files changed

+178
-20
lines changed

5 files changed

+178
-20
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ matrix:
1919
env: DISTRIB="conda" PYTHON_VERSION="3.6" MINICONDA_URL="https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh"
2020
- os: linux
2121
env: DISTRIB="conda" PYTHON_VERSION="3.6" EXAMPLES="true" MINICONDA_URL="https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh"
22+
- os: linux
23+
env: DISTRIB="conda" PYTHON_VERSION="3.7" MINICONDA_URL="https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh"
24+
- os: linux
25+
env: DISTRIB="conda" PYTHON_VERSION="3.6" RUN_FLAKE8="true" SKIP_TESTS="true" MINICONDA_URL="https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh"
26+
2227

2328
# Temporarily disabling OSX builds because thy take too long
2429
# Set language to generic to not break travis-ci
@@ -59,13 +64,14 @@ install:
5964
# Install general requirements the way setup.py suggests
6065
- pip install pep8 codecov
6166
# Temporarily pin the numpy version for travis-ci
62-
- pip install "numpy<1.15"
67+
- pip install "numpy<=1.14.5"
6368
- cat requirements.txt | xargs -n 1 -L 1 pip install
6469
# Install openml dependency for metadata generation unittest
6570
- pip install xmltodict requests liac-arff
6671
- pip install git+https://github.com/openml/openml-python@0b9009b0436fda77d9f7c701bd116aff4158d5e1 --no-deps
6772
- mkdir ~/.openml
6873
- echo "apikey = 610344db6388d9ba34f6db45a3cf71de" > ~/.openml/config
74+
- pip install flake8
6975
# Debug output to know all exact package versions!
7076
- pip freeze
7177
- python setup.py install

ci_scripts/flake8_diff.sh

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/bin/bash
2+
3+
# This script is mostly taken from https://github.com/scikit-learn/scikit-learn/blob/master/build_tools/travis/flake8_diff.sh
4+
5+
# This script is used in Travis to check that PRs do not add obvious
6+
# flake8 violations. It relies on two things:
7+
# - find common ancestor between branch and
8+
# automl/auto-sklearn remote
9+
# - run flake8 --diff on the diff between the branch and the common
10+
# ancestor
11+
#
12+
# Additional features:
13+
# - the line numbers in Travis match the local branch on the PR
14+
# author machine.
15+
# - ./build_tools/travis/flake8_diff.sh can be run locally for quick
16+
# turn-around
17+
18+
set -e
19+
# pipefail is necessary to propagate exit codes
20+
set -o pipefail
21+
22+
PROJECT=automl/auto-sklearn
23+
PROJECT_URL=https://github.com/$PROJECT.git
24+
25+
# Find the remote with the project name (upstream in most cases)
26+
REMOTE=$(git remote -v | grep $PROJECT | cut -f1 | head -1 || echo '')
27+
28+
# Add a temporary remote if needed. For example this is necessary when
29+
# Travis is configured to run in a fork. In this case 'origin' is the
30+
# fork and not the reference repo we want to diff against.
31+
if [[ -z "$REMOTE" ]]; then
32+
TMP_REMOTE=tmp_reference_upstream
33+
REMOTE=$TMP_REMOTE
34+
git remote add $REMOTE $PROJECT_URL
35+
fi
36+
37+
echo "Remotes:"
38+
echo '--------------------------------------------------------------------------------'
39+
git remote --verbose
40+
41+
# Travis does the git clone with a limited depth.
42+
# This may not be enough to find the common ancestor with
43+
# $REMOTE/development so we unshallow the git checkout
44+
if [[ -a .git/shallow ]]; then
45+
echo -e '\nTrying to unshallow the repo:'
46+
echo '--------------------------------------------------------------------------------'
47+
git fetch --unshallow
48+
fi
49+
50+
if [[ "$TRAVIS" == "true" ]]; then
51+
if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]
52+
then
53+
# In main repo, using TRAVIS_COMMIT_RANGE to test the commits
54+
# that were pushed into a branch
55+
if [[ "$PROJECT" == "$TRAVIS_REPO_SLUG" ]]; then
56+
if [[ -z "$TRAVIS_COMMIT_RANGE" ]]; then
57+
echo "New branch, no commit range from Travis so passing this test by convention"
58+
exit 0
59+
fi
60+
COMMIT_RANGE=$TRAVIS_COMMIT_RANGE
61+
fi
62+
else
63+
# We want to fetch the code as it is in the PR branch and not
64+
# the result of the merge into development. This way line numbers
65+
# reported by Travis will match with the local code.
66+
LOCAL_BRANCH_REF=travis_pr_$TRAVIS_PULL_REQUEST
67+
# In Travis the PR target is always origin
68+
git fetch origin pull/$TRAVIS_PULL_REQUEST/head:refs/$LOCAL_BRANCH_REF
69+
fi
70+
fi
71+
72+
# If not using the commit range from Travis we need to find the common
73+
# ancestor between $LOCAL_BRANCH_REF and $REMOTE/development
74+
if [[ -z "$COMMIT_RANGE" ]]; then
75+
if [[ -z "$LOCAL_BRANCH_REF" ]]; then
76+
LOCAL_BRANCH_REF=$(git rev-parse --abbrev-ref HEAD)
77+
fi
78+
echo -e "\nLast 2 commits in $LOCAL_BRANCH_REF:"
79+
echo '--------------------------------------------------------------------------------'
80+
git --no-pager log -2 $LOCAL_BRANCH_REF
81+
82+
REMOTE_DEVELOPMENT_REF="$REMOTE/development"
83+
# Make sure that $REMOTE_DEVELOPMENT_REF is a valid reference
84+
echo -e "\nFetching $REMOTE_DEVELOPMENT_REF"
85+
echo '--------------------------------------------------------------------------------'
86+
git fetch $REMOTE development:refs/remotes/$REMOTE_DEVELOPMENT_REF
87+
LOCAL_BRANCH_SHORT_HASH=$(git rev-parse --short $LOCAL_BRANCH_REF)
88+
REMOTE_DEVELOPMENT_SHORT_HASH=$(git rev-parse --short $REMOTE_DEVELOPMENT_REF)
89+
90+
COMMIT=$(git merge-base $LOCAL_BRANCH_REF $REMOTE_DEVELOPMENT_REF) || \
91+
echo "No common ancestor found for $(git show $LOCAL_BRANCH_REF -q) and $(git show $REMOTE_DEVELOPMENT_REF -q)"
92+
93+
if [ -z "$COMMIT" ]; then
94+
exit 1
95+
fi
96+
97+
COMMIT_SHORT_HASH=$(git rev-parse --short $COMMIT)
98+
99+
echo -e "\nCommon ancestor between $LOCAL_BRANCH_REF ($LOCAL_BRANCH_SHORT_HASH)"\
100+
"and $REMOTE_DEVELOPMENT_REF ($REMOTE_DEVELOPMENT_SHORT_HASH) is $COMMIT_SHORT_HASH:"
101+
echo '--------------------------------------------------------------------------------'
102+
git --no-pager show --no-patch $COMMIT_SHORT_HASH
103+
104+
COMMIT_RANGE="$COMMIT_SHORT_HASH..$LOCAL_BRANCH_SHORT_HASH"
105+
106+
if [[ -n "$TMP_REMOTE" ]]; then
107+
git remote remove $TMP_REMOTE
108+
fi
109+
110+
else
111+
echo "Got the commit range from Travis: $COMMIT_RANGE"
112+
fi
113+
114+
echo -e '\nRunning flake8 on the diff in the range' "$COMMIT_RANGE" \
115+
"($(git rev-list $COMMIT_RANGE | wc -l) commit(s)):"
116+
echo '--------------------------------------------------------------------------------'
117+
118+
# We need the following command to exit with 0 hence the echo in case
119+
# there is no match
120+
MODIFIED_FILES="$(git diff --name-only $COMMIT_RANGE || echo "no_match")"
121+
122+
check_files() {
123+
files="$1"
124+
shift
125+
options="$*"
126+
if [ -n "$files" ]; then
127+
# Conservative approach: diff without context (--unified=0) so that code
128+
# that was not changed does not create failures
129+
git diff --unified=0 $COMMIT_RANGE -- $files | flake8 --diff --show-source $options
130+
fi
131+
}
132+
133+
if [[ "$MODIFIED_FILES" == "no_match" ]]; then
134+
echo "No file has been modified"
135+
else
136+
137+
check_files "$(echo "$MODIFIED_FILES" | grep -v ^examples)"
138+
check_files "$(echo "$MODIFIED_FILES" | grep ^examples)" \
139+
--config ./examples/.flake8
140+
fi
141+
echo -e "No problem detected by flake8\n"

ci_scripts/test.sh

100644100755
Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
set -e
22

3-
# Get into a temp directory to run test from the installed scikit learn and
4-
# check if we do not leave artifacts
5-
mkdir -p $TEST_DIR
3+
run_tests() {
4+
# Get into a temp directory to run test from the installed scikit learn and
5+
# check if we do not leave artifacts
6+
mkdir -p $TEST_DIR
67

7-
cwd=`pwd`
8-
examples_dir=$cwd/examples
9-
test_dir=$cwd/test/
8+
cwd=`pwd`
9+
examples_dir=$cwd/examples
10+
test_dir=$cwd/test/
1011

11-
cd $TEST_DIR
12+
cd $TEST_DIR
13+
if [[ "$COVERAGE" == "true" ]]; then
14+
nosetests --no-path-adjustment -sv --with-coverage --cover-package=$MODULE $test_dir
15+
elif [[ "$EXAMPLES" == "true" ]]; then
16+
for example in `find $examples_dir -name '*.py'`
17+
do
18+
python $example
19+
done
20+
else
21+
nosetests --no-path-adjustment -sv $test_dir
22+
fi
23+
}
1224

13-
if [[ "$COVERAGE" == "true" ]]; then
14-
nosetests --no-path-adjustment -sv --with-coverage --cover-package=$MODULE $test_dir
15-
elif [[ "$EXAMPLES" == "true" ]]; then
16-
for example in `find $examples_dir -name '*.py'`
17-
do
18-
python $example
19-
done
20-
else
21-
nosetests --no-path-adjustment -sv $test_dir
25+
if [[ "$RUN_FLAKE8" ]]; then
26+
source ci_scripts/flake8_diff.sh
2227
fi
28+
29+
if [[ "$SKIP_TESTS" != "true" ]]; then
30+
run_tests
31+
fi
32+
33+

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ nose
44
six
55
Cython
66

7-
numpy==1.14.5
7+
numpy>=1.9.0<=1.14.5
88
scipy>=0.14.1
99

1010
scikit-learn>=0.19,<0.20

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"six",
3737
"Cython",
3838
# Numpy version of higher than 1.14.5 causes libgcc_s.so.1 error.
39-
"numpy==1.14.5",
39+
"numpy>=1.9.0<=1.14.5",
4040
"scipy>=0.14.1",
4141
"scikit-learn>=0.19,<0.20",
4242
"lockfile",
@@ -69,6 +69,6 @@
6969
license='BSD',
7070
platforms=['Linux'],
7171
classifiers=[],
72-
python_requires='>=3.4.*',
72+
python_requires='>=3.5.*',
7373
url='https://automl.github.io/auto-sklearn',
7474
)

0 commit comments

Comments
 (0)