Skip to content

Drop python 3.8 and 3.9 #9140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Aug 19, 2024
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
6 changes: 6 additions & 0 deletions .changeset/chubby-hairs-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"gradio": minor
"gradio_client": minor
---

feat:Drop python 3.8 and 3.9
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
with:
always_install_pnpm: true
python_version: "3.10"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to manually specify this b/c our CI uses the version of the action that is on main, and the one currently on main is using 3.8

skip_build: "false"
- name: Build packages
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/storybook-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
- name: install dependencies
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
with:
python_version: "3.10"
always_install_pnpm: true
skip_build: "true"
- name: build client
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-functional-lite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
always_install_pnpm: true
build_lite: true
skip_build: true
python_version: "3.10"
test: true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pngwn I added test: true to several invocations of "gradio-app/gradio/.github/actions/install-all-deps@main". The action was failing for me otherwise -- not sure how they were passing before

- run: pnpm exec playwright install chromium firefox
- name: Run Lite E2E tests
run: |
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test-functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ jobs:
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
with:
always_install_pnpm: true
- name: install outbreak_forecast dependencies
python_version: "3.10"
test: true
- name: install dependencies for specific tests
run: |
. venv/bin/activate
python -m pip install -r demo/outbreak_forecast/requirements.txt
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/website-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
with:
always_install_pnpm: true
skip_build: true
python_version: "3.10"
- name: build client
run: pnpm --filter @gradio/client build

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/website-docs-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ jobs:
- name: install dependencies
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
with:
python_version: "3.10"
skip_build: true
test: true

# generated when installing deps
- name: upload website json artifacts
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ More than 200 awesome developers have contributed to the `gradio` library, and w

Prerequisites:

- [Python 3.8+](https://www.python.org/downloads/)
- [Python 3.10+](https://www.python.org/downloads/)
- [Node.js v16.14+](https://nodejs.dev/en/download/package-manager/) (only needed if you are making changes to the frontend)
- [pnpm 8.1+](https://pnpm.io/8.x/installation) (only needed if you are making changes to the frontend)

Expand Down
5 changes: 2 additions & 3 deletions client/python/gradio_client/cli/deploy_discord.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import List, Optional
from typing import Annotated, Optional

from typer import Option
from typing_extensions import Annotated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many (but sadly not all) classes from typing_extensions are no longer needed

from gradio_client import Client

Expand All @@ -17,7 +16,7 @@ def main(
str, Option(help="Discord bot token. Get one on the discord website.")
] = None,
api_names: Annotated[
List[str], Option(help="Api names to turn into discord bots")
list[str], Option(help="Api names to turn into discord bots")
] = None,
to_id: Annotated[
Optional[str], Option(help="Name of the space used to host the discord bot")
Expand Down
9 changes: 7 additions & 2 deletions client/python/gradio_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import urllib.parse
import uuid
import warnings
from collections.abc import Callable
from concurrent.futures import Future
from dataclasses import dataclass
from datetime import datetime
from functools import partial
from pathlib import Path
from threading import Lock
from typing import Any, Callable, Literal
from typing import Any, Literal

import httpx
import huggingface_hub
Expand Down Expand Up @@ -1303,7 +1304,11 @@ def download_files(self, *data) -> tuple:

def remove_skipped_components(self, *data) -> tuple:
""""""
data = [d for d, oct in zip(data, self.output_component_types) if not oct.skip]
data = [
d
for d, oct in zip(data, self.output_component_types, strict=False)
if not oct.skip
]
return tuple(data)

def reduce_singleton_output(self, *data) -> Any:
Expand Down
12 changes: 7 additions & 5 deletions client/python/gradio_client/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _upload(
"orig_name": Path(f).name,
"data": None,
}
for f, o in zip(fs, output)
for f, o in zip(fs, output, strict=False)
]
else:
o = next(o for ix, o in enumerate(result) if indices[ix] == i)
Expand Down Expand Up @@ -207,7 +207,7 @@ def insert_state(self, *data) -> tuple:
def remove_skipped_components(self, *data) -> tuple:
data = [
d
for d, oct in zip(data, self.output_component_types)
for d, oct in zip(data, self.output_component_types, strict=False)
if oct not in utils.SKIP_COMPONENTS
]
return tuple(data)
Expand Down Expand Up @@ -235,13 +235,15 @@ def serialize(self, *data) -> tuple:

files = [
f
for f, t in zip(data, self.input_component_types)
for f, t in zip(data, self.input_component_types, strict=False)
if t in ["file", "uploadbutton"]
]
uploaded_files = self._upload(files)
data = list(data)
self._add_uploaded_files_to_data(uploaded_files, data)
o = tuple([s.serialize(d) for s, d in zip(self.serializers, data)])
o = tuple(
[s.serialize(d) for s, d in zip(self.serializers, data, strict=False)]
)
return o

def deserialize(self, *data) -> tuple:
Expand All @@ -257,7 +259,7 @@ def deserialize(self, *data) -> tuple:
hf_token=self.client.hf_token,
root_url=self.root_url,
)
for s, d in zip(self.deserializers, data)
for s, d in zip(self.deserializers, data, strict=False)
]
)
return outputs
Expand Down
2 changes: 1 addition & 1 deletion client/python/gradio_client/documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import inspect
import warnings
from collections import defaultdict
from collections.abc import Callable
from functools import lru_cache
from typing import Callable

classes_to_document = defaultdict(list)
classes_inherit_documentation = {}
Expand Down
3 changes: 2 additions & 1 deletion client/python/gradio_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import tempfile
import time
import warnings
from collections.abc import Callable, Coroutine
from dataclasses import dataclass, field
from datetime import datetime
from enum import Enum
from pathlib import Path
from threading import Lock
from typing import TYPE_CHECKING, Any, Callable, Coroutine, Literal, Optional, TypedDict
from typing import TYPE_CHECKING, Any, Literal, Optional, TypedDict

import fsspec.asyn
import httpx
Expand Down
2 changes: 1 addition & 1 deletion client/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "gradio_client"
dynamic = ["version", "dependencies", "readme"]
description = "Python library for easily interacting with trained machine learning models"
license = "Apache-2.0"
requires-python = ">=3.8"
requires-python = ">=3.10"
authors = [
{ name = "Abubakar Abid", email = "[email protected]" },
{ name = "Ali Abid", email = "[email protected]" },
Expand Down
3 changes: 2 additions & 1 deletion gradio/_simple_templates/simpledropdown.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING, Any, Callable, Sequence
from collections.abc import Callable, Sequence
from typing import TYPE_CHECKING, Any

from gradio.components.base import Component, FormComponent
from gradio.events import Events
Expand Down
3 changes: 2 additions & 1 deletion gradio/_simple_templates/simpleimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import annotations

from collections.abc import Sequence
from pathlib import Path
from typing import TYPE_CHECKING, Any, Sequence
from typing import TYPE_CHECKING, Any

from gradio_client import handle_file
from gradio_client.documentation import document
Expand Down
3 changes: 2 additions & 1 deletion gradio/_simple_templates/simpletextbox.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Callable, Sequence
from collections.abc import Callable, Sequence
from typing import TYPE_CHECKING, Any

from gradio.components.base import Component, FormComponent
from gradio.events import Events
Expand Down
31 changes: 16 additions & 15 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
import warnings
import webbrowser
from collections import defaultdict
from collections.abc import AsyncIterator, Callable, Sequence, Set
from pathlib import Path
from types import ModuleType
from typing import (
TYPE_CHECKING,
AbstractSet,
Any,
AsyncIterator,
Callable,
Literal,
Sequence,
cast,
)
from urllib.parse import urlparse, urlunparse
Expand Down Expand Up @@ -681,14 +678,14 @@ def set_event_trigger(
Component
| BlockContext
| Sequence[Component | BlockContext]
| AbstractSet[Component | BlockContext]
| Set[Component | BlockContext]
| None
),
outputs: (
Component
| BlockContext
| Sequence[Component | BlockContext]
| AbstractSet[Component | BlockContext]
| Set[Component | BlockContext]
| None
),
preprocess: bool = True,
Expand Down Expand Up @@ -754,7 +751,7 @@ def set_event_trigger(
)
for target in targets
]
if isinstance(inputs, AbstractSet):
if isinstance(inputs, Set):
inputs_as_dict = True
inputs = sorted(inputs, key=lambda x: x._id)
else:
Expand All @@ -764,7 +761,7 @@ def set_event_trigger(
elif not isinstance(inputs, Sequence):
inputs = [inputs]

if isinstance(outputs, AbstractSet):
if isinstance(outputs, Set):
outputs = sorted(outputs, key=lambda x: x._id)
elif outputs is None:
outputs = []
Expand Down Expand Up @@ -1215,7 +1212,7 @@ def iterate_over_children(children_list):
raise ValueError(
"This config is missing the 'dependencies' field and cannot be loaded."
)
for dependency, fn in zip(config["dependencies"], fns):
for dependency, fn in zip(config["dependencies"], fns, strict=False):
# We used to add a "fake_event" to the config to cache examples
# without removing it. This was causing bugs in calling gr.load
# We fixed the issue by removing "fake_event" from the config in examples.py
Expand Down Expand Up @@ -1521,7 +1518,9 @@ async def call_function(

if iterator is None: # If not a generator function that has already run
if block_fn.inputs_as_dict:
processed_input = [dict(zip(block_fn.inputs, processed_input))]
processed_input = [
dict(zip(block_fn.inputs, processed_input, strict=False))
]

processed_input, progress_index, _ = special_args(
block_fn.fn, processed_input, request, event_data
Expand Down Expand Up @@ -1928,11 +1927,11 @@ async def process_api(
)
inputs = [
await self.preprocess_data(block_fn, list(i), state, explicit_call)
for i in zip(*inputs)
for i in zip(*inputs, strict=False)
]
result = await self.call_function(
block_fn,
list(zip(*inputs)),
list(zip(*inputs, strict=False)),
None,
request,
event_id,
Expand All @@ -1943,11 +1942,11 @@ async def process_api(
preds = result["prediction"]
data = [
await self.postprocess_data(block_fn, list(o), state)
for o in zip(*preds)
for o in zip(*preds, strict=False)
]
if root_path is not None:
data = processing_utils.add_root_url(data, root_path, None) # type: ignore
data = list(zip(*data))
data = list(zip(*data, strict=False))
is_generating, iterator = None, None
else:
old_iterator = iterator
Expand All @@ -1972,7 +1971,9 @@ async def process_api(
if state:
changed_state_ids = [
state_id
for hash_value, state_id in zip(hashed_values, state_ids_to_track)
for hash_value, state_id in zip(
hashed_values, state_ids_to_track, strict=False
)
if hash_value != utils.deep_hash(state[state_id])
]

Expand Down
3 changes: 2 additions & 1 deletion gradio/chat_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import functools
import inspect
import warnings
from typing import AsyncGenerator, Callable, Literal, Union, cast
from collections.abc import AsyncGenerator, Callable
from typing import Literal, Union, cast

import anyio
from gradio_client.documentation import document
Expand Down
21 changes: 2 additions & 19 deletions gradio/cli/commands/components/_docs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,31 +145,14 @@ def get_type_arguments(type_hint) -> tuple:

def get_container_name(arg):
"""Gets a human readable name for a type."""

# This is a bit of a hack to get the generic type for python 3.8
typing_genericalias = getattr(typing, "_GenericAlias", None)
types_genericalias = getattr(types, "GenericAlias", None)
types_uniontype = getattr(types, "UnionType", None)
if types_genericalias is None:
raise ValueError(
"""Unable to find GenericAlias type. This is likely because you are using an older version of python. Please upgrade to python 3.10 or higher."""
)

generic_type_tuple = (
(types_genericalias,)
if typing_genericalias is None
else (types_genericalias, typing_genericalias)
)

if inspect.isclass(arg):
return arg.__name__
if isinstance(arg, (generic_type_tuple)):
if isinstance(arg, types.GenericAlias):
return arg.__origin__.__name__
elif types_uniontype and isinstance(arg, types_uniontype):
elif isinstance(arg, types.UnionType):
return "Union"
elif getattr(arg, "__origin__", None) is typing.Literal:
return "Literal"

else:
return str(arg)

Expand Down
3 changes: 1 addition & 2 deletions gradio/cli/commands/components/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import shutil
import subprocess
from pathlib import Path
from typing import Optional
from typing import Annotated, Optional

import semantic_version
import typer
from tomlkit import dump, parse
from typing_extensions import Annotated

import gradio
from gradio.analytics import custom_component_analytics
Expand Down
Loading
Loading