diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0cf1cdae9bf..14cbfcba60e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,7 @@ jobs: - name: Install changed files test dependencies run: dev_tools/conf/pip-install-minimal-for-pytest-changed-files.sh - name: Changed files test - run: check/pytest-changed-files + run: check/pytest-changed-files -n auto lint: name: Lint check runs-on: ubuntu-20.04 @@ -168,7 +168,7 @@ jobs: - name: Run Quil dependencies run: docker-compose -f cirq-rigetti/docker-compose.test.yaml up -d - name: Pytest check - run: check/pytest --ignore=cirq-core/cirq/contrib --actually-quiet --rigetti-integration + run: check/pytest -n auto --ignore=cirq-core/cirq/contrib --actually-quiet --rigetti-integration - name: Stop Quil dependencies run: docker-compose -f cirq-rigetti/docker-compose.test.yaml down build_docs: @@ -221,7 +221,7 @@ jobs: - name: Run Quil dependencies run: docker-compose -f cirq-rigetti/docker-compose.test.yaml up -d - name: Coverage check - run: check/pytest-and-incremental-coverage --actually-quiet + run: check/pytest-and-incremental-coverage -n auto - name: Stop Quil dependencies run: docker-compose -f cirq-rigetti/docker-compose.test.yaml down windows: @@ -245,7 +245,7 @@ jobs: - name: Pytest Windows run: | source dev_tools/pypath - check/pytest --ignore=cirq-core/cirq/contrib --actually-quiet + check/pytest -n auto --ignore=cirq-core/cirq/contrib --actually-quiet shell: bash macos: name: Pytest MacOS @@ -266,7 +266,7 @@ jobs: - name: Install requirements run: pip install --upgrade --upgrade-strategy eager -r dev_tools/requirements/no-contrib.env.txt - name: Pytest check - run: check/pytest --ignore=cirq-core/cirq/contrib + run: check/pytest -n auto --ignore=cirq-core/cirq/contrib notebooks-stable: name: Changed Notebooks Isolated Test against Cirq stable env: diff --git a/check/pytest-and-incremental-coverage b/check/pytest-and-incremental-coverage index b8ace83ebd4..027c2260fa1 100755 --- a/check/pytest-and-incremental-coverage +++ b/check/pytest-and-incremental-coverage @@ -4,7 +4,7 @@ # Finds changed uncovered lines. # # Usage: -# check/pytest-and-incremental-coverage [BASE_REVISION] +# check/pytest-and-incremental-coverage [BASE_REVISION] [PYTEST_ARGS] # # You can specify a base git revision to compare against (i.e. to use when # determining whether or not a line is considered to have "changed"). To make @@ -26,13 +26,30 @@ cd "$( dirname "${BASH_SOURCE[0]}" )" || exit 1 cd "$(git rev-parse --show-toplevel)" || exit 1 +PYTEST_ARGS=() +ANALYZE_COV=1 +BASEREV="" + +if [[ "$1" == [^-]* ]]; then + BASEREV="$1" + shift +fi + +for arg in "$@"; do + if [[ "${arg}" == "--no-analyze" ]]; then + ANALYZE_COV=0 + else + PYTEST_ARGS+=("${arg}") + fi +done + # Figure out which revision to compare against. -if [ ! -z "$1" ] && [[ $1 != -* ]]; then - if [ "$(git cat-file -t $1 2> /dev/null)" != "commit" ]; then - echo -e "\033[31mNo revision '$1'.\033[0m" >&2 +if [ -n "${BASEREV}" ]; then + if [ "$(git cat-file -t "${BASEREV}" 2> /dev/null)" != "commit" ]; then + echo -e "\033[31mNo revision '${BASEREV}'.\033[0m" >&2 exit 1 fi - rev=$1 + rev="${BASEREV}" elif [ "$(git cat-file -t upstream/master 2> /dev/null)" == "commit" ]; then rev=upstream/master elif [ "$(git cat-file -t origin/master 2> /dev/null)" == "commit" ]; then @@ -57,19 +74,27 @@ source dev_tools/pypath check/pytest --actually-quiet \ --rigetti-integration \ --cov \ - --cov-report=annotate \ - --cov-config=dev_tools/conf/.coveragerc + --cov-config=dev_tools/conf/.coveragerc \ + "${PYTEST_ARGS[@]}" pytest_result=$? -# Analyze coverage files. -python dev_tools/check_incremental_coverage_annotations.py "${rev}" -cover_result=$? -# Clean up generated coverage files. -find . | grep "\.py,cover$" | xargs rm -f +# assume succesful cover_result in case coverage is not run +cover_result=0 +if (( $ANALYZE_COV )); then + # Convert to .py,cover files. + coverage annotate + + # Analyze coverage files. + python dev_tools/check_incremental_coverage_annotations.py "${rev}" + cover_result=$? + + # Clean up generated coverage files. + git clean --force --quiet -x -- "*.py,cover" +fi # Report result. -if [ "${pytest_result}" -ne "0" ] || [ "${cover_result}" -ne "0" ]; then - exit 1 +if (( ${pytest_result} || ${cover_result} )); then + exit 1 fi exit 0 diff --git a/check/pytest-changed-files-and-incremental-coverage b/check/pytest-changed-files-and-incremental-coverage index f4fa9f721ac..200a1fc22a7 100755 --- a/check/pytest-changed-files-and-incremental-coverage +++ b/check/pytest-changed-files-and-incremental-coverage @@ -101,7 +101,7 @@ python dev_tools/check_incremental_coverage_annotations.py "${rev}" cover_result=$? # Clean up generated coverage files. -find . | grep "\.py,cover$" | xargs rm -f +git clean --force --quiet -x -- "*.py,cover" # Report result. if [ "${pytest_result}" -ne "0" ] || [ "${cover_result}" -ne "0" ]; then diff --git a/dev_tools/bash_scripts_test.py b/dev_tools/bash_scripts_test.py index f7dadabc368..c63530d68af 100644 --- a/dev_tools/bash_scripts_test.py +++ b/dev_tools/bash_scripts_test.py @@ -351,8 +351,11 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory): assert result.exit_code == 0 assert result.out == ( 'INTERCEPTED check/pytest ' - '--actually-quiet --rigetti-integration --cov --cov-report=annotate ' + '--actually-quiet --rigetti-integration --cov ' '--cov-config=dev_tools/conf/.coveragerc\n' + 'The annotate command will be removed in a future version.\n' + 'Get in touch if you still use it: ned@nedbatchelder.com\n' + 'No data to report.\n' 'INTERCEPTED ' 'python dev_tools/check_incremental_coverage_annotations.py HEAD\n' ) @@ -375,10 +378,13 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory): assert result.exit_code == 0 assert result.out == ( 'INTERCEPTED check/pytest ' - '--actually-quiet --rigetti-integration --cov --cov-report=annotate ' + '--actually-quiet --rigetti-integration --cov ' '--cov-config=dev_tools/conf/.coveragerc\n' - 'INTERCEPTED python ' - 'dev_tools/check_incremental_coverage_annotations.py master\n' + 'The annotate command will be removed in a future version.\n' + 'Get in touch if you still use it: ned@nedbatchelder.com\n' + 'No data to report.\n' + 'INTERCEPTED ' + 'python dev_tools/check_incremental_coverage_annotations.py master\n' ) assert result.err == "Comparing against revision 'master'.\n" @@ -391,10 +397,13 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory): assert result.exit_code == 0 assert result.out == ( 'INTERCEPTED check/pytest ' - '--actually-quiet --rigetti-integration --cov --cov-report=annotate ' + '--actually-quiet --rigetti-integration --cov ' '--cov-config=dev_tools/conf/.coveragerc\n' - 'INTERCEPTED python ' - 'dev_tools/check_incremental_coverage_annotations.py origin/master\n' + 'The annotate command will be removed in a future version.\n' + 'Get in touch if you still use it: ned@nedbatchelder.com\n' + 'No data to report.\n' + 'INTERCEPTED ' + 'python dev_tools/check_incremental_coverage_annotations.py origin/master\n' ) assert result.err == "Comparing against revision 'origin/master'.\n" @@ -407,10 +416,13 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory): assert result.exit_code == 0 assert result.out == ( 'INTERCEPTED check/pytest ' - '--actually-quiet --rigetti-integration --cov --cov-report=annotate ' + '--actually-quiet --rigetti-integration --cov ' '--cov-config=dev_tools/conf/.coveragerc\n' - 'INTERCEPTED python ' - 'dev_tools/check_incremental_coverage_annotations.py upstream/master\n' + 'The annotate command will be removed in a future version.\n' + 'Get in touch if you still use it: ned@nedbatchelder.com\n' + 'No data to report.\n' + 'INTERCEPTED ' + 'python dev_tools/check_incremental_coverage_annotations.py upstream/master\n' ) assert result.err == "Comparing against revision 'upstream/master'.\n" @@ -423,10 +435,13 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory): assert result.exit_code == 0 assert result.out == ( 'INTERCEPTED check/pytest ' - '--actually-quiet --rigetti-integration --cov --cov-report=annotate ' + '--actually-quiet --rigetti-integration --cov ' '--cov-config=dev_tools/conf/.coveragerc\n' - 'INTERCEPTED python ' - 'dev_tools/check_incremental_coverage_annotations.py upstream/master\n' + 'The annotate command will be removed in a future version.\n' + 'Get in touch if you still use it: ned@nedbatchelder.com\n' + 'No data to report.\n' + 'INTERCEPTED ' + 'python dev_tools/check_incremental_coverage_annotations.py upstream/master\n' ) assert result.err == "Comparing against revision 'upstream/master'.\n" @@ -451,10 +466,13 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory): assert result.exit_code == 0 assert result.out == ( 'INTERCEPTED check/pytest ' - '--actually-quiet --rigetti-integration --cov --cov-report=annotate ' + '--actually-quiet --rigetti-integration --cov ' '--cov-config=dev_tools/conf/.coveragerc\n' - 'INTERCEPTED python ' - 'dev_tools/check_incremental_coverage_annotations.py HEAD\n' + 'The annotate command will be removed in a future version.\n' + 'Get in touch if you still use it: ned@nedbatchelder.com\n' + 'No data to report.\n' + 'INTERCEPTED ' + 'python dev_tools/check_incremental_coverage_annotations.py HEAD\n' ) assert result.err == "Comparing against revision 'HEAD'.\n" @@ -467,10 +485,13 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory): assert result.exit_code == 0 assert result.out == ( 'INTERCEPTED check/pytest ' - '--actually-quiet --rigetti-integration --cov --cov-report=annotate ' + '--actually-quiet --rigetti-integration --cov ' '--cov-config=dev_tools/conf/.coveragerc\n' - 'INTERCEPTED python ' - 'dev_tools/check_incremental_coverage_annotations.py master\n' + 'The annotate command will be removed in a future version.\n' + 'Get in touch if you still use it: ned@nedbatchelder.com\n' + 'No data to report.\n' + 'INTERCEPTED ' + 'python dev_tools/check_incremental_coverage_annotations.py master\n' ) assert result.err == "Comparing against revision 'master'.\n" @@ -490,10 +511,13 @@ def test_pytest_and_incremental_coverage_branch_selection(tmpdir_factory): assert result.exit_code == 0 assert result.out.startswith( 'INTERCEPTED check/pytest ' - '--actually-quiet --rigetti-integration --cov --cov-report=annotate ' + '--actually-quiet --rigetti-integration --cov ' '--cov-config=dev_tools/conf/.coveragerc\n' - 'INTERCEPTED python ' - 'dev_tools/check_incremental_coverage_annotations.py ' + 'The annotate command will be removed in a future version.\n' + 'Get in touch if you still use it: ned@nedbatchelder.com\n' + 'No data to report.\n' + 'INTERCEPTED ' + 'python dev_tools/check_incremental_coverage_annotations.py ' ) assert result.err.startswith("Comparing against revision 'master' (merge base ")