8000 Support Python 3.13 and 3.14 in Fiddle OSS packaging and GitHub CI. by copybara-service[bot] · Pull Request #625 · google/fiddle · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
branches:
- 'main'
jobs:
build:

Check warning on line 10 in .github/workflows/testing.yaml

View workflow job for this annotation

GitHub Actions / zizmor-output

excessive-permissions

testing.yaml:10: overly broad permissions: default permissions used due to no permissions: block
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# tensorflow-text (and hence seqio) is not available for python 3.13
python-version: ["3.11", "3.12"]
# NOTE: The job names (`build (<version>)`) must stay in sync with
# `github_check_runs` in copy.bara.sky.
python-version: ["3.11", "3.12", "3.13", "3.14"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

Check failure on line 20 in .github/workflows/testing.yaml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 20 in .github/workflows/testing.yaml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

testing.yaml:20: unpinned action reference: action is not pinned to a hash (required by blanket policy)
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5

Check failure on line 22 in .github/workflows/testing.yaml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 22 in .github/workflows/testing.yaml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

testing.yaml:22: unpinned action reference: action is not pinned to a hash (required by blanket policy)
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies and package
Expand All @@ -27,4 +28,24 @@
pip install -e .[testing]
- name: Test with pytest
run: |
pytest --ignore=fiddle/_src/extensions/seqio_test.py fiddle
PYTEST_ARGS="--ignore=fiddle/_src/extensions/seqio_test.py"
# seqio (and hence tensorflow) is not installed for Python 3.13+
# because tensorflow-text is unavailable; see setup.py.
if python -c 'import sys; sys.exit(sys.version_info < (3, 13))'; then
PYTEST_ARGS="${PYTEST_ARGS} --ignore=fiddle/_src/extensions/tf_test.py"
fi
pytest ${PYTEST_ARGS} fiddle
- name: Build wheel and test the installed package
if: matrix.python-version == '3.14'
run: |
python -m pip install build twine
python -m build
python -m twine check dist/*
python -m venv /tmp/wheel-venv
WHEEL="$(ls dist/*.whl)"
/tmp/wheel-venv/bin/pip install "${WHEEL}[testing]"
SITE="$(/tmp/wheel-venv/bin/python -c 'import site; print(site.getsitepackages()[0])')"
cd "${SITE}" && /tmp/wheel-venv/bin/python -m pytest \
--ignore=fiddle/_src/extensions/seqio_test.py \
--ignore=fiddle/_src/extensions/tf_test.py \
fiddle
22 changes: 11 additions & 11 deletions fiddle/_src/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from fiddle._src import config as config_lib
from fiddle._src.experimental import daglish_legacy
from fiddle._src.testing.example import demo_configs
import pytype_extensions
import typing_extensions


class Tag1(fdl.Tag):
Expand Down Expand Up @@ -128,7 +128,7 @@ class ConfigTest(parameterized.TestCase):

def test_config_for_classes(self):
class_config = fdl.Config(SampleClass, 1, kwarg2='kwarg2')
pytype_extensions.assert_type(class_config, fdl.Config[SampleClass])
typing_extensions.assert_type(class_config, fdl.Config[SampleClass])
self.assertEqual(class_config.arg1, 1)
self.assertEqual(class_config.kwarg2, 'kwarg2')
class_config.arg1 = 'arg1'
Expand All @@ -137,15 +137,15 @@ def test_config_for_classes(self):
class_config.kwarg1 = 'kwarg1'

instance = fdl.build(class_config)
pytype_extensions.assert_type(instance, SampleClass)
typing_extensions.assert_type(instance, SampleClass)
self.assertEqual(instance.arg1, 'arg1')
self.assertEqual(instance.arg2, 'arg2')
self.assertEqual(instance.kwarg1, 'kwarg1')
self.assertEqual(instance.kwarg2, 'kwarg2')

def test_config_for_functions(self):
fn_config = fdl.Config(basic_fn, 1, kwarg2='kwarg2')
pytype_extensions.assert_type(
typing_extensions.assert_type(
fn_config, fdl.Config[Dict[str, Any]]
) # use-fiddle-overlay
self.assertEqual(fn_config.arg1, 1)
Expand All @@ -156,7 +156,7 @@ def test_config_for_functions(self):
fn_config.kwarg1 = 'kwarg1'

result = fdl.build(fn_config)
pytype_extensions.assert_type(result, Dict[str, Any]) # use-fiddle-overlay
typing_extensions.assert_type(result, Dict[str, Any]) # use-fiddle-overlay
self.assertEqual(result, {
'arg1': 'arg1',
'arg2': 'arg2',
Expand All @@ -166,15 +166,15 @@ def test_config_for_functions(self):

def test_config_for_functions_with_var_args(self):
fn_config = fdl.Config(fn_with_var_args, 'arg1', kwarg1='kwarg1')
pytype_extensions.assert_type(fn_config, fdl.Config)
typing_extensions.assert_type(fn_config, fdl.Config)
fn_args = fdl.build(fn_config)
self.assertEqual(fn_args['arg1'], 'arg1')
self.assertEqual(fn_args['kwarg1'], 'kwarg1')

fn_config.arg1 = 'new_arg1'
fn_config.kwarg1 = 'new_kwarg1'
fn_args = fdl.build(fn_config)
pytype_extensions.assert_type(fn_args, Any)
typing_extensions.assert_type(fn_args, Any)
self.assertEqual(fn_args['arg1'], 'new_arg1')
self.assertEqual(fn_args['kwarg1'], 'new_kwarg1')

Expand Down Expand Up @@ -788,17 +788,17 @@ def test_dir_var_args_and_kwargs(self):

def test_typed_config(self):
class_config = make_typed_config()
pytype_extensions.assert_type(class_config, fdl.Config[SampleClass])
typing_extensions.assert_type(class_config, fdl.Config[SampleClass])
instance = fdl.build(class_config)
pytype_extensions.assert_type(instance, SampleClass)
typing_extensions.assert_type(instance, SampleClass)
self.assertEqual(instance.arg1, 1)
self.assertEqual(instance.arg2, 2)

def test_untyped_config(self):
class_config = make_untyped_config(SampleClass, arg1=2, arg2=3)
pytype_extensions.assert_type(class_config, fdl.Config)
typing_extensions.assert_type(class_config, fdl.Config)
instance = fdl.build(class_config)
pytype_extensions.assert_type(instance, Any)
typing_extensions.assert_type(instance, Any)
self.assertEqual(instance.arg1, 2)
self.assertEqual(instance.arg2, 3)

Expand Down
4 changes: 2 additions & 2 deletions fiddle/_src/experimental/auto_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from fiddle._src.experimental import auto_config_policy
from fiddle._src.experimental import autobuilders as ab
from fiddle._src.testing import test_util
import pytype_extensions
import typing_extensions


def basic_fn(arg, kwarg='test'):
Expand Down Expand Up @@ -834,7 +834,7 @@ def make_sample(max_value):
def test_exemption_type_inference(self):
exempted_func = auto_config.exempt(pass_through)
value = exempted_func(42)
pytype_extensions.assert_type(value, int)
typing_extensions.assert_type(value, int)

def test_lambda_supported_in_decorator(self):
@auto_config.auto_config(experimental_exemption_policy=lambda x: False)
Expand Down
23 changes: 12 additions & 11 deletions fiddle/_src/partial_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from absl.testing import parameterized
import fiddle as fdl
from fiddle import arg_factory
import pytype_extensions
import typing_extensions


class Tag1(fdl.Tag):
Expand Down Expand Up @@ -93,11 +93,11 @@ def test_deep_copy_partials(self):

def test_partial_for_classes(self):
class_partial = fdl.Partial(SampleClass, 'arg1', 'arg2')
pytype_extensions.assert_type(class_partial, fdl.Partial[SampleClass])
typing_extensions.assert_type(class_partial, fdl.Partial[SampleClass])
partial = fdl.build(class_partial)
pytype_extensions.assert_type(partial, Callable[..., SampleClass])
typing_extensions.assert_type(partial, Callable[..., SampleClass])
instance = partial()
pytype_extensions.assert_type(instance, SampleClass)
typing_extensions.assert_type(instance, SampleClass)
self.assertIsInstance(partial, functools.partial)
self.assertIsInstance(instance, SampleClass)
self.assertEqual(instance.arg1, 'arg1')
Expand All @@ -111,7 +111,7 @@ def test_partial_for_classes(self):

def test_partial_for_functions(self):
fn_partial = fdl.Partial(basic_fn, 1, kwarg2='kwarg2')
pytype_extensions.assert_type(
typing_extensions.assert_type(
fn_partial, fdl.Partial[Dict[str, Any]]
) # use-fiddle-overlay
self.assertEqual(fn_partial.arg1, 1)
Expand All @@ -122,11 +122,11 @@ def test_partial_for_functions(self):
fn_partial.kwarg1 = 'kwarg1'

partial = fdl.build(fn_partial)
pytype_extensions.assert_type(
typing_extensions.assert_type(
partial, Callable[..., Dict[str, Any]]
) # use-fiddle-overlay
value = partial()
pytype_extensions.assert_type(value, Dict[str, Any]) # use-fiddle-overlay
typing_extensions.assert_type(value, Dict[str, Any]) # use-fiddle-overlay
self.assertEqual(
value,
{
Expand All @@ -139,18 +139,19 @@ def test_partial_for_functions(self):

def test_typed_partial(self):
class_partial = make_typed_partial()
pytype_extensions.assert_type(class_partial, fdl.Partial[SampleClass])
typing_extensions.assert_type(class_partial, fdl.Partial[SampleClass])
partial = fdl.build(class_partial)
pytype_extensions.assert_type(partial, Callable[..., SampleClass])
10000 typing_extensions.assert_type(partial, Callable[..., SampleClass])
instance = partial(arg2=4)
self.assertEqual(instance.arg1, 1)
self.assertEqual(instance.arg2, 4)

def test_untyped_partial(self):
class_partial = make_untyped_partial(SampleClass, arg1=2)
pytype_extensions.assert_type(class_partial, fdl.Partial)
typing_extensions.assert_type(class_partial, fdl.Partial)
partial = fdl.build(class_partial)
pytype_extensions.assert_type(partial, Callable[..., Any])
# Building an unparameterized `fdl.Partial` is statically typed as `Any`.
typing_extensions.assert_type(partial, Any)
instance = partial(arg2=4)
self.assertEqual(instance.arg1, 2)
self.assertEqual(instance.arg2, 4)
Expand Down
34 changes: 20 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

# pyformat: disable

import sys
from setuptools import find_packages
from setuptools import setup
import setuptools


_dct = {}
Expand All @@ -41,14 +39,15 @@
**Authors**: Dan Holtmann-Rice, Brennan Saeta, Sergio Guadarrama
"""

# pylint: disable=g-long-ternary
setup(
setuptools.setup(
name='fiddle',
version=__version__,
include_package_data=True,
packages=find_packages(exclude=['docs']), # Required
package_data={'testdata': ['testdata/*.fiddle']},
python_requires='>=3.8',
packages=setuptools.find_namespace_packages(
include=['fiddle', 'fiddle.*'],
exclude=['*.testdata'],
), # Required
package_data={'': ['testdata/*']},
python_requires='>=3.11',
install_requires=[
'absl-py',
'graphviz',
Expand All @@ -66,13 +65,16 @@
'flax',
'graphviz',
'pytest',
'pytype',
] + [
'seqio',
# seqio depends on tensorflow-text, which is not available for
# Python 3.13+ (or macOS) in our CI configuration.
'seqio; python_version < "3.13" and sys_platform != "darwin"',
# Temporarily pin the TFDS version to avoid pip backtracking during
# unit tests.
'tfds_nightly>=4.9.2.dev202308090034',
] if sys.platform != 'darwin' else []
(
'tfds_nightly>=4.9.2.dev202308090034; '
'python_version < "3.13" and sys_platform != "darwin"'
),
],
},
description='Fiddle: A Python-first configuration library',
long_description=long_description,
Expand All @@ -94,6 +96,10 @@
# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: 3.14',

'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Mathematics',
Expand Down
Loading
0