From 033d79a16c13e30c268656c855456af14fc2be55 Mon Sep 17 00:00:00 2001 From: moto <855818+mthrok@users.noreply.github.com> Date: Wed, 13 May 2020 17:35:21 +0000 Subject: [PATCH] Move style check to CCI --- .circleci/config.yml | 32 +++++++++ .circleci/config.yml.in | 29 ++++++++ .circleci/regenerate.py | 10 ++- .../unittest/scripts/run_style_checks.sh | 32 +++++++++ .circleci/unittest/scripts/run_test.sh | 3 - .travis.yml | 23 ------- build_tools/travis/after_success.sh | 13 ---- build_tools/travis/install.sh | 68 ------------------- build_tools/travis/test_script.sh | 26 ------- 9 files changed, 102 insertions(+), 134 deletions(-) create mode 100755 .circleci/unittest/scripts/run_style_checks.sh delete mode 100644 .travis.yml delete mode 100644 build_tools/travis/after_success.sh delete mode 100644 build_tools/travis/install.sh delete mode 100644 build_tools/travis/test_script.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 5ce617105..f0701b585 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -285,6 +285,35 @@ jobs: - store_test_results: path: test-results + stylecheck: + <<: *binary_common + docker: + - image: "pytorch/manylinux-cuda100" + resource_class: medium + steps: + - checkout + - run: + name: Generate cache key + # This will refresh cache on Sundays, nightly build should generate new cache. + command: echo "$(date +"%Y-%U")" > .circleci-weekly + - restore_cache: + + keys: + - env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} + + - run: + name: Setup + command: .circleci/unittest/scripts/setup_env.sh + - save_cache: + + key: env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} + + paths: + - conda + - env + - run: + name: Run style check + command: .circleci/unittest/scripts/run_style_checks.sh workflows: # build: @@ -299,6 +328,9 @@ workflows: - unittest_linux: name: unittest_linux_py3.6 python_version: '3.6' + - stylecheck: + name: stylecheck_py3.6 + python_version: '3.6' - unittest_linux: name: unittest_linux_py3.7 python_version: '3.7' diff --git a/.circleci/config.yml.in b/.circleci/config.yml.in index 097a6d7b1..c27a8b4df 100644 --- a/.circleci/config.yml.in +++ b/.circleci/config.yml.in @@ -285,6 +285,35 @@ jobs: - store_test_results: path: test-results + stylecheck: + <<: *binary_common + docker: + - image: "pytorch/manylinux-cuda100" + resource_class: medium + steps: + - checkout + - run: + name: Generate cache key + # This will refresh cache on Sundays, nightly build should generate new cache. + command: echo "$(date +"%Y-%U")" > .circleci-weekly + - restore_cache: + {% raw %} + keys: + - env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} + {% endraw %} + - run: + name: Setup + command: .circleci/unittest/scripts/setup_env.sh + - save_cache: + {% raw %} + key: env-v1-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }} + {% endraw %} + paths: + - conda + - env + - run: + name: Run style check + command: .circleci/unittest/scripts/run_style_checks.sh workflows: # build: diff --git a/.circleci/regenerate.py b/.circleci/regenerate.py index ee3d57eaf..2f387fc1a 100755 --- a/.circleci/regenerate.py +++ b/.circleci/regenerate.py @@ -102,13 +102,21 @@ def indent(indentation, data_list): def unittest_workflows(indentation=6): w = [] for os_type in ["linux"]: - for python_version in PYTHON_VERSIONS: + for i, python_version in enumerate(PYTHON_VERSIONS): w.append({ f"unittest_{os_type}": { "name": f"unittest_{os_type}_py{python_version}", "python_version": python_version, } }) + + if i == 0: + w.append({ + f"stylecheck": { + "name": f"stylecheck_py{python_version}", + "python_version": python_version, + } + }) return indent(indentation, w) diff --git a/.circleci/unittest/scripts/run_style_checks.sh b/.circleci/unittest/scripts/run_style_checks.sh new file mode 100755 index 000000000..acfade534 --- /dev/null +++ b/.circleci/unittest/scripts/run_style_checks.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -u + +eval "$(./conda/bin/conda shell.bash hook)" +conda activate ./env + +# We want to run all the style checks even if one of them fail. + +exit_status=0 + +printf "\x1b[34mRunning flake8: " +flake8 --version +printf "\x1b[0m\n" +flake8 torchtext test build_tools/setup_helpers +status=$? +exit_status="$((exit_status+status))" +if [ "${status}" -ne 0 ]; then + printf "\x1b[31mflake8 failed. Check the format of Python files.\x1b[0m\n" +fi + +printf "\x1b[34mRunning clang-format: " +clang-format --version +printf "\x1b[0m\n" +git-clang-format origin/master +git diff --exit-code +status=$? +exit_status="$((exit_status+status))" +if [ "${status}" -ne 0 ]; then + printf "\x1b[31mC++ files are not formatted. Please use git-clang-format to format CPP files.\x1b[0m\n" +fi +exit $exit_status diff --git a/.circleci/unittest/scripts/run_test.sh b/.circleci/unittest/scripts/run_test.sh index fd08ae864..c8322ea5f 100755 --- a/.circleci/unittest/scripts/run_test.sh +++ b/.circleci/unittest/scripts/run_test.sh @@ -7,6 +7,3 @@ conda activate ./env python -m torch.utils.collect_env pytest --cov=torchtext --junitxml=test-results/junit.xml -v --durations 20 test -flake8 torchaudio test build_tools/setup_helpers -git-clang-format origin/master -git diff --exit-code || (echo "C++ files are not formatted. Use clang-format on CPP files."; exit 1) diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 83f69ea38..000000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -dist: trusty - -language: python - -cache: - directories: - - /home/travis/download - - /home/travis/.cache/pip - -# This matrix tests that the code works on Python 3.5, -# 3.6 (same versions as PyTorch CI), and passes lint. -matrix: - fast_finish: true - include: - - env: PYTHON_VERSION="3.6" RUN_FLAKE8="true" SKIP_TESTS="true" - sudo: required - -notifications: - email: false - -install: source build_tools/travis/install.sh -script: bash build_tools/travis/test_script.sh -after_success: source build_tools/travis/after_success.sh diff --git a/build_tools/travis/after_success.sh b/build_tools/travis/after_success.sh deleted file mode 100644 index 5f672c0db..000000000 --- a/build_tools/travis/after_success.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# This script is meant to be called by the "after_success" step defined in -# .travis.yml. See http://docs.travis-ci.com/ for more details. - -set -e - -if [[ "$COVERAGE" == "true" ]]; then - # Ignore codecov failures as the codecov server is not - # very reliable but we don't want travis to report a failure - # in the github UI just because the coverage report failed to - # be published. - codecov || echo "codecov upload failed" -fi diff --git a/build_tools/travis/install.sh b/build_tools/travis/install.sh deleted file mode 100644 index 57370136d..000000000 --- a/build_tools/travis/install.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash -# This script is meant to be called by the "install" step defined in -# .travis.yml. See http://docs.travis-ci.com/ for more details. -# The behavior of the script is controlled by environment variabled defined -# in the .travis.yml in the top level folder of the project. - -set -e - -echo 'List files from cached directories' -if [ -d $HOME/download ]; then - echo 'download:' - ls $HOME/download -fi -if [ -d $HOME/.cache/pip ]; then - echo 'pip:' - ls $HOME/.cache/pip -fi - -# Deactivate the travis-provided virtual environment and setup a -# conda-based environment instead -deactivate - -# Add the miniconda bin directory to $PATH -export PATH=/home/travis/miniconda3/bin:$PATH -echo $PATH - -# Use the miniconda installer for setup of conda itself -pushd . -cd -mkdir -p download -cd download -if [[ ! -f /home/travis/miniconda3/bin/activate ]] -then - if [[ ! -f miniconda.sh ]] - then - wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh \ - -O miniconda.sh - fi - chmod +x miniconda.sh && ./miniconda.sh -b -f - conda update --yes conda - echo "Creating environment to run tests in." - conda create -n testenv --yes python="$PYTHON_VERSION" -fi -cd .. -popd - -# Activate the python environment we created. -source activate testenv - -# Install requirements via pip in our conda environment -pip install -r requirements.txt - -# Install the following only if running tests -if [[ "$SKIP_TESTS" != "true" ]]; then - # SpaCy English models - python -m spacy download en - -# TODO: Add nltk data back once moses tokenizer is back online. -# https://github.com/alvations/sacremoses/issues/61 -# # NLTK data needed for Moses tokenizer -# python -m nltk.downloader perluniprops nonbreaking_prefixes -# - # PyTorch - conda install --yes pytorch -c pytorch-test - - # Installation - python setup.py install -fi diff --git a/build_tools/travis/test_script.sh b/build_tools/travis/test_script.sh deleted file mode 100644 index 200d8eb8b..000000000 --- a/build_tools/travis/test_script.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# This script is meant to be called by the "script" step defined in -# .travis.yml. See http://docs.travis-ci.com/ for more details. -# The behavior of the script is controlled by environment variabled defined -# in the .travis.yml in the top level folder of the project. - -set -e - -python --version - -run_tests() { - if [[ "$RUN_SLOW" == "true" ]]; then - TEST_CMD="py.test --runslow -s -v --cov=torchtext --durations=20" - else - TEST_CMD="py.test -v --cov=torchtext --durations=20" - fi - $TEST_CMD -} - -if [[ "$RUN_FLAKE8" == "true" ]]; then - flake8 -fi - -if [[ "$SKIP_TESTS" != "true" ]]; then - run_tests -fi