Skip to content

Commit

Permalink
Move to pyproject.toml. (#1440)
Browse files Browse the repository at this point in the history
* Move to pyproject.toml.

This uses hatch.

Note I've removed the human player. I don't believe we ever use it. If
we want to we can add it back in.

* Bump version number.
  • Loading branch information
drvinceknight authored May 8, 2024
1 parent 95052da commit 9838f84
Show file tree
Hide file tree
Showing 67 changed files with 328 additions and 564 deletions.
76 changes: 0 additions & 76 deletions .github/workflows/config.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI

on: [push, pull_request]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 4
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
python-version: ["3.11", "3.12"]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: update pip
run: |
python -m pip install --upgrade pip
- name: install tox
run: |
python -m pip install tox tox-gh-actions
- name: run tox
run: |
python -m tox
1 change: 1 addition & 0 deletions axelrod/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)

import yaml

from axelrod.makes_use_of import makes_use_of
from axelrod.player import Player

Expand Down
5 changes: 3 additions & 2 deletions axelrod/fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
from tempfile import mkstemp
from typing import Any, List, Union

import axelrod as axl
import dask.dataframe as dd
import matplotlib.pyplot as plt
import numpy as np
import tqdm
from mpl_toolkits.axes_grid1 import make_axes_locatable

import axelrod as axl
from axelrod import Player
from axelrod.interaction_utils import (
compute_final_score_per_turn,
read_interactions_from_file,
)
from axelrod.strategy_transformers import DualTransformer, JossAnnTransformer
from mpl_toolkits.axes_grid1 import make_axes_locatable

Point = namedtuple("Point", "x y")

Expand Down
7 changes: 5 additions & 2 deletions axelrod/game.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Tuple, Union
from enum import Enum
from typing import Tuple, Union

import numpy as np

Expand Down Expand Up @@ -71,6 +71,7 @@ def get_value(x):
if isinstance(x, Enum):
return x.value
return x

row, col = map(get_value, pair)

return (self.A[row][col], self.B[row][col])
Expand All @@ -97,7 +98,9 @@ class Game(AsymmetricGame):
The numerical score attribute to all combinations of action pairs.
"""

def __init__(self, r: Score = 3, s: Score = 0, t: Score = 5, p: Score = 1) -> None:
def __init__(
self, r: Score = 3, s: Score = 0, t: Score = 5, p: Score = 1
) -> None:
"""Create a new game object.
Parameters
Expand Down
2 changes: 2 additions & 0 deletions axelrod/interaction_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
This is used by both the Match class and the ResultSet class which analyse
interactions.
"""

from collections import Counter, defaultdict

import pandas as pd
import tqdm

from axelrod.action import Action, str_to_actions

from .game import Game
Expand Down
11 changes: 8 additions & 3 deletions axelrod/load_data_.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pathlib
import pkgutil
from typing import Dict, List, Text, Tuple

import pkgutil

def axl_filename(path: pathlib.Path) -> pathlib.Path:
"""Given a path under Axelrod/, return absolute filepath.
Expand All @@ -27,7 +27,7 @@ def load_file(filename: str, directory: str) -> List[List[str]]:
path = str(pathlib.Path(directory) / filename)
data_bytes = pkgutil.get_data(__name__, path)
data = data_bytes.decode("UTF-8", "replace")

rows = []
for line in data.split("\n"):
if line.startswith("#") or len(line) == 0:
Expand Down Expand Up @@ -57,7 +57,12 @@ def load_pso_tables(filename="pso_gambler.csv", directory="data"):
rows = load_file(filename, directory)
d = dict()
for row in rows:
name, a, b, c, = (
(
name,
a,
b,
c,
) = (
str(row[0]),
int(row[1]),
int(row[2]),
Expand Down
1 change: 1 addition & 0 deletions axelrod/moran.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import matplotlib.pyplot as plt
import numpy as np

from axelrod import DEFAULT_TURNS, EvolvablePlayer, Game, Player
from axelrod.deterministic_cache import DeterministicCache
from axelrod.graph import Graph, complete_graph
Expand Down
3 changes: 2 additions & 1 deletion axelrod/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, Dict

import numpy as np

from axelrod import _module_random
from axelrod.action import Action
from axelrod.game import DefaultGame
Expand Down Expand Up @@ -121,7 +122,7 @@ def _post_init(self):
def _post_transform(self):
"""Handles post transform tasks such as further reclassifying."""
# Reclassify strategy post __init__, if needed.
for (reclassifier, args, kwargs) in self._reclassifiers:
for reclassifier, args, kwargs in self._reclassifiers:
self.classifier = reclassifier(self.classifier, *args, **kwargs)

def __eq__(self, other):
Expand Down
2 changes: 1 addition & 1 deletion axelrod/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _payoff_heatmap(
names: namesType,
title: titleType = None,
ax: matplotlib.axes.SubplotBase = None,
cmap: str = 'viridis'
cmap: str = "viridis",
) -> matplotlib.figure.Figure:
"""Generic heatmap plot"""

Expand Down
3 changes: 2 additions & 1 deletion axelrod/random_.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Optional

import numpy as np
from axelrod.action import Action
from numpy.random import RandomState

from axelrod.action import Action

C, D = Action.C, Action.D


Expand Down
1 change: 1 addition & 0 deletions axelrod/result_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dask.dataframe as dd
import numpy as np
import tqdm

from axelrod.action import Action

from . import eigen
Expand Down
11 changes: 1 addition & 10 deletions axelrod/strategies/_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)
# isort:skip_file
"""

import warnings

from .adaptive import Adaptive
Expand Down Expand Up @@ -152,16 +153,6 @@
from .hmm import EvolvedHMM5
from .hmm import EvolvableHMMPlayer, HMMPlayer # pylint: disable=unused-import

try:
from .human import Human # pylint: disable=unused-import
except ImportError as ie: # pragma: no cover
# Check that the expected module is missing and no other.
if ie.name == "prompt_toolkit":
warnings.warn(
"Human strategy not available because python package prompt_toolkit is not available."
)
else:
raise ie
from .hunter import (
AlternatorHunter,
CooperatorHunter,
Expand Down
3 changes: 2 additions & 1 deletion axelrod/strategies/adaptor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Dict, Tuple

from numpy import heaviside

from axelrod.action import Action
from axelrod.player import Player
from numpy import heaviside

C, D = Action.C, Action.D

Expand Down
1 change: 1 addition & 0 deletions axelrod/strategies/ann.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List, Tuple

import numpy as np

from axelrod.action import Action
from axelrod.evolvable_player import (
EvolvablePlayer,
Expand Down
4 changes: 2 additions & 2 deletions axelrod/strategies/axelrod_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

from typing import Dict, List, Optional, Tuple

from scipy.stats import chisquare

from axelrod.action import Action
from axelrod.player import Player
from axelrod.strategy_transformers import FinalTransformer
from scipy.stats import chisquare

from .memoryone import MemoryOnePlayer

Expand Down Expand Up @@ -624,7 +625,6 @@ def score_history(
opponent_history: List[Action],
score_map: Dict[Tuple[Action, Action], int],
) -> int:

"""Implements the Nydegger formula A = 16 a_1 + 4 a_2 + a_3"""
a = 0
for i, weight in [(-1, 16), (-2, 4), (-3, 1)]:
Expand Down
9 changes: 4 additions & 5 deletions axelrod/strategies/axelrod_second.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import List

import numpy as np

from axelrod.action import Action
from axelrod.interaction_utils import compute_final_score
from axelrod.player import Player
Expand Down Expand Up @@ -204,7 +205,6 @@ def strategy(self, opponent: Player) -> Action:


class SecondByTranquilizer(Player):

"""
Submitted to Axelrod's second tournament by Craig Feathers
Expand Down Expand Up @@ -341,7 +341,6 @@ def __init__(self):
self.dict = {C: 0, D: 1}

def update_state(self, opponent):

"""
Calculates the ratio values for the one_turn_after_good_defection_ratio,
two_turns_after_good_defection_ratio and the probability values,
Expand Down Expand Up @@ -1349,9 +1348,9 @@ def strategy(self, opponent: Player) -> Action:
if self.detect_streak(opponent.history[-1]):
return self.try_return(D, inc_parity=True)
if self.detect_parity_streak(opponent.history[-1]):
self.parity_streak[
self.parity_bit
] = 0 # Reset `parity_streak` when we hit the limit.
self.parity_streak[self.parity_bit] = (
0 # Reset `parity_streak` when we hit the limit.
)
self.parity_hits += (
1 # Keep track of how many times we hit the limit.
)
Expand Down
1 change: 1 addition & 0 deletions axelrod/strategies/darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
indicated by their classifier). We do not recommend putting a lot of time in to
optimising it.
"""

from typing import Optional

from axelrod.action import Action
Expand Down
1 change: 1 addition & 0 deletions axelrod/strategies/gambler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
For the original see:
https://gist.github.com/GDKO/60c3d0fd423598f3c4e4
"""

from typing import Any

from axelrod.action import Action, actions_to_str, str_to_actions
Expand Down
Loading

0 comments on commit 9838f84

Please sign in to comment.