Skip to content

Commit

Permalink
[black] Apply black to recipes (asteroid-team#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpariente authored Aug 19, 2020
1 parent 25d1c46 commit f161cb3
Show file tree
Hide file tree
Showing 55 changed files with 1,988 additions and 1,748 deletions.
138 changes: 73 additions & 65 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,50 @@
import shutil

import builtins

# TODO : change it to asteroid_sphinx_theme

PATH_HERE = os.path.abspath(os.path.dirname(__file__))
PATH_ROOT = os.path.join(PATH_HERE, '..', '..')
PATH_ROOT = os.path.join(PATH_HERE, "..", "..")
sys.path.insert(0, os.path.abspath(PATH_ROOT))

# -- Project information -----------------------------------------------------

project = 'asteroid'
copyright = '2019, Oncoming'
author = 'Manuel Pariente et al.'
project = "asteroid"
copyright = "2019, Oncoming"
author = "Manuel Pariente et al."
# The short X.Y version
version = '0.0.1'
version = "0.0.1"
# The full version, including alpha/beta/rc tags
release = '0.0.1'
release = "0.0.1"

# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
needs_sphinx = '1.4'
needs_sphinx = "1.4"

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.napoleon',
'sphinx.ext.autosectionlabel',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.coverage",
"sphinx.ext.napoleon",
"sphinx.ext.autosectionlabel",
# 'sphinxcontrib.mockautodoc',
# 'sphinxcontrib.fulltoc', # breaks pytorch-theme with unexpected
# w argument 'titles_only'
# We can either use viewcode, which shows source code in the doc page
'sphinx.ext.viewcode',
"sphinx.ext.viewcode",
# Or linkcode to find the corresponding code in github. Start with viewcode
# 'sphinx.ext.linkcode',
# 'recommonmark',
'm2r2',
'nbsphinx',
"m2r2",
"nbsphinx",
]

# Napoleon config
Expand All @@ -67,13 +68,13 @@
napoleon_use_rtype = False

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

# https://berkeley-stat159-f17.github.io/stat159-f17/lectures/14-sphinx..html#conf.py-(cont.)
# https://stackoverflow.com/questions/38526888/embed-ipython-notebook-in-sphinx-document
# I execute the notebooks manually in advance. If notebooks test the code,
# they should be run at build time.
nbsphinx_execute = 'never'
nbsphinx_execute = "never"
nbsphinx_allow_errors = True

# The suffix(es) of source filenames.
Expand All @@ -82,14 +83,14 @@
# source_suffix = ['.rst', '.md']
# source_suffix = ['.rst', '.md', '.ipynb']
source_suffix = {
'.rst': 'restructuredtext',
'.txt': 'markdown',
".rst": "restructuredtext",
".txt": "markdown",
# '.md': 'markdown',
'.ipynb': 'nbsphinx',
".ipynb": "nbsphinx",
}

# 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 @@ -114,7 +115,7 @@
# html_theme = 'bizstyle'
# https://sphinx-themes.org

html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# import pt_lightning_sphinx_theme
# html_theme = 'pt_lightning_sphinx_theme'
Expand All @@ -129,19 +130,19 @@
# documentation.

html_theme_options = {
'pytorch_project': 'docs',
'canonical_url': 'https://github.com/mpariente/asteroid',
'collapse_navigation': False,
'display_version': True,
'logo_only': False,
"pytorch_project": "docs",
"canonical_url": "https://github.com/mpariente/asteroid",
"collapse_navigation": False,
"display_version": True,
"logo_only": False,
}

html_logo = '_static/images/favicon.ico'
html_logo = "_static/images/favicon.ico"

# 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 @@ -157,47 +158,49 @@
# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = project + '-doc'
htmlhelp_basename = project + "-doc"

# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
# 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',
"figure_align": "htbp",
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, project + '.tex', project + ' Documentation', author, 'manual'),
(master_doc, project + ".tex", project + " Documentation", author, "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, project, project + ' Documentation', [author], 1)
]
man_pages = [(master_doc, project, project + " Documentation", [author], 1)]

# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, project, project + ' Documentation', author, project,
'One line description of project.', 'Miscellaneous'),
(
master_doc,
project,
project + " Documentation",
author,
project,
"One line description of project.",
"Miscellaneous",
),
]

# -- Options for Epub output -------------------------------------------------
Expand All @@ -215,19 +218,18 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]

# -- Extension configuration -------------------------------------------------

# -- Options for intersphinx extension ---------------------------------------

# Intersphinx config
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'numpy': ('http://docs.scipy.org/doc/numpy/', None),
'torch': ('https://pytorch.org/docs/master/', None),
'pytorch_lightning':
('https://pytorch-lightning.readthedocs.io/en/latest/', None)
"python": ("https://docs.python.org/3", None),
"numpy": ("http://docs.scipy.org/doc/numpy/", None),
"torch": ("https://pytorch.org/docs/master/", None),
"pytorch_lightning": ("https://pytorch-lightning.readthedocs.io/en/latest/", None),
}

# -- Options for todo extension ----------------------------------------------
Expand All @@ -242,30 +244,37 @@
# sphinx-apidoc for me, since it's easy to forget to regen API docs
# and commit them to my repo after making changes to my code.

PACKAGES = [
'asteroid'
]
PACKAGES = ["asteroid"]


def run_apidoc(_):
os.makedirs(os.path.join(PATH_HERE, 'apidoc'), exist_ok=True)
os.makedirs(os.path.join(PATH_HERE, "apidoc"), exist_ok=True)
for pkg in PACKAGES:
argv = ['-e', '-o', os.path.join(PATH_HERE, 'apidoc'),
os.path.join(PATH_HERE, PATH_ROOT, pkg), '**/test_*',
'--force', '--private', '--module-first']
argv = [
"-e",
"-o",
os.path.join(PATH_HERE, "apidoc"),
os.path.join(PATH_HERE, PATH_ROOT, pkg),
"**/test_*",
"--force",
"--private",
"--module-first",
]
try:
# Sphinx 1.7+
from sphinx.ext import apidoc

apidoc.main(argv)
except ImportError:
# Sphinx 1.6 (and earlier)
from sphinx import apidoc

argv.insert(0, apidoc.__file__)
apidoc.main(argv)


def setup(app):
app.connect('builder-inited', run_apidoc)
app.connect("builder-inited", run_apidoc)


# copy all notebooks to local folder #FIXME : temp fix
Expand All @@ -280,15 +289,15 @@ def setup(app):
# https://stackoverflow.com/questions/15889621/sphinx-how-to-exclude-imports-in-automodule

MOCK_REQUIRE_PACKAGES = []
with open(os.path.join(PATH_ROOT, 'requirements.txt'), 'r') as fp:
with open(os.path.join(PATH_ROOT, "requirements.txt"), "r") as fp:
for ln in fp.readlines():
found = [ln.index(ch) for ch in list(',=<>#') if ch in ln]
pkg = ln[:min(found)] if found else ln
found = [ln.index(ch) for ch in list(",=<>#") if ch in ln]
pkg = ln[: min(found)] if found else ln
if pkg.rstrip():
MOCK_REQUIRE_PACKAGES.append(pkg.rstrip())

# TODO: better parse from package since the import name and package name may differ
MOCK_MANUAL_PACKAGES = ['torch', 'torchvision']
MOCK_MANUAL_PACKAGES = ["torch", "torchvision"]
autodoc_mock_imports = MOCK_REQUIRE_PACKAGES + MOCK_MANUAL_PACKAGES
# for mod_name in MOCK_REQUIRE_PACKAGES:
# sys.modules[mod_name] = mock.Mock()
Expand Down Expand Up @@ -339,12 +348,11 @@ def setup(app):
# % (github_user, github_repo, filename)



# Autodoc config
autodoc_inherit_docstring = False
autodoc_default_flags = ['members', 'show-inheritance']
autodoc_default_flags = ["members", "show-inheritance"]
# Order functions by appearance in source (default 'alphabetical')
autodoc_member_order = 'groupwise'
autodoc_member_order = "groupwise"


# autodoc_member_order = 'groupwise'
Expand All @@ -359,4 +367,4 @@ def setup(app):
# autodoc_inherit_docstring = True
# # autodoc_default_flags = ['members', 'show-inheritance']
# # Order functions by appearance in source (default 'alphabetical')
# # autodoc_member_order = 'bysource'
# # autodoc_member_order = 'bysource'
17 changes: 4 additions & 13 deletions egs/avspeech/looking-to-listen/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@ def main(conf):
learning_rate=conf["optim"]["lr"],
)

val_dataset = AVSpeechDataset(
Path("data/val.csv"), Path(EMBED_DIR), conf["main_args"]["n_src"]
)
val_dataset = AVSpeechDataset(Path("data/val.csv"), Path(EMBED_DIR), conf["main_args"]["n_src"])

model = load_best_model(conf, conf["main_args"]["exp_dir"])

print(
f"AVFusion has {sum(np.prod(i.shape) for i in model.parameters()):,} parameters"
)
print(f"AVFusion has {sum(np.prod(i.shape) for i in model.parameters()):,} parameters")

if torch.cuda.device_count() > 1:
print(f"Multiple GPUs available")
Expand All @@ -75,15 +71,10 @@ def main(conf):
parser = ArgumentParser()
parser.add_argument("--gpus", type=str, help="list of GPUs", default="-1")
parser.add_argument(
"--n-src",
type=int,
help="number of inputs to neural network",
default=2,
"--n-src", type=int, help="number of inputs to neural network", default=2,
)
parser.add_argument(
"--exp_dir",
default="exp/logdir",
help="Full path to save best validation model",
"--exp_dir", default="exp/logdir", help="Full path to save best validation model",
)

from asteroid.utils import prepare_parser_from_dict, parse_args_as_dict
Expand Down
1 change: 0 additions & 1 deletion egs/avspeech/looking-to-listen/local/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .postprocess import filter_audio, shelf

Loading

0 comments on commit f161cb3

Please sign in to comment.