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

Enable dependabot #31

Merged
merged 4 commits into from
Apr 17, 2024
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
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
6 changes: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Build and test
on: [push, pull_request]
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -13,10 +13,8 @@ jobs:
run: python -m pip install --upgrade build
- name: Install dependencies
run: python -m pip install '.[dev]'
- name: Lint
run: python -m black --check flask_mab tests
- name: Run tests
run: pytest
run: tox
- name: Build dist
run: python -m build .
- name: Build docs
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ jobs:
run: python -m pip install --upgrade build
- name: Install dependencies
run: python -m pip install '.[dev]'
- name: Lint
run: python -m black --check flask_mab tests
- name: Run tests
run: pytest
run: tox
- name: Build dist
run: python -m build .
- name: Build docs
Expand Down
10 changes: 2 additions & 8 deletions flask_mab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,15 @@
:license: BSD, see LICENSE for more details.
"""

from flask import current_app, g, request
from flask import current_app, request
import json
import flask_mab.storage
from flask_mab.mab import Mab
import types
from collections import namedtuple
from flask import _request_ctx_stack
from functools import wraps

try:
from flask import _app_ctx_stack as stack
except ImportError:
from flask import _request_ctx_stack as stack

__version__ = "2.0.1"
__version__ = "3.0.0"


def choose_arm(bandit):
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ dev = [
"mock==5.0.2",
"sphinx-pyproject==0.1.0",
"sphinx==7.0.1",
"Pallets-Sphinx-Themes==2.1.1"
"Pallets-Sphinx-Themes==2.1.1",
"tox==4.14.2"
]

[tool.sphinx-pyproject]
Expand Down
21 changes: 8 additions & 13 deletions tests/test_bandits.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ def save_results(self, results, output_stream):
)
sys.stdout.flush()

def percentage_picked(self, picks, winner):
should_win = dict(picks)[winner]
total = sum([pt[1] for pt in picks])
return should_win / total


class EpsilonGreedyTest(MonteCarloTest):
bandit_name = "EpsilonGreedyBandit"
Expand All @@ -67,8 +62,8 @@ class EpsilonGreedyTest(MonteCarloTest):
def test_bandit(self):
results = self.run_algo(make_bandit(self.bandit_name, epsilon=0.1), 4000, 250)
data = Counter(results[2])
picks = data.most_common(3)
assert self.percentage_picked(picks, "green") > 0.75
winner, _ = data.most_common(1).pop()
assert winner is "green"


class SoftmaxTest(MonteCarloTest):
Expand All @@ -77,8 +72,8 @@ class SoftmaxTest(MonteCarloTest):
def test_bandit(self):
results = self.run_algo(make_bandit("SoftmaxBandit", tau=0.1), 3, 10000)
data = Counter(results[2])
picks = data.most_common(3)
assert self.percentage_picked(picks, "blue") > 0.5
winner, _ = data.most_common(1).pop()
assert winner is "blue"


class AnnealingSoftmaxTest(MonteCarloTest):
Expand All @@ -87,8 +82,8 @@ class AnnealingSoftmaxTest(MonteCarloTest):
def test_bandit(self):
results = self.run_algo(make_bandit("AnnealingSoftmaxBandit"), 3, 10000)
data = Counter(results[2])
picks = data.most_common(3)
assert self.percentage_picked(picks, "blue") > 0.4
winner, _ = data.most_common(1).pop()
assert winner is "blue"


class ThompsonBanditTest(MonteCarloTest):
Expand All @@ -97,5 +92,5 @@ class ThompsonBanditTest(MonteCarloTest):
def test_bandit(self):
results = self.run_algo(make_bandit("ThompsonBandit"), 10, 15000)
data = Counter(results[2])
picks = data.most_common(3)
assert self.percentage_picked(picks, "blue") > 0.7
winner, _ = data.most_common(1).pop()
assert winner is "blue"
2 changes: 1 addition & 1 deletion tests/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_improper_configuration(self):
rv = app_client.get("/")

with self.assertRaises(MABConfigException):
app_client.set_cookie("localhost", "MAB", '{"some_bandit": "blue"}')
app_client.set_cookie("MAB", '{"some_bandit": "blue"}', domain="localhost")
app_client.get("/reward")

def get_arm(self, headers):
Expand Down
17 changes: 17 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tox]
min_version = 4.0
env_list =
py38
py39
py310
lint

[testenv]
deps =
.[dev]
commands = pytest tests

[testenv:lint]
deps =
.[dev]
commands = black --check flask_mab tests
Loading