Skip to content

Commit adb0994

Browse files
committed
Make into a stand-alone library
1 parent 20974cd commit adb0994

37 files changed

+396
-78
lines changed

.drone.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
kind: pipeline
3+
name: Lint & Test
4+
5+
steps:
6+
- name: "Lint"
7+
image: python:3.8
8+
commands:
9+
- pip install -r requirements.txt
10+
- make lint
11+
depends_on: [clone]
12+
13+
- name: "Test - Py3.6"
14+
image: python:3.6
15+
commands:
16+
- pip install -r requirements.txt
17+
- make test
18+
depends_on: [clone]
19+
20+
- name: "Test - Py3.7"
21+
image: python:3.7
22+
commands:
23+
- pip install -r requirements.txt
24+
- make test
25+
depends_on: [clone]
26+
27+
- name: "Test - Py3.8"
28+
image: python:3.8
29+
commands:
30+
- pip install -r requirements.txt
31+
- make test
32+
depends_on: [clone]

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build/
2+
.coverage
3+
dist/
4+
.eggs/
5+
__pycache__/
6+
reddit_experiments.egg-info/

LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2021 Reddit Inc.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions
6+
are met:
7+
8+
1. Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
2. Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
13+
3. Neither the name of the copyright holder nor the names of its
14+
contributors may be used to endorse or promote products derived from
15+
this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27+
SUCH DAMAGE.

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
SOURCE_ROOT := reddit_experiments/
2+
PYTHON_SOURCE = $(shell find $(SOURCE_ROOT) tests/ setup.py -name '*.py')
3+
REORDER_PYTHON_IMPORTS := reorder-python-imports --py3-plus --separate-from-import --separate-relative
4+
5+
6+
.PHONY: fmt
7+
fmt:
8+
$(REORDER_PYTHON_IMPORTS) --exit-zero-even-if-changed $(PYTHON_SOURCE)
9+
black $(PYTHON_SOURCE)
10+
11+
12+
.PHONY: lint
13+
lint:
14+
$(REORDER_PYTHON_IMPORTS) --diff-only $(PYTHON_SOURCE)
15+
black --diff --check $(PYTHON_SOURCE)
16+
flake8 $(SOURCE_ROOT)
17+
mypy $(SOURCE_ROOT)
18+
19+
.PHONY: test
20+
test:
21+
python -m pytest -v tests/
22+
23+
24+
.PHONY: docs
25+
docs:
26+
sphinx-build -M html docs/ build/

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# experiments.py
2+
3+
This is a work-in-progress extraction of the Python experiments framework from
4+
Baseplate.py.

docs/conf.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# sphinx docs config
2+
#
3+
# This file is execfile()d with the current directory set to its
4+
# containing dir.
5+
import os
6+
import sys
7+
8+
import alabaster
9+
10+
# where to find the modules to import for autodoc
11+
sys.path.insert(0, os.path.abspath(".."))
12+
13+
# -- General configuration ------------------------------------------------
14+
# Add any Sphinx extension module names here, as strings. They can be
15+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
16+
# ones.
17+
extensions = [
18+
"alabaster",
19+
"sphinx.ext.autodoc",
20+
"sphinx.ext.doctest",
21+
"sphinx.ext.intersphinx",
22+
"sphinx.ext.viewcode",
23+
"sphinx_autodoc_typehints",
24+
]
25+
26+
intersphinx_mapping = {
27+
"python": ("https://docs.python.org/3.7", None),
28+
"baseplate": ("https://baseplate.readthedocs.io/en/stable/", None),
29+
}
30+
31+
# The suffix of source filenames.
32+
source_suffix = ".rst"
33+
34+
# The encoding of source files.
35+
source_encoding = "utf-8"
36+
37+
# The master toctree document.
38+
master_doc = "index"
39+
40+
# General information about the project.
41+
project = "reddit_experiments"
42+
43+
# The language for content autogenerated by Sphinx. Refer to documentation
44+
# for a list of supported languages.
45+
language = "en"
46+
47+
# List of patterns, relative to source directory, that match files and
48+
# directories to ignore when looking for source files.
49+
exclude_patterns = ["docs/html"]
50+
51+
# The name of the Pygments (syntax highlighting) style to use.
52+
pygments_style = "friendly"
53+
54+
# -- Options for HTML output ----------------------------------------------
55+
56+
html_theme_path = [alabaster.get_path()]
57+
html_static_path = []
58+
59+
# The theme to use for HTML and HTML Help pages. See the documentation for
60+
# a list of builtin themes.
61+
html_theme = "alabaster"
62+
63+
# The name for this set of Sphinx documents. If None, it defaults to
64+
# "<project> v<release> documentation".
65+
# html_title =
66+
67+
# which templates to put in the sidebar. we're just removing the relations
68+
# section from the defaults here, that's "next article" and "previous article"
69+
html_sidebars = {
70+
"**": ["about.html", "searchbox.html", "navigation.html"]
71+
}
72+
73+
html_theme_options = {
74+
"description": "Reddit's Python Experiments Framework",
75+
"github_button": False,
76+
"github_repo": "experiments.py",
77+
"github_user": "reddit",
78+
"github_banner": True,
79+
"logo_name": True,
80+
"show_powered_by": False,
81+
"show_related": False,
82+
"show_relbars": True,
83+
"page_width": "960px",
84+
}
85+
86+
# The name of an image file (within the static path) to use as favicon of the
87+
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
88+
# pixels large.
89+
html_favicon = "images/favicon.png"
90+
91+
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
92+
# using the given strftime format.
93+
html_last_updated_fmt = "%b %d, %Y"
94+
95+
# If true, SmartyPants will be used to convert quotes and dashes to
96+
# typographically correct entities.
97+
html_use_smartypants = True
98+
99+
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
100+
html_show_sphinx = False
101+
102+
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
103+
html_show_copyright = False
104+
105+
# -- Autodoc --
106+
autodoc_member_order = "bysource"
107+
108+
# -- Spelling --
109+
spelling_word_list_filename = "words.txt"
110+
spelling_show_suggestions = True

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
``baseplate.lib.experiments``
1+
``reddit_experiments``
22
===============================
33

4-
.. automodule:: baseplate.lib.experiments
4+
.. automodule:: reddit_experiments
55

66
Configuration Parsing
77
---------------------

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.black]
2+
line-length = 100
3+
target-version = ['py36']

reddit_experiments/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
from baseplate.lib.edge_context import User
1616
from baseplate.lib.events import DebugLogger
1717
from baseplate.lib.events import EventLogger
18-
from baseplate.lib.experiments.providers import parse_experiment
19-
from baseplate.lib.experiments.providers.base import Experiment
2018
from baseplate.lib.file_watcher import FileWatcher
2119
from baseplate.lib.file_watcher import WatchedFileNotAvailableError
2220

21+
from reddit_experiments.providers import parse_experiment
22+
from reddit_experiments.providers.base import Experiment
23+
2324

2425
logger = logging.getLogger(__name__)
2526

@@ -33,7 +34,7 @@ class ExperimentsContextFactory(ContextFactory):
3334
"""Experiment client context factory.
3435
3536
This factory will attach a new
36-
:py:class:`baseplate.lib.experiments.Experiments` to an attribute on the
37+
:py:class:`reddit_experiments.Experiments` to an attribute on the
3738
:py:class:`~baseplate.RequestContext`.
3839
3940
:param path: Path to the experiment configuration file.

reddit_experiments/providers/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
from typing import Dict
66

77
from baseplate.lib import warn_deprecated
8-
from baseplate.lib.experiments.providers.base import Experiment
9-
from baseplate.lib.experiments.providers.feature_flag import FeatureFlag
10-
from baseplate.lib.experiments.providers.forced_variant import ForcedVariantExperiment
11-
from baseplate.lib.experiments.providers.r2 import R2Experiment
12-
from baseplate.lib.experiments.providers.simple_experiment import SimpleExperiment
8+
9+
from reddit_experiments.providers.base import Experiment
10+
from reddit_experiments.providers.feature_flag import FeatureFlag
11+
from reddit_experiments.providers.forced_variant import ForcedVariantExperiment
12+
from reddit_experiments.providers.r2 import R2Experiment
13+
from reddit_experiments.providers.simple_experiment import SimpleExperiment
1314

1415
logger = logging.getLogger(__name__)
1516

reddit_experiments/providers/feature_flag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any
22
from typing import Dict
33

4-
from baseplate.lib.experiments.providers.r2 import R2Experiment
4+
from reddit_experiments.providers.r2 import R2Experiment
55

66

77
class FeatureFlag(R2Experiment):

reddit_experiments/providers/forced_variant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any
22
from typing import Optional
33

4-
from baseplate.lib.experiments.providers.base import Experiment
4+
from reddit_experiments.providers.base import Experiment
55

66

77
class ForcedVariantExperiment(Experiment):

reddit_experiments/providers/r2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import List
77
from typing import Optional
88

9-
from baseplate.lib.experiments.providers.base import Experiment
9+
from reddit_experiments.providers.base import Experiment
1010

1111

1212
logger = logging.getLogger(__name__)

reddit_experiments/providers/simple_experiment.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
from typing import Optional
99
from typing import Type
1010

11-
from baseplate.lib.experiments.providers.base import Experiment
12-
from baseplate.lib.experiments.targeting.base import Targeting
13-
from baseplate.lib.experiments.targeting.tree_targeting import create_targeting_tree
14-
from baseplate.lib.experiments.variant_sets.base import VariantSet
15-
from baseplate.lib.experiments.variant_sets.multi_variant_set import MultiVariantSet
16-
from baseplate.lib.experiments.variant_sets.range_variant_set import RangeVariantSet
17-
from baseplate.lib.experiments.variant_sets.rollout_variant_set import RolloutVariantSet
18-
from baseplate.lib.experiments.variant_sets.single_variant_set import SingleVariantSet
11+
from reddit_experiments.providers.base import Experiment
12+
from reddit_experiments.targeting.base import Targeting
13+
from reddit_experiments.targeting.tree_targeting import create_targeting_tree
14+
from reddit_experiments.variant_sets.base import VariantSet
15+
from reddit_experiments.variant_sets.multi_variant_set import MultiVariantSet
16+
from reddit_experiments.variant_sets.range_variant_set import RangeVariantSet
17+
from reddit_experiments.variant_sets.rollout_variant_set import RolloutVariantSet
18+
from reddit_experiments.variant_sets.single_variant_set import SingleVariantSet
1919

2020

2121
logger = logging.getLogger(__name__)

reddit_experiments/targeting/tree_targeting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import List
88
from typing import Type
99

10-
from baseplate.lib.experiments.targeting.base import Targeting
10+
from reddit_experiments.targeting.base import Targeting
1111

1212

1313
logger = logging.getLogger(__name__)

reddit_experiments/variant_sets/multi_variant_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List
44
from typing import Optional
55

6-
from baseplate.lib.experiments.variant_sets.base import VariantSet
6+
from reddit_experiments.variant_sets.base import VariantSet
77

88

99
class MultiVariantSet(VariantSet):

reddit_experiments/variant_sets/range_variant_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List
44
from typing import Optional
55

6-
from baseplate.lib.experiments.variant_sets.base import VariantSet
6+
from reddit_experiments.variant_sets.base import VariantSet
77

88

99
class RangeVariantSet(VariantSet):

reddit_experiments/variant_sets/rollout_variant_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List
44
from typing import Optional
55

6-
from baseplate.lib.experiments.variant_sets.base import VariantSet
6+
from reddit_experiments.variant_sets.base import VariantSet
77

88

99
class RolloutVariantSet(VariantSet):

reddit_experiments/variant_sets/single_variant_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List
44
from typing import Optional
55

6-
from baseplate.lib.experiments.variant_sets.base import VariantSet
6+
from reddit_experiments.variant_sets.base import VariantSet
77

88

99
class SingleVariantSet(VariantSet):

0 commit comments

Comments
 (0)