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

Split requirements.txt to factor out hypothesis and prompt_toolkit #1407

Merged
merged 8 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion .github/workflows/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion axelrod/strategies/_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
)
# isort:skip_file
"""
import warnings

from .adaptive import Adaptive
from .adaptor import AdaptorBrief, AdaptorLong
from .alternator import Alternator
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions docs/how-to/contributing/setting_up_the_environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ 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.

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
----------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`::
Copy link
Member

Choose a reason for hiding this comment

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

Love this.


$ pip install axelrod[Human]

You can also build it from source if you would like to::

Expand Down
3 changes: 3 additions & 0 deletions requirements/development.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-r requirements.txt
-r human.txt
hypothesis==5.19.3
2 changes: 2 additions & 0 deletions requirements/human.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-r requirements.txt
prompt-toolkit>=3.0
4 changes: 1 addition & 3 deletions requirements.txt → requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 21 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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"],
Expand All @@ -35,4 +48,5 @@
"Programming Language :: Python :: 3 :: Only",
],
python_requires=">=3.6",
extras_require=extras_require,
)