Skip to content

Commit

Permalink
Merge pull request #562 from ahn1340/pep8_enforce
Browse files Browse the repository at this point in the history
Pep8 enforce
  • Loading branch information
ahn1340 committed Oct 29, 2018
2 parents 278f88a + de3192f commit c963f75
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 20 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Expand Up @@ -19,6 +19,11 @@ matrix:
env: DISTRIB="conda" PYTHON_VERSION="3.6" MINICONDA_URL="https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh"
- os: linux
env: DISTRIB="conda" PYTHON_VERSION="3.6" EXAMPLES="true" MINICONDA_URL="https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh"
- os: linux
env: DISTRIB="conda" PYTHON_VERSION="3.7" MINICONDA_URL="https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh"
- os: linux
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"


# Temporarily disabling OSX builds because thy take too long
# Set language to generic to not break travis-ci
Expand Down Expand Up @@ -59,13 +64,14 @@ install:
# Install general requirements the way setup.py suggests
- pip install pep8 codecov
# Temporarily pin the numpy version for travis-ci
- pip install "numpy<1.15"
- pip install "numpy<=1.14.5"
- cat requirements.txt | xargs -n 1 -L 1 pip install
# Install openml dependency for metadata generation unittest
- pip install xmltodict requests liac-arff
- pip install git+https://github.com/openml/openml-python@0b9009b0436fda77d9f7c701bd116aff4158d5e1 --no-deps
- mkdir ~/.openml
- echo "apikey = 610344db6388d9ba34f6db45a3cf71de" > ~/.openml/config
- pip install flake8
# Debug output to know all exact package versions!
- pip freeze
- python setup.py install
Expand Down
141 changes: 141 additions & 0 deletions ci_scripts/flake8_diff.sh
@@ -0,0 +1,141 @@
#!/bin/bash

# This script is mostly taken from https://github.com/scikit-learn/scikit-learn/blob/master/build_tools/travis/flake8_diff.sh

# This script is used in Travis to check that PRs do not add obvious
# flake8 violations. It relies on two things:
# - find common ancestor between branch and
# automl/auto-sklearn remote
# - run flake8 --diff on the diff between the branch and the common
# ancestor
#
# Additional features:
# - the line numbers in Travis match the local branch on the PR
# author machine.
# - ./build_tools/travis/flake8_diff.sh can be run locally for quick
# turn-around

set -e
# pipefail is necessary to propagate exit codes
set -o pipefail

PROJECT=automl/auto-sklearn
PROJECT_URL=https://github.com/$PROJECT.git

# Find the remote with the project name (upstream in most cases)
REMOTE=$(git remote -v | grep $PROJECT | cut -f1 | head -1 || echo '')

# Add a temporary remote if needed. For example this is necessary when
# Travis is configured to run in a fork. In this case 'origin' is the
# fork and not the reference repo we want to diff against.
if [[ -z "$REMOTE" ]]; then
TMP_REMOTE=tmp_reference_upstream
REMOTE=$TMP_REMOTE
git remote add $REMOTE $PROJECT_URL
fi

echo "Remotes:"
echo '--------------------------------------------------------------------------------'
git remote --verbose

# Travis does the git clone with a limited depth.
# This may not be enough to find the common ancestor with
# $REMOTE/development so we unshallow the git checkout
if [[ -a .git/shallow ]]; then
echo -e '\nTrying to unshallow the repo:'
echo '--------------------------------------------------------------------------------'
git fetch --unshallow
fi

if [[ "$TRAVIS" == "true" ]]; then
if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]
then
# In main repo, using TRAVIS_COMMIT_RANGE to test the commits
# that were pushed into a branch
if [[ "$PROJECT" == "$TRAVIS_REPO_SLUG" ]]; then
if [[ -z "$TRAVIS_COMMIT_RANGE" ]]; then
echo "New branch, no commit range from Travis so passing this test by convention"
exit 0
fi
COMMIT_RANGE=$TRAVIS_COMMIT_RANGE
fi
else
# We want to fetch the code as it is in the PR branch and not
# the result of the merge into development. This way line numbers
# reported by Travis will match with the local code.
LOCAL_BRANCH_REF=travis_pr_$TRAVIS_PULL_REQUEST
# In Travis the PR target is always origin
git fetch origin pull/$TRAVIS_PULL_REQUEST/head:refs/$LOCAL_BRANCH_REF
fi
fi

# If not using the commit range from Travis we need to find the common
# ancestor between $LOCAL_BRANCH_REF and $REMOTE/development
if [[ -z "$COMMIT_RANGE" ]]; then
if [[ -z "$LOCAL_BRANCH_REF" ]]; then
LOCAL_BRANCH_REF=$(git rev-parse --abbrev-ref HEAD)
fi
echo -e "\nLast 2 commits in $LOCAL_BRANCH_REF:"
echo '--------------------------------------------------------------------------------'
git --no-pager log -2 $LOCAL_BRANCH_REF

REMOTE_DEVELOPMENT_REF="$REMOTE/development"
# Make sure that $REMOTE_DEVELOPMENT_REF is a valid reference
echo -e "\nFetching $REMOTE_DEVELOPMENT_REF"
echo '--------------------------------------------------------------------------------'
git fetch $REMOTE development:refs/remotes/$REMOTE_DEVELOPMENT_REF
LOCAL_BRANCH_SHORT_HASH=$(git rev-parse --short $LOCAL_BRANCH_REF)
REMOTE_DEVELOPMENT_SHORT_HASH=$(git rev-parse --short $REMOTE_DEVELOPMENT_REF)

COMMIT=$(git merge-base $LOCAL_BRANCH_REF $REMOTE_DEVELOPMENT_REF) || \
echo "No common ancestor found for $(git show $LOCAL_BRANCH_REF -q) and $(git show $REMOTE_DEVELOPMENT_REF -q)"

if [ -z "$COMMIT" ]; then
exit 1
fi

COMMIT_SHORT_HASH=$(git rev-parse --short $COMMIT)

echo -e "\nCommon ancestor between $LOCAL_BRANCH_REF ($LOCAL_BRANCH_SHORT_HASH)"\
"and $REMOTE_DEVELOPMENT_REF ($REMOTE_DEVELOPMENT_SHORT_HASH) is $COMMIT_SHORT_HASH:"
echo '--------------------------------------------------------------------------------'
git --no-pager show --no-patch $COMMIT_SHORT_HASH

COMMIT_RANGE="$COMMIT_SHORT_HASH..$LOCAL_BRANCH_SHORT_HASH"

if [[ -n "$TMP_REMOTE" ]]; then
git remote remove $TMP_REMOTE
fi

else
echo "Got the commit range from Travis: $COMMIT_RANGE"
fi

echo -e '\nRunning flake8 on the diff in the range' "$COMMIT_RANGE" \
"($(git rev-list $COMMIT_RANGE | wc -l) commit(s)):"
echo '--------------------------------------------------------------------------------'

# We need the following command to exit with 0 hence the echo in case
# there is no match
MODIFIED_FILES="$(git diff --name-only $COMMIT_RANGE || echo "no_match")"

check_files() {
files="$1"
shift
options="$*"
if [ -n "$files" ]; then
# Conservative approach: diff without context (--unified=0) so that code
# that was not changed does not create failures
git diff --unified=0 $COMMIT_RANGE -- $files | flake8 --diff --show-source $options
fi
}

if [[ "$MODIFIED_FILES" == "no_match" ]]; then
echo "No file has been modified"
else

check_files "$(echo "$MODIFIED_FILES" | grep -v ^examples)"
check_files "$(echo "$MODIFIED_FILES" | grep ^examples)" \
--config ./examples/.flake8
fi
echo -e "No problem detected by flake8\n"
43 changes: 27 additions & 16 deletions ci_scripts/test.sh 100644 → 100755
@@ -1,22 +1,33 @@
set -e

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

cwd=`pwd`
examples_dir=$cwd/examples
test_dir=$cwd/test/
cwd=`pwd`
examples_dir=$cwd/examples
test_dir=$cwd/test/

cd $TEST_DIR
cd $TEST_DIR
if [[ "$COVERAGE" == "true" ]]; then
nosetests --no-path-adjustment -sv --with-coverage --cover-package=$MODULE $test_dir
elif [[ "$EXAMPLES" == "true" ]]; then
for example in `find $examples_dir -name '*.py'`
do
python $example
done
else
nosetests --no-path-adjustment -sv $test_dir
fi
}

if [[ "$COVERAGE" == "true" ]]; then
nosetests --no-path-adjustment -sv --with-coverage --cover-package=$MODULE $test_dir
elif [[ "$EXAMPLES" == "true" ]]; then
for example in `find $examples_dir -name '*.py'`
do
python $example
done
else
nosetests --no-path-adjustment -sv $test_dir
if [[ "$RUN_FLAKE8" ]]; then
source ci_scripts/flake8_diff.sh
fi

if [[ "$SKIP_TESTS" != "true" ]]; then
run_tests
fi


2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -4,7 +4,7 @@ nose
six
Cython

numpy==1.14.5
numpy>=1.9.0<=1.14.5
scipy>=0.14.1

scikit-learn>=0.19,<0.20
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -36,7 +36,7 @@
"six",
"Cython",
# Numpy version of higher than 1.14.5 causes libgcc_s.so.1 error.
"numpy==1.14.5",
"numpy>=1.9.0<=1.14.5",
"scipy>=0.14.1",
"scikit-learn>=0.19,<0.20",
"lockfile",
Expand Down Expand Up @@ -69,6 +69,6 @@
license='BSD',
platforms=['Linux'],
classifiers=[],
python_requires='>=3.4.*',
python_requires='>=3.5.*',
url='https://automl.github.io/auto-sklearn',
)

0 comments on commit c963f75

Please sign in to comment.