Skip to content

Commit

Permalink
Bump minimum python version to 3.9 (#6167)
Browse files Browse the repository at this point in the history
* dropped 3.7 support

* Update setup.py

* Removed 3.8 as well

* changing some more 3.8's to 3.9's

* reformat

* Update pyproject.toml

* Update setup.py

* changing notebook python versions

* Update setup.py

* testing

* Update packaging_test.sh

* Update packaging_test.sh

* Update packaging_test.sh

* adding 311

* updating formatter

* Bump Python version for CI actions to 3.9

* Remove code specific to Python <= 3.8 only

* Drop redundant python_version checks from requirement files

* Fix required Python version in the installation doc

* Clean redundant assertion

* Skip coverage for code run in subprocess

* Suggest a more recent cirq for old pythons

---------

Co-authored-by: Pavol Juhas <juhas@google.com>
  • Loading branch information
skushnir123 and pavoljuhas committed Jun 29, 2023
1 parent 74cee7e commit bc09047
Show file tree
Hide file tree
Showing 46 changed files with 656 additions and 847 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-weekly.yml
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install requirements
run: pip install -r dev_tools/requirements/isolated-base.env.txt
Expand Down
36 changes: 18 additions & 18 deletions .github/workflows/ci.yml
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Misc
run: check/misc
Expand All @@ -31,7 +31,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.7'
python-version: '3.9'
architecture: 'x64'
- name: Install dependencies
run: pip install -r dev_tools/requirements/deps/packaging.txt
Expand All @@ -46,7 +46,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install dependencies
run: pip install -r dev_tools/requirements/deps/format.txt
Expand All @@ -59,7 +59,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install mypy
run: pip install -r dev_tools/requirements/mypy.env.txt
Expand All @@ -74,7 +74,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install changed files test dependencies
run: dev_tools/conf/pip-install-minimal-for-pytest-changed-files.sh
Expand All @@ -87,7 +87,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install pylint
run: pip install -r dev_tools/requirements/pylint.env.txt
Expand All @@ -102,7 +102,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install requirements
run: pip install -r dev_tools/requirements/dev.env.txt
Expand All @@ -117,7 +117,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install requirements
run: pip install -r dev_tools/requirements/deps/tensorflow-docs.txt
Expand All @@ -139,7 +139,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install dependencies
run: pip install -r dev_tools/requirements/isolated-base.env.txt
Expand All @@ -149,7 +149,7 @@ jobs:
name: Pytest Ubuntu
strategy:
matrix:
python-version: [ '3.7', '3.8', '3.9', '3.10' ]
python-version: [ '3.9', '3.10' ]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install requirements
run: pip install pip-tools
Expand All @@ -192,7 +192,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install requirements
run: |
Expand All @@ -208,7 +208,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install requirements
run: |
Expand All @@ -224,7 +224,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- uses: actions/cache@v2
with:
Expand All @@ -244,7 +244,7 @@ jobs:
name: Pytest Windows
strategy:
matrix:
python-version: [ '3.7', '3.8', '3.9', '3.10' ]
python-version: [ '3.9', '3.10' ]
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
Expand All @@ -269,7 +269,7 @@ jobs:
name: Pytest MacOS
strategy:
matrix:
python-version: [ '3.7.16', '3.8', '3.9', '3.10' ]
python-version: [ '3.9', '3.10' ]
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -302,7 +302,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install requirements
run: pip install -r dev_tools/requirements/isolated-base.env.txt
Expand All @@ -320,7 +320,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install requirements
run: pip install -r dev_tools/requirements/notebooks.env.txt
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-master.yml
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'
- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Expand Up @@ -2,7 +2,7 @@ version: 2
build:
image: latest
python:
version: 3.8
version: 3.9
install:
- requirements: rtd_docs/requirements.txt
sphinx:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
@@ -1,4 +1,4 @@
FROM python:3.8-slim AS cirq_base
FROM python:3.9-slim AS cirq_base

# Install dependencies.
# rm -rf /var/lib/apt/lists/* cleans up apt cache. See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
Expand Down
2 changes: 1 addition & 1 deletion asv.conf.json
Expand Up @@ -8,7 +8,7 @@
"dvcs": "git",
"environment_type": "virtualenv",
"show_commit_url": "https://github.com/quantumlib/Cirq/commit/",
"pythons": ["3.8"],
"pythons": ["3.9"],
"matrix": {"env_nobuild": {"PYTHONOPTIMIZE": ["-O", ""]}},
"benchmark_dir": "benchmarks",
"env_dir": ".asv/env",
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/README.md
Expand Up @@ -13,7 +13,7 @@ To run all benchmarks, navigate to the root Cirq directory at the command line a

You can also pass arguments to the script, which would be forwarded to the `asv run` command. For eg:
```bash
./check/asv_run --quick --bench bench_examples --python 3.8
./check/asv_run --quick --bench bench_examples --python 3.9
```

Please refer [Running Benchmarks guide by ASV](https://asv.readthedocs.io/en/stable/using.html#running-benchmarks) for more information.
Expand Down
2 changes: 1 addition & 1 deletion cirq-aqt/setup.py
Expand Up @@ -60,7 +60,7 @@
url='http://github.com/quantumlib/cirq',
author='The Cirq Developers',
author_email='cirq-dev@googlegroups.com',
python_requires=('>=3.7.0'),
python_requires=('>=3.9.0'),
install_requires=requirements,
license='Apache 2',
description=description,
Expand Down
15 changes: 3 additions & 12 deletions cirq-core/cirq/_compat_test.py
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
import collections
import dataclasses
import importlib
import importlib.metadata
import logging
import multiprocessing
import os
Expand Down Expand Up @@ -722,21 +722,12 @@ def test_metadata_search_path():
subprocess_context(_test_metadata_search_path_inner)()


def _test_metadata_search_path_inner():
def _test_metadata_search_path_inner(): # pragma: no cover
# initialize the DeprecatedModuleFinders
# pylint: disable=unused-import
import cirq.testing._compat_test_data.module_a

try:
# importlib.metadata for python 3.8+
# coverage: ignore
import importlib.metadata as m
except: # coverage: ignore
# coverage: ignore
# importlib_metadata for python <3.8
m = pytest.importorskip("importlib_metadata")

assert m.metadata('flynt')
assert importlib.metadata.metadata('flynt')


def test_metadata_distributions_after_deprecated_submodule():
Expand Down
10 changes: 5 additions & 5 deletions cirq-core/cirq/_version.py
Expand Up @@ -13,20 +13,20 @@
# limitations under the License.

"""Define version number here, read it from setup.py automatically,
and warn users that the latest version of cirq uses python 3.7+"""
and warn users that the latest version of cirq uses python 3.9+"""

import sys

if sys.version_info < (3, 7, 0):
if sys.version_info < (3, 9, 0):
# coverage: ignore
raise SystemError(
"You installed the latest version of cirq but aren't on python 3.7+.\n"
"You installed the latest version of cirq but aren't on python 3.9+.\n"
'To fix this error, you need to either:\n'
'\n'
'A) Update to python 3.7 or later.\n'
'A) Update to python 3.9 or later.\n'
'- OR -\n'
'B) Explicitly install an older deprecated-but-compatible version '
'of cirq (e.g. "python -m pip install cirq==0.5.*")'
'of cirq (e.g. "python -m pip install cirq==1.1.*")'
)

__version__ = "1.2.0.dev"
4 changes: 2 additions & 2 deletions cirq-core/cirq/protocols/json_serialization_test.py
Expand Up @@ -57,8 +57,8 @@ class _ModuleDeprecation:


# pyQuil 3.0, necessary for cirq_rigetti module requires
# python >= 3.7
if sys.version_info < (3, 7): # pragma: no cover
# python >= 3.9
if sys.version_info < (3, 9): # pragma: no cover
del TESTED_MODULES['cirq_rigetti']


Expand Down
5 changes: 0 additions & 5 deletions cirq-core/cirq/study/resolver_test.py
Expand Up @@ -15,7 +15,6 @@
"""Tests for parameter resolvers."""

import fractions
import sys

import numpy as np
import pytest
Expand Down Expand Up @@ -243,10 +242,6 @@ def _resolved_value_(self):
assert r.value_of(b) == 'Baz'


# sympy 1.12 does not support Python 3.7
@pytest.mark.xfail(
condition=sys.version_info < (3, 8, 0), reason='this test requires sympy 1.12', strict=True
)
def test_custom_value_not_implemented():
class Bar:
def _resolved_value_(self):
Expand Down
3 changes: 0 additions & 3 deletions cirq-core/requirements.txt
@@ -1,8 +1,5 @@
# Runtime requirements for the python 3 version of cirq.

# functools.cached_property was introduced in python 3.8
backports.cached_property~=1.0.1; python_version < '3.8'

duet~=0.2.8
matplotlib~=3.0
networkx>=2.4
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/setup.py
Expand Up @@ -63,7 +63,7 @@
url='http://github.com/quantumlib/cirq',
author='The Cirq Developers',
author_email='cirq-dev@googlegroups.com',
python_requires=('>=3.7.0'),
python_requires=('>=3.9.0'),
install_requires=requirements,
extras_require={'contrib': contrib_requirements},
license='Apache 2',
Expand Down
2 changes: 1 addition & 1 deletion cirq-ft/cirq_ft/algos/and_gate.ipynb
Expand Up @@ -223,4 +223,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
3 changes: 0 additions & 3 deletions cirq-ft/cirq_ft/infra/gate_with_registers.py
Expand Up @@ -13,15 +13,12 @@
# limitations under the License.

import abc
import sys
from typing import Dict, Iterable, List, Optional, Sequence, Tuple, Union, overload

import attr
import cirq
import numpy as np

assert sys.version_info > (3, 6), "https://docs.python.org/3/whatsnew/3.6.html#whatsnew36-pep468"


@attr.frozen
class Register:
Expand Down
2 changes: 1 addition & 1 deletion cirq-ft/setup.py
Expand Up @@ -59,7 +59,7 @@
url='http://github.com/quantumlib/cirq',
author='The Cirq Developers',
author_email='cirq-dev@googlegroups.com',
python_requires='>=3.7.0',
python_requires='>=3.9.0',
install_requires=requirements,
license='Apache 2',
description=description,
Expand Down
10 changes: 5 additions & 5 deletions cirq-google/cirq_google/_version.py
Expand Up @@ -13,20 +13,20 @@
# limitations under the License.

"""Define version number here, read it from setup.py automatically,
and warn users that the latest version of cirq uses python 3.7+"""
and warn users that the latest version of cirq uses python 3.9+"""

import sys

if sys.version_info < (3, 7, 0):
if sys.version_info < (3, 9, 0):
# coverage: ignore
raise SystemError(
"You installed the latest version of cirq but aren't on python 3.7+.\n"
"You installed the latest version of cirq but aren't on python 3.9+.\n"
'To fix this error, you need to either:\n'
'\n'
'A) Update to python 3.7 or later.\n'
'A) Update to python 3.9 or later.\n'
'- OR -\n'
'B) Explicitly install an older deprecated-but-compatible version '
'of cirq (e.g. "python -m pip install cirq==0.5.*")'
'of cirq (e.g. "python -m pip install cirq==1.1.*")'
)

__version__ = "1.2.0.dev"

0 comments on commit bc09047

Please sign in to comment.