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

Black format napalm repository #873

Closed
wants to merge 6 commits into from
Closed
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
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ language: python

python:
- 2.7
- 3.4
- 3.5
- 3.6

matrix:
include:
- python: 3.6
env: TOXENV=sphinx
- python: 3.6
env: TOXENV=pylama
- python: 3.6
env: TOXENV=black
- python: 3.6
env: TOXENV=sphinx

install:
- pip install tox==3.0.0 tox-travis coveralls
- pip install tox==3.5.3 tox-travis coveralls

deploy:
provider: pypi
Expand Down
146 changes: 79 additions & 67 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,37 @@
# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'

autoclass_content = 'both'
autoclass_content = "both"

# 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.napoleon',
]
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon"]

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

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
# source_encoding = 'utf-8-sig'

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

# General information about the project.
project = u'NAPALM'
copyright = u'2016, David Barroso'
project = u"NAPALM"
copyright = u"2016, David Barroso"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0'
version = "0"
# The full version, including alpha/beta/rc tags.
release = '1'
release = "1"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -81,7 +78,7 @@

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build', 'napalm_ansible_repo']
exclude_patterns = ["_build", "napalm_ansible_repo"]

# The reST default role (used for this markup: `text`) to use for all
# documents.
Expand All @@ -99,7 +96,7 @@
# show_authors = False

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

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
Expand All @@ -112,14 +109,15 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = os.environ.get("READTHEDOCS", None) == "True"

if not on_rtd: # only import and set the theme if we're building docs locally
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'

html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
else:
html_theme = 'default'
html_theme = "default"

# 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 Down Expand Up @@ -148,7 +146,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"]

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
Expand Down Expand Up @@ -197,18 +195,16 @@
# html_file_suffix = None

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


# -- 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': '',
}
Expand All @@ -217,8 +213,7 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'napalm.tex', u'NAPALM Documentation',
u'David Barroso', 'manual'),
("index", "napalm.tex", u"NAPALM Documentation", u"David Barroso", "manual")
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -246,10 +241,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'napalm', u'NAPALM Documentation',
[u'David Barroso'], 1)
]
man_pages = [("index", "napalm", u"NAPALM Documentation", [u"David Barroso"], 1)]

# If true, show URL addresses after external links.
# man_show_urls = False
Expand All @@ -261,9 +253,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'napalm', u'NAPALM Documentation',
u'David Barroso', 'napalm', 'One line description of project.',
'Miscellaneous'),
(
"index",
"napalm",
u"NAPALM Documentation",
u"David Barroso",
"napalm",
"One line description of project.",
"Miscellaneous",
)
]

# Documents to append as an appendix to all manuals.
Expand All @@ -282,26 +280,35 @@
enable_pdf_build = False
enable_epub_build = False

EXCLUDE_METHODS = ('cli', 'close', 'commit_config', 'compare_config',
'discard_config', 'load_merge_candidate',
'load_replace_candidate', 'load_template', 'open',
'rollback', 'compliance_report', 'connection_tests',
'post_connection_tests', 'pre_connection_tests')
EXCLUDE_METHODS = (
"cli",
"close",
"commit_config",
"compare_config",
"discard_config",
"load_merge_candidate",
"load_replace_candidate",
"load_template",
"open",
"rollback",
"compliance_report",
"connection_tests",
"post_connection_tests",
"pre_connection_tests",
)

EXCLUDE_IN_REPORT = ('test_method_signatures')
EXCLUDE_IN_REPORT = "test_method_signatures"

METHOD_ALIASES = {
'get_config_filtered': 'get_config',
}
METHOD_ALIASES = {"get_config_filtered": "get_config"}


def _merge_results(last, intermediate):
if intermediate == 'failed':
return 'failed'
elif intermediate == 'skipped':
return 'failed' if last == 'failed' else 'skipped'
elif intermediate == 'passed':
return 'ok' if last == 'ok' else last
if intermediate == "failed":
return "failed"
elif intermediate == "skipped":
return "failed" if last == "failed" else "skipped"
elif intermediate == "passed":
return "ok" if last == "ok" else last
else:
return last

Expand All @@ -310,23 +317,25 @@ def build_napalm_ansible_module_docs(app):
"""Create documentation for Ansible modules."""

# Add script to clone napalm-ansible repo
status = subprocess.call("./build-ansible-module-docs.sh", stdout=sys.stdout, stderr=sys.stderr)
status = subprocess.call(
"./build-ansible-module-docs.sh", stdout=sys.stdout, stderr=sys.stderr
)

if status != 0:
print("Something bad happened when processing the Ansible modules.")
sys.exit(-1)

env = Environment(loader=FileSystemLoader("."))

modules_dir = './integrations/ansible/modules/source'
module_files = glob('{0}/*.json'.format(modules_dir))
modules_dir = "./integrations/ansible/modules/source"
module_files = glob("{0}/*.json".format(modules_dir))
for module_file in module_files:
with open(module_file, 'r') as f:
module = module_file.split('/')[-1].split('.')[0]
with open(module_file, "r") as f:
module = module_file.split("/")[-1].split(".")[0]
data = json.loads(f.read())
data['name'] = module
data["name"] = module

module_dir = './integrations/ansible/modules/{0}'.format(module)
module_dir = "./integrations/ansible/modules/{0}".format(module)

try:
os.stat(module_dir)
Expand All @@ -336,7 +345,7 @@ def build_napalm_ansible_module_docs(app):
template_file = env.get_template("ansible-module.j2")
rendered_template = template_file.render(**data)

with open('{0}/index.rst'.format(module_dir), 'w') as f:
with open("{0}/index.rst".format(module_dir), "w") as f:
f.write(rendered_template)


Expand All @@ -349,26 +358,28 @@ def build_getters_support_matrix(app):
sys.exit(-1)

drivers = set()
matrix = {m: defaultdict(dict) for m in dir(NetworkDriver)
if not (m.startswith('_') or
m in EXCLUDE_METHODS)}
matrix = {
m: defaultdict(dict)
for m in dir(NetworkDriver)
if not (m.startswith("_") or m in EXCLUDE_METHODS)
}

regex_name = re.compile(r"(?P<driver>\w+)\/.*::test_(?P<getter>\w+)")

filename = './support/tests/report.json'
with open(filename, 'r') as f:
filename = "./support/tests/report.json"
with open(filename, "r") as f:
data = json.loads(f.read())
for test in data["report"]["tests"]:
match = regex_name.search(test['name'])
match = regex_name.search(test["name"])
if match:
driver = match.group('driver')
driver = match.group("driver")
drivers.add(driver)
method = match.group('getter')
method = match.group("getter")
else:
continue
if method in EXCLUDE_IN_REPORT:
continue
result = test['outcome']
result = test["outcome"]

if method in METHOD_ALIASES.keys():
method = METHOD_ALIASES[method]
Expand All @@ -380,17 +391,18 @@ def build_getters_support_matrix(app):
drivers = sorted(drivers)
env = Environment(loader=FileSystemLoader("."))
template_file = env.get_template("matrix.j2")
rendered_template = template_file.render(matrix=matrix, drivers=drivers,
sorted_methods=sorted_methods)
rendered_template = template_file.render(
matrix=matrix, drivers=drivers, sorted_methods=sorted_methods
)

with open('support/matrix.rst', 'w') as f:
with open("support/matrix.rst", "w") as f:
f.write(rendered_template)


def setup(app):
"""Map methods to states of the documentation build."""
app.connect('builder-inited', build_getters_support_matrix)
app.connect('builder-inited', build_napalm_ansible_module_docs)
app.connect("builder-inited", build_getters_support_matrix)
app.connect("builder-inited", build_napalm_ansible_module_docs)


build_getters_support_matrix(None)
Expand Down
Loading