Skip to content

Commit

Permalink
Replace setup.py with pyproject.toml (#875)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjshoots authored Jan 4, 2023
1 parent bbf00cc commit 6bde09b
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 101 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linux-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
run: |
sudo apt-get install python3-opengl xvfb
pip install -e .[all]
pip install -e .[tests]
AutoROM -v
- name: Source distribution test
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/macos-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- name: Install dependencies
run: |
pip install -e .[all]
pip install -e .[tests]
AutoROM -v
- name: Full Python tests
run: |
Expand Down
6 changes: 3 additions & 3 deletions pettingzoo/test/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def play_test(env, observation_0, num_cycles):
if terminated or truncated:
action = None
elif isinstance(prev_observe, dict) and "action_mask" in prev_observe:
action = random.choice(np.flatnonzero(prev_observe["action_mask"]))
action = random.choice(np.flatnonzero(prev_observe["action_mask"]).tolist())
else:
action = env.action_space(agent).sample()

Expand Down Expand Up @@ -319,7 +319,7 @@ def play_test(env, observation_0, num_cycles):
if terminated or truncated:
action = None
elif isinstance(obs, dict) and "action_mask" in obs:
action = random.choice(np.flatnonzero(obs["action_mask"]))
action = random.choice(np.flatnonzero(obs["action_mask"]).tolist())
else:
action = env.action_space(agent).sample()
assert isinstance(terminated, bool), "terminated from last is not True or False"
Expand Down Expand Up @@ -350,7 +350,7 @@ def test_action_flexibility(env):
if terminated or truncated:
action = None
elif isinstance(obs, dict) and "action_mask" in obs:
action = random.choice(np.flatnonzero(obs["action_mask"]))
action = random.choice(np.flatnonzero(obs["action_mask"]).tolist())
else:
action = 0
env.step(action)
Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/test/bombardment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def bombardment_test(env, cycles=10000):
if termination or truncation:
action = None
elif isinstance(obs, dict) and "action_mask" in obs:
action = random.choice(np.flatnonzero(obs["action_mask"]))
action = random.choice(np.flatnonzero(obs["action_mask"]).tolist())
else:
action = env.action_space(agent).sample()
next_observe = env.step(action)
Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/test/performance_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def performance_benchmark(env):
if termination or truncation:
action = None
elif isinstance(obs, dict) and "action_mask" in obs:
action = random.choice(np.flatnonzero(obs["action_mask"]))
action = random.choice(np.flatnonzero(obs["action_mask"]).tolist())
else:
action = env.action_space(agent).sample()
env.step(action)
Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/test/render_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def collect_render_results(env):
if terminated or truncated:
action = None
elif isinstance(obs, dict) and "action_mask" in obs:
action = random.choice(np.flatnonzero(obs["action_mask"]))
action = random.choice(np.flatnonzero(obs["action_mask"]).tolist())
else:
action = env.action_space(agent).sample()
env.step(action)
Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/test/seed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def calc_hash(new_env, rand_issue, max_env_iters):
if terminated or truncated:
action = None
elif isinstance(obs, dict) and "action_mask" in obs:
action = sampler.choice(np.flatnonzero(obs["action_mask"]))
action = sampler.choice(np.flatnonzero(obs["action_mask"]).tolist())
else:
action = new_env.action_space(agent).sample()
new_env.step(action)
Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/utils/average_total_reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def average_total_reward(env, max_episodes=100, max_steps=10000000000):
if termination or truncation:
action = None
elif isinstance(obs, dict) and "action_mask" in obs:
action = random.choice(np.flatnonzero(obs["action_mask"]))
action = random.choice(np.flatnonzero(obs["action_mask"]).tolist())
else:
action = env.action_space(agent).sample()
env.step(action)
Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/utils/random_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def random_demo(env, render=True, episodes=1):
if termination or truncation:
action = None
elif isinstance(obs, dict) and "action_mask" in obs:
action = random.choice(np.flatnonzero(obs["action_mask"]))
action = random.choice(np.flatnonzero(obs["action_mask"]).tolist())
else:
action = env.action_space(agent).sample()
env.step(action)
Expand Down
89 changes: 88 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,92 @@
[tool.pyright]
# Package ######################################################################

[build-system]
requires = ["setuptools >= 61.0.0"]
build-backend = "setuptools.build_meta"

[project]
name = "pettingzoo"
description = "Gymnasium for multi-agent reinforcement learning."
readme = "README.md"
requires-python = ">= 3.7"
authors = [{ name = "Farama Foundation", email = "[email protected]" }]
license = { text = "MIT License" }
keywords = ["Reinforcement Learning", "game", "RL", "AI", "gymnasium"]
classifiers = [
"Development Status :: 4 - Beta", # change to `5 - Production/Stable` when ready
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
]

dependencies = [
"numpy>=1.21.0",
"gymnasium>=0.26.0",
]
dynamic = ["version"]

[project.optional-dependencies]
# Update dependencies in `all` if any are added or removed
atari = ["multi_agent_ale_py==0.1.11", "pygame==2.1.3.dev8"]
classic = [
"chess==1.7.0",
"rlcard==1.0.5",
"pygame==2.1.3.dev8",
"hanabi_learning_environment==0.0.4",
]
butterfly = ["pygame==2.1.3.dev8", "pymunk==6.2.0"]
mpe = ["pygame==2.1.3.dev8"]
sisl = ["pygame==2.1.3.dev8", "box2d-py==2.3.5", "scipy>=1.4.1"]
other = ["pillow>=8.0.1"]
tests = [
"pynput",
"pytest",
"AutoROM",
"pytest",
"pytest-cov",
"pre-commit",
]
all = [
"multi_agent_ale_py==0.1.11",
"pygame==2.1.3.dev8",
"chess==1.7.0",
"rlcard==1.0.5",
"hanabi_learning_environment==0.0.4",
"pymunk==6.2.0",
"box2d-py==2.3.5",
"scipy>=1.4.1",
"pillow>=8.0.1",
]

[project.urls]
Homepage = "https://farama.org"
Repository = "https://github.com/Farama-Foundation/PettingZoo"
Documentation = "https://pettingzoo.farama.org"
"Bug Report" = "https://github.com/Farama-Foundation/PettingZoo/issues"

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
include = ["pettingzoo", "pettingzoo.*"]

# Linters and Test tools #######################################################

[tool.black]
safe = true

[tool.isort]
atomic = true
profile = "black"
src_paths = ["pettingzoo", "test"]

[tool.pyright]
# add any files/directories with type declaration to include
include = [
"pettingzoo/",
Expand Down
93 changes: 8 additions & 85 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,98 +1,21 @@
"""Sets up the PettingZoo module."""
"""Setups the project."""

from setuptools import find_packages, setup
import pathlib

from setuptools import setup

def get_description():
"""Gets the description from the readme."""
with open("README.md") as fh:
long_description = ""
header_count = 0
for line in fh:
if line.startswith("##"):
header_count += 1
if header_count < 2:
long_description += line
else:
break
return header_count, long_description
CWD = pathlib.Path(__file__).absolute().parent


def get_version():
"""Gets the pettingzoo version."""
path = "pettingzoo/__init__.py"
with open(path) as file:
lines = file.readlines()
path = CWD / "pettingzoo" / "__init__.py"
content = path.read_text()

for line in lines:
for line in content.splitlines():
if line.startswith("__version__"):
return line.strip().split()[-1].strip().strip('"')
raise RuntimeError("bad version data in __init__.py")


extras = {
"atari": ["multi_agent_ale_py==0.1.11", "pygame==2.1.3.dev8"],
"classic": [
"chess==1.7.0",
"rlcard==1.0.5",
"pygame==2.1.3.dev8",
"hanabi_learning_environment==0.0.4",
],
"butterfly": ["pygame==2.1.3.dev8", "pymunk==6.2.0"],
"mpe": ["pygame==2.1.3.dev8"],
"sisl": ["pygame==2.1.3.dev8", "box2d-py==2.3.5", "scipy>=1.4.1"],
"other": ["pillow>=8.0.1"],
"tests": [
"pynput",
"pytest",
"codespell",
"flake8",
"isort",
"AutoROM",
"bandit",
"pytest",
"pytest-cov",
"pre-commit",
],
}

extras["all"] = (
extras["atari"]
+ extras["classic"]
+ extras["butterfly"]
+ extras["mpe"]
+ extras["sisl"]
+ extras["other"]
+ extras["tests"]
)

version = get_version()
header_count, long_description = get_description()

setup(
name="PettingZoo",
version=version,
author="Farama Foundation",
author_email="[email protected]",
description="Gymnasium for multi-agent reinforcement learning",
url="https://pettingzoo.farama.org/",
license_files=("LICENSE.txt",),
long_description=long_description,
long_description_content_type="text/markdown",
keywords=["Reinforcement Learning", "game", "RL", "AI", "gymnasium"],
python_requires=">=3.7, <3.12",
packages=["pettingzoo"]
+ ["pettingzoo." + pkg for pkg in find_packages("pettingzoo")],
include_package_data=True,
install_requires=["numpy>=1.18.0", "gymnasium>=0.26.0"],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
extras_require=extras,
)
setup(name="pettingzoo", version=get_version())
1 change: 1 addition & 0 deletions test/doc_examples_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from docs.code_examples import aec_rps, parallel_rps

from pettingzoo.test import api_test, parallel_api_test


Expand Down
2 changes: 1 addition & 1 deletion tutorials/CleanRL/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SuperSuit==3.6.0
torch==1.13.1
pettingzoo==1.22.0
pettingzoo==1.22.3
2 changes: 1 addition & 1 deletion tutorials/EnvironmentCreation/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pettingzoo==1.22.1
pettingzoo==1.22.3
2 changes: 1 addition & 1 deletion tutorials/Ray/render_rllib_pistonball.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from ray.rllib.env.wrappers.pettingzoo_env import PettingZooEnv
from ray.rllib.models import ModelCatalog
from ray.tune.registry import register_env
from tutorials.Ray.rllib_pistonball import CNNModelV2

from pettingzoo.butterfly import pistonball_v6
from tutorials.Ray.rllib_pistonball import CNNModelV2

raise NotImplementedError(
"There are currently bugs in this tutorial, we will fix them soon."
Expand Down
2 changes: 1 addition & 1 deletion tutorials/Ray/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Pillow==9.3.0
torch==1.13.1
SuperSuit==3.6.0
ray[rllib]==2
pettingzoo==1.22.0
pettingzoo==1.22.3
4 changes: 2 additions & 2 deletions tutorials/Tianshou/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pettingzoo[classic]==1.22.1
pettingzoo[classic]==1.22.3
packaging==21.3
git+https://github.com/WillDudley/tianshou.git
git+https://github.com/WillDudley/tianshou.git

0 comments on commit 6bde09b

Please sign in to comment.