Skip to content

Commit

Permalink
Separate style check from unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mthrok committed May 28, 2020
1 parent da59f59 commit b320be4
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 2 deletions.
34 changes: 34 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,37 @@ jobs:
- store_test_results:
path: test-results

stylecheck:
<<: *binary_common
docker:
- image: "pytorch/torchaudio_unittest_base:manylinux"
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-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}

- run:
name: Setup
command: .circleci/unittest/linux/scripts/setup_env.sh
- save_cache:

key: env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}

paths:
- conda
- env
- third_party/build
- run:
name: Run style check
command: .circleci/unittest/linux/scripts/run_style_checks.sh

workflows:
build:
jobs:
Expand Down Expand Up @@ -534,6 +565,9 @@ workflows:
- unittest_linux_cpu:
name: unittest_linux_cpu_py3.6
python_version: '3.6'
- stylecheck:
name: stylecheck_py3.6
python_version: '3.6'
- unittest_linux_cpu:
name: unittest_linux_cpu_py3.7
python_version: '3.7'
Expand Down
31 changes: 31 additions & 0 deletions .circleci/config.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,37 @@ jobs:
- store_test_results:
path: test-results

stylecheck:
<<: *binary_common
docker:
- image: "pytorch/torchaudio_unittest_base:manylinux"
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-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
{% endraw %}
- run:
name: Setup
command: .circleci/unittest/linux/scripts/setup_env.sh
- save_cache:
{% raw %}
key: env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
{% endraw %}
paths:
- conda
- env
- third_party/build
- run:
name: Run style check
command: .circleci/unittest/linux/scripts/run_style_checks.sh

workflows:
build:
jobs:
Expand Down
10 changes: 9 additions & 1 deletion .circleci/regenerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def unittest_workflows(indentation=6):
jobs = []
for os_type in ["linux", "windows"]:
for device_type in ["cpu", "gpu"]:
for python_version in PYTHON_VERSIONS:
for i, python_version in enumerate(PYTHON_VERSIONS):
job = {
"name": f"unittest_{os_type}_{device_type}_py{python_version}",
"python_version": python_version,
Expand All @@ -123,6 +123,14 @@ def unittest_workflows(indentation=6):
if device_type == 'gpu':
job['filters'] = gen_filter_branch_tree('master')
jobs.append({f"unittest_{os_type}_{device_type}": job})

if i == 0 and os_type == "linux" and device_type == "cpu":
jobs.append({
f"stylecheck": {
"name": f"stylecheck_py{python_version}",
"python_version": python_version,
}
})
return indent(indentation, jobs)


Expand Down
1 change: 1 addition & 0 deletions .circleci/unittest/linux/scripts/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ dependencies:
- librosa
- pip
- pip:
- clang-format
- kaldi-io
- scipy
32 changes: 32 additions & 0 deletions .circleci/unittest/linux/scripts/run_style_checks.sh
Original file line number Diff line number Diff line change
@@ -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 torchaudio 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
1 change: 0 additions & 1 deletion .circleci/unittest/linux/scripts/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ conda activate ./env

python -m torch.utils.collect_env
pytest --cov=torchaudio --junitxml=test-results/junit.xml -v --durations 20 test
flake8 torchaudio test build_tools/setup_helpers

0 comments on commit b320be4

Please sign in to comment.