Skip to content

Commit

Permalink
feat: Add support for Python 3.12 (#231)
Browse files Browse the repository at this point in the history
* chore(python): Add Python 3.12

Source-Link: googleapis/synthtool@af16e6d
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:bacc3af03bff793a03add584537b36b5644342931ad989e3ba1171d3bd5399f5

* add python 3.12 to noxfile and setup.py

* update system test to use python 3.12

* add constraints file for python 3.12

* add python 3.12 to owlbot.py

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* add python 3.12 as a required check

* skip recursion test

* avoid matplotlib error

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <[email protected]>
Co-authored-by: Tim Swast <[email protected]>
  • Loading branch information
4 people authored Mar 22, 2024
1 parent 2ad1e46 commit df2976f
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ branchProtectionRules:
- 'unit (3.9)'
- 'unit (3.10)'
- 'unit (3.11)'
- 'unit (3.12)'
- 'cover'
- 'Kokoro presubmit'
permissionRules:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.9', '3.10', '3.11']
python: ['3.9', '3.10', '3.11', '3.12']
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
10 changes: 6 additions & 4 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ In order to add a feature:
documentation.

- The feature must work fully on the following CPython versions:
3.9, 3.10 and 3.11 on both UNIX and Windows.
3.9, 3.10, 3.11 and 3.12 on both UNIX and Windows.

- The feature must not add unnecessary dependencies (where
"unnecessary" is of course subjective, but new dependencies should
Expand Down Expand Up @@ -72,7 +72,7 @@ We use `nox <https://nox.readthedocs.io/en/latest/>`__ to instrument our tests.

- To run a single unit test::

$ nox -s unit-3.11 -- -k <name of test>
$ nox -s unit-3.12 -- -k <name of test>


.. note::
Expand Down Expand Up @@ -143,12 +143,12 @@ Running System Tests
$ nox -s system

# Run a single system test
$ nox -s system-3.11 -- -k <name of test>
$ nox -s system-3.12 -- -k <name of test>


.. note::

System tests are only configured to run under Python 3.9 and 3.11.
System tests are only configured to run under Python 3.9, 3.11 and 3.12.
For expediency, we do not run them in older versions of Python 3.

This alone will not run the tests. You'll need to change some local
Expand Down Expand Up @@ -261,10 +261,12 @@ We support:
- `Python 3.9`_
- `Python 3.10`_
- `Python 3.11`_
- `Python 3.12`_

.. _Python 3.9: https://docs.python.org/3.9/
.. _Python 3.10: https://docs.python.org/3.10/
.. _Python 3.11: https://docs.python.org/3.11/
.. _Python 3.12: https://docs.python.org/3.12/


Supported versions can be found in our ``noxfile.py`` `config`_.
Expand Down
7 changes: 5 additions & 2 deletions bigframes/operations/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import abc
import typing

import matplotlib.pyplot as plt

DEFAULT_SAMPLING_N = 1000
DEFAULT_SAMPLING_STATE = 0

Expand All @@ -27,6 +25,11 @@ def generate(self):
pass

def draw(self) -> None:
# This import can fail with "Matplotlib failed to acquire the
# following lock file" so import here to reduce the chance of
# our parallel test suite from triggering this.
import matplotlib.pyplot as plt

plt.draw_if_interactive()

@property
Expand Down
3 changes: 3 additions & 0 deletions bigframes/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,9 @@ def to_datetime(

# SQL Compilation uses recursive algorithms on deep trees
# 10M tree depth should be sufficient to generate any sql that is under bigquery limit
# Note: This limit does not have the desired effect on Python 3.12 in
# which the applicable limit is now hard coded. See:
# https://github.com/python/cpython/issues/112282
sys.setrecursionlimit(max(10000000, sys.getrecursionlimit()))
resource.setrlimit(
resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY)
Expand Down
4 changes: 2 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

DEFAULT_PYTHON_VERSION = "3.10"

UNIT_TEST_PYTHON_VERSIONS = ["3.9", "3.10", "3.11"]
UNIT_TEST_PYTHON_VERSIONS = ["3.9", "3.10", "3.11", "3.12"]
UNIT_TEST_STANDARD_DEPENDENCIES = [
"mock",
"asyncmock",
Expand All @@ -54,7 +54,7 @@
UNIT_TEST_EXTRAS: List[str] = []
UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {}

SYSTEM_TEST_PYTHON_VERSIONS = ["3.9", "3.11"]
SYSTEM_TEST_PYTHON_VERSIONS = ["3.9", "3.12"]
SYSTEM_TEST_STANDARD_DEPENDENCIES = [
"jinja2",
"mock",
Expand Down
4 changes: 2 additions & 2 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
# Add templated files
# ----------------------------------------------------------------------------
templated_files = common.py_library(
unit_test_python_versions=["3.9", "3.10", "3.11"],
system_test_python_versions=["3.9", "3.11"],
unit_test_python_versions=["3.9", "3.10", "3.11", "3.12"],
system_test_python_versions=["3.9", "3.11", "3.12"],
cov_level=35,
intersphinx_dependencies={
"pandas": "https://pandas.pydata.org/pandas-docs/stable/",
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: OS Independent",
"Topic :: Internet",
],
Expand Down
Empty file added testing/constraints-3.12.txt
Empty file.
8 changes: 8 additions & 0 deletions tests/system/small/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import io
import operator
import sys
import tempfile
import typing
from typing import Tuple
Expand Down Expand Up @@ -4003,6 +4004,13 @@ def test_df_dot_operator_series(
)


# TODO(tswast): We may be able to re-enable this test after we break large
# queries up in https://github.com/googleapis/python-bigquery-dataframes/pull/427
@pytest.mark.skipif(
sys.version_info >= (3, 12),
# See: https://github.com/python/cpython/issues/112282
reason="setrecursionlimit has no effect on the Python C stack since Python 3.12.",
)
def test_recursion_limit(scalars_df_index):
scalars_df_index = scalars_df_index[["int64_too", "int64_col", "float64_col"]]
for i in range(400):
Expand Down

0 comments on commit df2976f

Please sign in to comment.