Bug 1633418 - [Perfdocs] Add the ability to include static content into perfdocs r=sparky,perftest-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D80031
This commit is contained in:
Myeongjun Go 2020-06-30 16:35:00 +00:00
parent 7ece4fe886
commit 20bcc8c1aa
3 changed files with 33 additions and 16 deletions

View File

@ -4,6 +4,6 @@ Performance Testing
Below you can find links to the various documentation that exists for performance testing and the associated tests.
:doc:`raptor`
* :doc:`raptor`
For more information please see this `wiki page <https://wiki.mozilla.org/TestEngineering/Performance>`_.

View File

@ -4,7 +4,6 @@
from __future__ import absolute_import
import os
import re
from perfdocs.logger import PerfDocLogger
from perfdocs.utils import read_yaml
@ -61,28 +60,30 @@ class Gatherer(object):
"path": Path to the perfdocs directory.
"yml": Name of the configuration YAML file.
"rst": Name of the RST file.
"static": Name of the static file
}, ...
]
This method doesn't return anything. The result can be found in
the perfdocs_tree attribute.
'''
yml_match = re.compile('^config.y(a)?ml$')
rst_match = re.compile('^index.rst$')
for dirpath, dirname, files in os.walk(self.root_dir):
# Walk through the testing directory tree
if dirpath.endswith('/perfdocs'):
matched = {"path": dirpath, "yml": "", "rst": ""}
matched = {"path": dirpath, "yml": "", "rst": "", "static": []}
for file in files:
# Add the yml/rst file to its key if re finds the searched file
if re.search(yml_match, file):
matched["yml"] = re.search(yml_match, file).string
if re.search(rst_match, file):
matched["rst"] = re.search(rst_match, file).string
# Append to structdocs if all the searched files were found
if all(matched.values()):
self._perfdocs_tree.append(matched)
# Add the yml/rst/static file to its key if re finds the searched file
if file == "config.yml" or file == "config.yaml":
matched["yml"] = file
elif file == "index.rst":
matched["rst"] = file
elif file.endswith(".rst"):
matched["static"].append(file)
# Append to structdocs if all the searched files were found
if all(val for val in matched.values() if not type(val) == list):
self._perfdocs_tree.append(matched)
logger.log("Found {} perfdocs directories in {}"
.format(len(self._perfdocs_tree), self.root_dir))

View File

@ -111,7 +111,17 @@ class Generator(object):
os.linesep.join(documentation),
rst_content
)
frameworks_info[yaml_content['name']] = framework_rst
frameworks_info[yaml_content["name"]] = {"dynamic": framework_rst, "static": []}
# For static `.rst` file
for static_file in framework["static"]:
frameworks_info[yaml_content["name"]]["static"].append({
"file": static_file,
"content": read_file(
os.path.join(framework["path"], static_file),
stringify=True
)
})
return frameworks_info
@ -150,13 +160,19 @@ class Generator(object):
for framework_name in sorted(framework_docs.keys()):
frameworks.append(framework_name)
save_file(
framework_docs[framework_name],
framework_docs[framework_name]["dynamic"],
os.path.join(perfdocs_tmpdir, framework_name)
)
for static_name in framework_docs[framework_name]["static"]:
save_file(
static_name["content"],
os.path.join(perfdocs_tmpdir, static_name["file"].split(".")[0])
)
# Get the main page and add the framework links to it
mainpage = read_file(os.path.join(self.templates_path, "index.rst"), stringify=True)
fmt_frameworks = os.linesep.join([' :doc:`%s`' % name for name in frameworks])
fmt_frameworks = os.linesep.join([' * :doc:`%s`' % name for name in frameworks])
fmt_mainpage = re.sub(r"{test_documentation}", fmt_frameworks, mainpage)
save_file(fmt_mainpage, os.path.join(perfdocs_tmpdir, 'index'))