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 diff --git a/axelrod/strategies/_strategies.py b/axelrod/strategies/_strategies.py index 1872027cf..90c2a1a26 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,17 @@ 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: + 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, diff --git a/docs/how-to/contributing/setting_up_the_environment.rst b/docs/how-to/contributing/setting_up_the_environment.rst index 2d6be2f86..c4a13f8e7 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 specify the development variant rather than the path:: + + $ python -m venv axelrod_development + $ source axelrod_development/bin/activate + $ pip install .[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..bca5566a4 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,24 @@ +from collections import defaultdict +import os +import pathlib 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) + +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: @@ -17,7 +30,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 +48,5 @@ "Programming Language :: Python :: 3 :: Only", ], python_requires=">=3.6", + extras_require=extras_require, )