Skip to content

Commit 256ec45

Browse files
authored
Fix #417: address pythonpackage.yml vulnerabilities & do other updates (#418)
1 parent c647128 commit 256ec45

File tree

2 files changed

+148
-72
lines changed

2 files changed

+148
-72
lines changed

.github/workflows/ci.yaml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Copyright 2020 Google, LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Continuous integration tests
16+
run-name: >-
17+
Test code and notebooks in
18+
${{github.event_name == 'pull_request' && format('PR #{0}', github.event.pull_request.number)
19+
|| format('push to {0}', github.ref_name) }}
20+
by @${{github.actor}}
21+
22+
on:
23+
push:
24+
branches:
25+
- master
26+
- main
27+
28+
pull_request:
29+
branches:
30+
- master
31+
- main
32+
33+
merge_group:
34+
types:
35+
- checks_requested
36+
37+
workflow_dispatch:
38+
39+
# Declare default workflow permissions as read only.
40+
permissions: read-all
41+
42+
concurrency:
43+
# Cancel any previously-started but still active runs on the same branch.
44+
cancel-in-progress: true
45+
group: ${{github.workflow}}-${{github.event.pull_request.number||github.ref}}
46+
47+
env:
48+
# Python version to use.
49+
python_version: 3.11
50+
51+
# Files containing lists of dependencies installed using pip. This is used as
52+
# a parameter to setup-python to check whether its pip cache needs updating.
53+
python_dep_files: |-
54+
requirements.txt
55+
recirq/**/extra-requirements.txt
56+
dev_tools/requirements/deps/*.txt
57+
dev_tools/check_notebooks.py
58+
dev_tools/write-ci-requirements.py
59+
60+
jobs:
61+
pytest:
62+
name: Run Python tests
63+
runs-on: ubuntu-24.04
64+
timeout-minutes: 15
65+
strategy:
66+
matrix:
67+
cirq-version:
68+
- 'current'
69+
- 'previous'
70+
- 'next'
71+
fail-fast: false
72+
steps:
73+
- name: Check out a copy of the git repository
74+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
75+
76+
- name: Set up Python with caching of pip dependencies
77+
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
78+
with:
79+
python-version: ${{env.python_version}}
80+
cache: pip
81+
cache-dependency-path: ${{env.python_dep_files}}
82+
83+
- name: Install Python dependencies
84+
run: |
85+
python -m pip install --upgrade pip
86+
pip install -r requirements.txt
87+
python dev_tools/write-ci-requirements.py \
88+
--relative-cirq-version=${{ matrix.cirq-version }} --all-extras
89+
pip install -r ci-requirements.txt
90+
pip install --no-deps -e .
91+
92+
- name: Test with pytest
93+
run: |
94+
# OMP_NUM_THREADS: PySCF's poor OpenMP performance slows down QCQMC tests.
95+
# RECIRQ_IMPORT_FAILSAFE: skip tests on unsupported Cirq configurations.
96+
export OMP_NUM_THREADS=1
97+
RECIRQ_IMPORT_FAILSAFE=y pytest -v --skipslow
98+
99+
pylint:
100+
name: Run Python linters
101+
runs-on: ubuntu-24.04
102+
timeout-minutes: 15
103+
steps:
104+
- name: Check out a copy of the git repository
105+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
106+
107+
- name: Set up Python with caching of pip dependencies
108+
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
109+
with:
110+
python-version: ${{env.python_version}}
111+
cache: pip
112+
cache-dependency-path: ${{env.python_dep_files}}
113+
114+
- name: Install Python dependencies
115+
run: |
116+
python -m pip install --upgrade pip
117+
pip install flake8
118+
119+
- name: Lint with flake8
120+
run: |
121+
# Stop the build if there are Python syntax errors or undefined names.
122+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
123+
# `exit-zero` treats all errors as warnings. The GitHub editor is 127 chars wide.
124+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
125+
126+
nbformat:
127+
name: Check notebook formatting
128+
runs-on: ubuntu-24.04
129+
timeout-minutes: 15
130+
steps:
131+
- name: Check out a copy of the git repository
132+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
133+
134+
- name: Set up Python with caching of pip dependencies
135+
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
136+
with:
137+
python-version: ${{env.python_version}}
138+
cache: pip
139+
cache-dependency-path: ${{env.python_dep_files}}
140+
141+
- name: Install Python dependencies
142+
run: |
143+
pip install --upgrade pip
144+
pip install -r dev_tools/requirements/deps/tensorflow-docs.txt
145+
146+
- name: Check notebook formatting
147+
run: |
148+
dev_tools/nbformat

.github/workflows/pythonpackage.yml

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)