Skip to content

Commit

Permalink
Format with black (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
markroth8 committed Feb 16, 2024
1 parent 105c88e commit 9b3536b
Show file tree
Hide file tree
Showing 48 changed files with 4,066 additions and 2,055 deletions.
70 changes: 35 additions & 35 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))


# -- Project information -----------------------------------------------------
import os

project = 'Memento'
copyright = '2018, AlphaStudio'
author = 'AlphaStudio'
project = "Memento"
copyright = "2018, AlphaStudio"
author = "AlphaStudio"

# The full version, including alpha/beta/rc tags
root_dir = os.path.dirname(os.path.realpath(__file__))
release = open(os.path.join(root_dir, '../../version.txt')).read().strip()
release = open(os.path.join(root_dir, "../../version.txt")).read().strip()
# The short X.Y version
version = release[0:release.rindex(".")]
version = release[0 : release.rindex(".")]


# -- General configuration ---------------------------------------------------
Expand All @@ -41,24 +42,24 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.doctest",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -70,18 +71,18 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -92,7 +93,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand All @@ -105,16 +106,16 @@
# html_sidebars = {}

html_context = {
'css_files': [
'_static/fix_table_text_wrap.css', # fix table width
"css_files": [
"_static/fix_table_text_wrap.css", # fix table width
],
}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'Mementodoc'
htmlhelp_basename = "Mementodoc"


# -- Options for LaTeX output ------------------------------------------------
Expand All @@ -123,15 +124,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -141,19 +139,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'Memento.tex', 'Memento Documentation',
'AlphaStudio', 'manual'),
(master_doc, "Memento.tex", "Memento Documentation", "AlphaStudio", "manual"),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'memento', 'Memento Documentation',
[author], 1)
]
man_pages = [(master_doc, "memento", "Memento Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------
Expand All @@ -162,16 +156,22 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Memento', 'Memento Documentation',
author, 'Memento', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"Memento",
"Memento Documentation",
author,
"Memento",
"One line description of project.",
"Miscellaneous",
),
]


# -- Extension configuration -------------------------------------------------
# Include Python objects as they appear in source files
autodoc_member_order = 'bysource'
autodoc_member_order = "bysource"
# Default flags used by autodoc directives
autodoc_default_flags = ['members', 'show-inheritance']
autodoc_default_flags = ["members", "show-inheritance"]

autosummary_generate = True
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@


def pytest_addoption(parser):
parser.addoption("--runslow", action="store_true", default=False, help="run slow tests")
parser.addoption(
"--runslow", action="store_true", default=False, help="run slow tests"
)


def pytest_configure(config):
Expand All @@ -31,7 +33,8 @@ def pytest_collection_modifyitems(config, items):

skip_slow = pytest.mark.skip(reason="need --runslow option to run")
skip_non_canonical_version = pytest.mark.skip(
reason=f"need python canonical version {canonical_version} to run (running {current_version})")
reason=f"need python canonical version {canonical_version} to run (running {current_version})"
)

for item in items:
if "slow" in item.keywords and not config.getoption("--runslow"):
Expand Down
14 changes: 10 additions & 4 deletions tests/test_call_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ def test_push_pop_caller(self):
recursive_context = RecursiveContext()
recursive_context.update("correlation_id", corr_id)
call_stack = CallStack.get()
frame1 = StackFrame(fn_sample_1.fn_reference().with_args(),
Environment.get().default_cluster.runner, recursive_context)
frame2 = StackFrame(fn_sample_1.fn_reference().with_args(),
Environment.get().default_cluster.runner, recursive_context)
frame1 = StackFrame(
fn_sample_1.fn_reference().with_args(),
Environment.get().default_cluster.runner,
recursive_context,
)
frame2 = StackFrame(
fn_sample_1.fn_reference().with_args(),
Environment.get().default_cluster.runner,
recursive_context,
)
call_stack.push_frame(frame1)
assert call_stack.depth() == 1
assert frame1 is call_stack.get_calling_frame()
Expand Down
39 changes: 30 additions & 9 deletions tests/test_code_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
from twosigma.memento import MementoFunction
from twosigma.memento.exception import UndeclaredDependencyError
from twosigma.memento import memento_function, Environment
from twosigma.memento.code_hash import fn_code_hash, list_dotted_names, resolve_to_symbolic_names
from twosigma.memento.code_hash import (
fn_code_hash,
list_dotted_names,
resolve_to_symbolic_names,
)


@memento_function()
Expand Down Expand Up @@ -79,6 +83,7 @@ def _non_memento_fn_3():
def dep_with_embedded_fn():
def embedded_fn():
return dep_b()

return embedded_fn()


Expand All @@ -95,6 +100,7 @@ def fn_with_cell_vars():
def inner():
y = x
return y

return inner()


Expand Down Expand Up @@ -133,7 +139,7 @@ def setup_method(self):
self.env_before = Environment.get()
self.env_dir = tempfile.mkdtemp(prefix="memoizeTest")
env_file = "{}/env.json".format(self.env_dir)
with open(env_file, 'w') as f:
with open(env_file, "w") as f:
print("""{"name": "test"}""", file=f)
Environment.set(env_file)

Expand Down Expand Up @@ -195,19 +201,26 @@ def test_non_memento_fn(self):
global _floating_fn

try:
assert {dep_b} == dep_floating_fn.dependencies().transitive_memento_fn_dependencies()
assert {
dep_b
} == dep_floating_fn.dependencies().transitive_memento_fn_dependencies()

version_before = dep_floating_fn.version()
_floating_fn = _non_memento_fn_2
version_after = dep_floating_fn.version()
assert version_before != version_after

assert {dep_a, dep_b} == dep_floating_fn.dependencies().transitive_memento_fn_dependencies()
assert {
dep_a,
dep_b,
} == dep_floating_fn.dependencies().transitive_memento_fn_dependencies()
finally:
_floating_fn = _non_memento_fn_1

def test_dep_with_embedded_fn(self):
assert {dep_b} == dep_with_embedded_fn.dependencies().transitive_memento_fn_dependencies()
assert {
dep_b
} == dep_with_embedded_fn.dependencies().transitive_memento_fn_dependencies()

def test_redefine_memento_fn_as_non_memento_fn(self):
"""
Expand Down Expand Up @@ -254,14 +267,18 @@ def test_fn_with_local_vars(self):
Make sure local variables are not included in the function hash
"""
assert not any("UndefinedSymbol;x" in r.describe() for r in fn_with_local_vars.hash_rules())
assert not any(
"UndefinedSymbol;x" in r.describe() for r in fn_with_local_vars.hash_rules()
)

def test_fn_with_cell_vars(self):
"""
Make sure cell variables are not included in the function hash
"""
assert not any("UndefinedSymbol;x" in r.describe() for r in fn_with_cell_vars.hash_rules())
assert not any(
"UndefinedSymbol;x" in r.describe() for r in fn_with_cell_vars.hash_rules()
)

def test_cluster_lock_prevents_version_update(self):
"""
Expand All @@ -279,7 +296,9 @@ def test_cluster_lock_prevents_version_update(self):
assert prev_value == dep_global_var()
global_var = prev_value + 1
v2 = dep_floating_fn.version()
assert prev_value == dep_global_var() # Should be memoized from previous call
assert (
prev_value == dep_global_var()
) # Should be memoized from previous call
assert v1 == v2
finally:
global_var = prev_value
Expand All @@ -303,6 +322,8 @@ def test_safe_to_call_memento_fn_wrappers(self):
function.
"""
result = fn_calls_wrapped_one_plus_one.dependencies().transitive_memento_fn_dependencies()
result = (
fn_calls_wrapped_one_plus_one.dependencies().transitive_memento_fn_dependencies()
)
# noinspection PyUnresolvedReferences
assert {_wrapped_one_plus_one.__wrapped__} == result
Loading

0 comments on commit 9b3536b

Please sign in to comment.