From 8ac3341d8c9fd98cf1cfac88a8d930807f3c49a7 Mon Sep 17 00:00:00 2001 From: Marc Harper Date: Sat, 31 Dec 2022 14:45:43 -0800 Subject: [PATCH 1/8] Split requirements.txt to factor out hypothesis and prompt_toolkit --- axelrod/strategies/_strategies.py | 8 ++++++- .../setting_up_the_environment.rst | 12 +++++++--- .../installation.rst | 3 +++ requirements/development.txt | 3 +++ requirements/human.txt | 2 ++ .../requirements.txt | 4 +--- setup.py | 22 +++++++++++++------ 7 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 requirements/development.txt create mode 100644 requirements/human.txt rename requirements.txt => requirements/requirements.txt (84%) diff --git a/axelrod/strategies/_strategies.py b/axelrod/strategies/_strategies.py index 1872027cf..fe6a40d1e 100644 --- a/axelrod/strategies/_strategies.py +++ b/axelrod/strategies/_strategies.py @@ -20,6 +20,8 @@ ) # isort:skip_file """ +import warnings + from .adaptive import Adaptive from .adaptor import AdaptorBrief, AdaptorLong from .alternator import Alternator @@ -149,7 +151,11 @@ from .handshake import Handshake from .hmm import EvolvedHMM5 from .hmm import EvolvableHMMPlayer, HMMPlayer # pylint: disable=unused-import -from .human import Human # pylint: disable=unused-import +try: + import prompt_toolkit + from .human import Human # pylint: disable=unused-import +except ImportError: + warnings.warn("Human strategy not available because python package prompt_toolkit is not available.") from .hunter import ( AlternatorHunter, CooperatorHunter, diff --git a/docs/how-to/contributing/setting_up_the_environment.rst b/docs/how-to/contributing/setting_up_the_environment.rst index 2d6be2f86..adb91bc86 100644 --- a/docs/how-to/contributing/setting_up_the_environment.rst +++ b/docs/how-to/contributing/setting_up_the_environment.rst @@ -4,9 +4,9 @@ Setting up the environment Installing all dependencies --------------------------- -All dependencies can be installed by running:: +All development dependencies can be installed by running:: - $ pip install -r requirements.txt + $ pip install -r requirements/development.txt It is recommended to do this using a virtual environment tool of your choice. @@ -14,7 +14,13 @@ For example, when using the virtual environment library :code:`venv`:: $ python -m venv axelrod_development $ source axelrod_development/bin/activate - $ pip install -r requirements.txt + $ pip install -r requirements/development.txt + +Alternatively, you can use `pip` and specify the development variant:: + + $ python -m venv axelrod_development + $ source axelrod_development/bin/activate + $ pip install axelrod[Development] The git workflow ---------------- diff --git a/docs/tutorials/new_to_game_theory_and_or_python/installation.rst b/docs/tutorials/new_to_game_theory_and_or_python/installation.rst index 4a2c38170..b8a16be63 100644 --- a/docs/tutorials/new_to_game_theory_and_or_python/installation.rst +++ b/docs/tutorials/new_to_game_theory_and_or_python/installation.rst @@ -10,6 +10,9 @@ repository:: $ pip install axelrod +If you want to have access to the manual Human strategy for interactive play, use the following command to also install `prompt_toolkit`:: + + $ pip install axelrod[Human] You can also build it from source if you would like to:: diff --git a/requirements/development.txt b/requirements/development.txt new file mode 100644 index 000000000..ebe5ad6aa --- /dev/null +++ b/requirements/development.txt @@ -0,0 +1,3 @@ +-r requirements.txt +-r human.txt +hypothesis==5.19.3 diff --git a/requirements/human.txt b/requirements/human.txt new file mode 100644 index 000000000..d595d21e2 --- /dev/null +++ b/requirements/human.txt @@ -0,0 +1,2 @@ +-r requirements.txt +prompt-toolkit>=3.0 diff --git a/requirements.txt b/requirements/requirements.txt similarity index 84% rename from requirements.txt rename to requirements/requirements.txt index 36983f865..f0c611e2d 100644 --- a/requirements.txt +++ b/requirements/requirements.txt @@ -2,13 +2,11 @@ cloudpickle>=0.2.2 fsspec>=0.6.0 toolz>=0.8.2 - dask>=2.9.2 -hypothesis==5.19.3 + matplotlib>=3.0.3 numpy>=1.17.4 pandas>=1.0.0 -prompt-toolkit>=3.0 pyyaml>=5.1 scipy>=1.3.3 tqdm>=4.39.0 diff --git a/setup.py b/setup.py index 3cbf00e22..27b16e8c0 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,18 @@ +from collections import defaultdict +import os from setuptools import setup -# Read in the requirements.txt file -with open("requirements.txt") as f: - requirements = [] - for library in f.read().splitlines(): - if "hypothesis" not in library: # Skip: used only for dev - requirements.append(library) +# Read in the requirements files. +requirements = defaultdict(list) +with os.listdir("requirements/") as filenames: + for filename in filenames: + variant = filename.split('.')[0] + with open(filename) as libraries: + for library in libraries: + if len(library) > 0 and (not library.startswith('-r')): + requirements[variant].append(library) +install_requires=requirements['requirements'] +del requirements['requirements'] # Read in long description with open("README.rst", "r") as f: @@ -17,7 +24,7 @@ setup( name="Axelrod", version=__version__, - install_requires=requirements, + install_requires=install_requires, author="Vince Knight, Owen Campbell, Karol Langner, Marc Harper", author_email=("axelrod-python@googlegroups.com"), packages=["axelrod", "axelrod.strategies", "axelrod.data"], @@ -35,4 +42,5 @@ "Programming Language :: Python :: 3 :: Only", ], python_requires=">=3.6", + extras_require=requirements, ) From d6a4736a34f6223562b2ed6268fc01db1a6f679b Mon Sep 17 00:00:00 2001 From: Marc Date: Sat, 31 Dec 2022 15:01:21 -0800 Subject: [PATCH 2/8] Point config.yml to new requirements file --- .github/workflows/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index 64df07049..15b24ee8e 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -25,7 +25,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install -r requirements.txt + python -m pip install -r requirements/development.txt - name: Check that documentation builds run: | python -m pip install sphinx From a317bb069eb841b3eb1da757132cea6b9995cbbc Mon Sep 17 00:00:00 2001 From: Marc Harper Date: Mon, 2 Jan 2023 12:03:41 -0800 Subject: [PATCH 3/8] Rewrite setup.py to use pathlib --- setup.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 27b16e8c0..a26b6d7b6 100644 --- a/setup.py +++ b/setup.py @@ -1,18 +1,24 @@ from collections import defaultdict import os +import pathlib from setuptools import setup # Read in the requirements files. requirements = defaultdict(list) -with os.listdir("requirements/") as filenames: - for filename in filenames: - variant = filename.split('.')[0] - with open(filename) as libraries: - for library in libraries: - if len(library) > 0 and (not library.startswith('-r')): - requirements[variant].append(library) + +requirements_directory = pathlib.Path.cwd() / "requirements" +for filename in requirements_directory.glob('*.txt'): + variant = filename.stem + with filename.open() as libraries: + for library in libraries: + if len(library) > 0 and (not library.startswith('-r')): + requirements[variant].append(library.strip()) + +# Grab the default requirements install_requires=requirements['requirements'] +# Delete the default from the dictionary for the extra variants. del requirements['requirements'] +extras_require = dict(requirements) # Read in long description with open("README.rst", "r") as f: @@ -42,5 +48,5 @@ "Programming Language :: Python :: 3 :: Only", ], python_requires=">=3.6", - extras_require=requirements, + extras_require=extras_require, ) From b70c90915a4f0a50b4d83b5db5d83311df98b95f Mon Sep 17 00:00:00 2001 From: Marc Harper Date: Mon, 2 Jan 2023 12:35:35 -0800 Subject: [PATCH 4/8] Correct documentation update --- docs/how-to/contributing/setting_up_the_environment.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/how-to/contributing/setting_up_the_environment.rst b/docs/how-to/contributing/setting_up_the_environment.rst index adb91bc86..c4a13f8e7 100644 --- a/docs/how-to/contributing/setting_up_the_environment.rst +++ b/docs/how-to/contributing/setting_up_the_environment.rst @@ -16,11 +16,11 @@ For example, when using the virtual environment library :code:`venv`:: $ source axelrod_development/bin/activate $ pip install -r requirements/development.txt -Alternatively, you can use `pip` and specify the development variant:: +Alternatively, you can specify the development variant rather than the path:: $ python -m venv axelrod_development $ source axelrod_development/bin/activate - $ pip install axelrod[Development] + $ pip install .[development] The git workflow ---------------- From 57ab0e9b31349d5951949a935d6ae8ad34a33077 Mon Sep 17 00:00:00 2001 From: Marc Harper Date: Thu, 5 Jan 2023 17:32:51 -0800 Subject: [PATCH 5/8] Attempt to exclude condition import from coverage --- axelrod/strategies/_strategies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axelrod/strategies/_strategies.py b/axelrod/strategies/_strategies.py index fe6a40d1e..ddef8c08c 100644 --- a/axelrod/strategies/_strategies.py +++ b/axelrod/strategies/_strategies.py @@ -151,7 +151,7 @@ from .handshake import Handshake from .hmm import EvolvedHMM5 from .hmm import EvolvableHMMPlayer, HMMPlayer # pylint: disable=unused-import -try: +try: # pragma: no cover import prompt_toolkit from .human import Human # pylint: disable=unused-import except ImportError: From b8f2938ad4d926a2622403f1a80058e139ca7b48 Mon Sep 17 00:00:00 2001 From: Marc Harper Date: Sat, 7 Jan 2023 17:07:21 -0800 Subject: [PATCH 6/8] Change pragma no cover for human strategy inclusion --- axelrod/strategies/_strategies.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/axelrod/strategies/_strategies.py b/axelrod/strategies/_strategies.py index ddef8c08c..6ce8c9382 100644 --- a/axelrod/strategies/_strategies.py +++ b/axelrod/strategies/_strategies.py @@ -151,10 +151,10 @@ from .handshake import Handshake from .hmm import EvolvedHMM5 from .hmm import EvolvableHMMPlayer, HMMPlayer # pylint: disable=unused-import -try: # pragma: no cover +try: import prompt_toolkit from .human import Human # pylint: disable=unused-import -except ImportError: +except ImportError: # pragma: no cover warnings.warn("Human strategy not available because python package prompt_toolkit is not available.") from .hunter import ( AlternatorHunter, From a6e64cf326a6a3b13c7ba3d0dff7a71f28fa02ca Mon Sep 17 00:00:00 2001 From: Marc Date: Sun, 22 Jan 2023 17:47:49 -0800 Subject: [PATCH 7/8] Attempt to fix unused-import check for human strategy when prompt_toolkit is missing --- axelrod/strategies/_strategies.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/axelrod/strategies/_strategies.py b/axelrod/strategies/_strategies.py index 6ce8c9382..a93dc4b43 100644 --- a/axelrod/strategies/_strategies.py +++ b/axelrod/strategies/_strategies.py @@ -152,10 +152,13 @@ from .hmm import EvolvedHMM5 from .hmm import EvolvableHMMPlayer, HMMPlayer # pylint: disable=unused-import try: - import prompt_toolkit from .human import Human # pylint: disable=unused-import -except ImportError: # pragma: no cover - warnings.warn("Human strategy not available because python package prompt_toolkit is not available.") +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, From b0873b9c252c85f0203b6510cfbbdc6d9ed7a153 Mon Sep 17 00:00:00 2001 From: Marc Harper Date: Sun, 22 Jan 2023 18:23:47 -0800 Subject: [PATCH 8/8] Format with black --- axelrod/strategies/_strategies.py | 7 +++++-- setup.py | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/axelrod/strategies/_strategies.py b/axelrod/strategies/_strategies.py index a93dc4b43..90c2a1a26 100644 --- a/axelrod/strategies/_strategies.py +++ b/axelrod/strategies/_strategies.py @@ -151,12 +151,15 @@ from .handshake import Handshake 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 +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.") + warnings.warn( + "Human strategy not available because python package prompt_toolkit is not available." + ) else: raise ie from .hunter import ( diff --git a/setup.py b/setup.py index a26b6d7b6..bca5566a4 100644 --- a/setup.py +++ b/setup.py @@ -7,17 +7,17 @@ requirements = defaultdict(list) requirements_directory = pathlib.Path.cwd() / "requirements" -for filename in requirements_directory.glob('*.txt'): +for filename in requirements_directory.glob("*.txt"): variant = filename.stem with filename.open() as libraries: for library in libraries: - if len(library) > 0 and (not library.startswith('-r')): + if len(library) > 0 and (not library.startswith("-r")): requirements[variant].append(library.strip()) # Grab the default requirements -install_requires=requirements['requirements'] +install_requires = requirements["requirements"] # Delete the default from the dictionary for the extra variants. -del requirements['requirements'] +del requirements["requirements"] extras_require = dict(requirements) # Read in long description