Skip to content
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

Drop support for Python 3.8 #1756

Merged
merged 4 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 0 additions & 2 deletions .github/workflows/build_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ jobs:
python-version: "3.10"
- os: ubuntu
python-version: "3.9"
- os: ubuntu
python-version: "3.8"
# Disabled for now. See https://github.com/projectmesa/mesa/issues/1253
#- os: ubuntu
# python-version: 'pypy-3.8'
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/intro_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"source": [
"### Tutorial Setup\n",
"\n",
"Create and activate a [virtual environment](http://docs.python-guide.org/en/latest/dev/virtualenvs/). *Python version 3.8 or higher is required*.\n",
"Create and activate a [virtual environment](http://docs.python-guide.org/en/latest/dev/virtualenvs/). *Python version 3.9 or higher is required*.\n",
Copy link
Member

Choose a reason for hiding this comment

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

Do we still want to do 3.9 as it seems Solara only works with 3.10 or higher?

Copy link
Contributor

Choose a reason for hiding this comment

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

Quite the opposite, solara still supports Python 3.6. They are quite proud of it, although i cant find the source for that claim right now. But their unit tests still run on Python 3.6 https://github.com/widgetti/solara/blob/master/.github/workflows/unittest.yml

Copy link
Member

Choose a reason for hiding this comment

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

Following SPEC 0, the successor of NEP 29, Python 3.9 can also be dropped at this point.

That would allow us to start using Structural Pattern Matching (also in examples) and use new typing features. See What’s New In Python 3.10.

Users still on Python 3.8 and 3.9 can of course still keep using the current Mesa versions, as always.

"\n",
"Install Mesa:\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions mesa/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import warnings
import weakref
from collections import defaultdict
from collections.abc import MutableSet, Sequence
from collections.abc import Iterable, Iterator, MutableSet, Sequence
from random import Random

# mypy
from typing import TYPE_CHECKING, Any, Callable, Iterable, Iterator
from typing import TYPE_CHECKING, Any, Callable

if TYPE_CHECKING:
# We ensure that these are not imported during runtime to prevent cyclic
Expand Down
23 changes: 9 additions & 14 deletions mesa/batchrunner.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import itertools
from collections.abc import Iterable, Mapping
from functools import partial
from multiprocessing import Pool
from typing import (
rht marked this conversation as resolved.
Show resolved Hide resolved
Any,
Dict,
Iterable,
List,
Mapping,
Optional,
Tuple,
Type,
Union,
)

Expand All @@ -19,15 +14,15 @@


def batch_run(
model_cls: Type[Model],
model_cls: type[Model],
parameters: Mapping[str, Union[Any, Iterable[Any]]],
# We still retain the Optional[int] because users may set it to None (i.e. use all CPUs)
number_processes: Optional[int] = 1,
iterations: int = 1,
data_collection_period: int = -1,
max_steps: int = 1000,
display_progress: bool = True,
) -> List[Dict[str, Any]]:
) -> list[dict[str, Any]]:
"""Batch run a mesa model with a set of parameter values.

Parameters
Expand Down Expand Up @@ -67,7 +62,7 @@ def batch_run(
data_collection_period=data_collection_period,
)

results: List[Dict[str, Any]] = []
results: list[dict[str, Any]] = []

with tqdm(total=len(runs_list), disable=not display_progress) as pbar:
if number_processes == 1:
Expand All @@ -86,7 +81,7 @@ def batch_run(

def _make_model_kwargs(
parameters: Mapping[str, Union[Any, Iterable[Any]]]
) -> List[Dict[str, Any]]:
) -> list[dict[str, Any]]:
"""Create model kwargs from parameters dictionary.

Parameters
Expand Down Expand Up @@ -116,11 +111,11 @@ def _make_model_kwargs(


def _model_run_func(
model_cls: Type[Model],
run: Tuple[int, int, Dict[str, Any]],
model_cls: type[Model],
run: tuple[int, int, dict[str, Any]],
max_steps: int,
data_collection_period: int,
) -> List[Dict[str, Any]]:
) -> list[dict[str, Any]]:
"""Run a single model run and collect model and agent data.

Parameters
Expand Down Expand Up @@ -185,7 +180,7 @@ def _model_run_func(
def _collect_data(
model: Model,
step: int,
) -> Tuple[Dict[str, Any], List[Dict[str, Any]]]:
) -> tuple[dict[str, Any], list[dict[str, Any]]]:
"""Collect model and agent data from a model using mesas datacollector."""
dc = model.datacollector

Expand Down
4 changes: 2 additions & 2 deletions mesa/experimental/jupyter_viz.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import threading
from typing import List, Optional
from typing import Optional

import matplotlib.pyplot as plt
import networkx as nx
Expand Down Expand Up @@ -317,7 +317,7 @@ def change_handler(value, name=name):


@solara.component
def SpaceMatplotlib(model, agent_portrayal, dependencies: Optional[List[any]] = None):
def SpaceMatplotlib(model, agent_portrayal, dependencies: Optional[list[any]] = None):
space_fig = Figure()
space_ax = space_fig.subplots()
space = getattr(model, "grid", None)
Expand Down
12 changes: 4 additions & 8 deletions mesa/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@
import itertools
import math
import warnings
from collections.abc import Iterable, Iterator, Sequence
from numbers import Real
from typing import (
rht marked this conversation as resolved.
Show resolved Hide resolved
Any,
Callable,
Iterable,
Iterator,
List,
Sequence,
Tuple,
TypeVar,
Union,
cast,
Expand All @@ -48,15 +44,15 @@
# for better performance, we calculate the tuple to use in the is_integer function
_types_integer = (int, np.integer)

Coordinate = Tuple[int, int]
Coordinate = tuple[int, int]
# used in ContinuousSpace
FloatCoordinate = Union[Tuple[float, float], npt.NDArray[float]]
FloatCoordinate = Union[tuple[float, float], npt.NDArray[float]]
NetworkCoordinate = int

Position = Union[Coordinate, FloatCoordinate, NetworkCoordinate]

GridContent = Union[Agent, None]
MultiGridContent = List[Agent]
MultiGridContent = list[Agent]

F = TypeVar("F", bound=Callable[..., Any])

Expand Down
3 changes: 2 additions & 1 deletion mesa/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
import heapq
import warnings
import weakref
from collections.abc import Iterable

# mypy
from typing import Iterable, Union
from typing import Union

from mesa.agent import Agent, AgentSet
from mesa.model import Model
Expand Down
11 changes: 3 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"
name = "Mesa"
description = "Agent-based modeling (ABM) in Python 3+"
license = { text = "Apache 2.0" }
requires-python = ">=3.8"
requires-python = ">=3.9"
authors = [
{ name = "Project Mesa Team", email = "projectmesa@googlegroups.com" },
]
Expand All @@ -28,7 +28,6 @@ classifiers = [
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: Apache Software License",
Expand Down Expand Up @@ -58,13 +57,9 @@ dev = [
"pytest-cov",
"sphinx",
]
# Explicitly install ipykernel for Python 3.8.
# See https://stackoverflow.com/questions/28831854/how-do-i-add-python3-kernel-to-jupyter-ipython
# Could be removed in the future
docs = [
"sphinx",
"ipython",
"ipykernel",
"pydata_sphinx_theme",
"seaborn",
"myst-nb",
Expand Down Expand Up @@ -134,6 +129,6 @@ extend-ignore = [
"ISC001", # ruff format asks to disable this feature
]
extend-exclude = ["docs", "build"]
# Hardcode to Python 3.8.
# Hardcode to Python 3.9.
# Reminder to update mesa-examples if the value below is changed.
target-version = "py38"
target-version = "py39"