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

Infra Refactor #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
56 changes: 48 additions & 8 deletions slalom/dataops/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ def init_and_apply(infra_dir: str = "./infra/", save_output: bool = False):
DOCS_FOOTER = """
---------------------

## Source Files

_Source code for this module is available using the links below._

{src}

---------------------

_**NOTE:** This documentation was auto-generated using
`terraform-docs` and `s-infra` from `slalom.dataops`.
Please do not attempt to manually update this file._
Expand All @@ -149,11 +157,13 @@ def init_and_apply(infra_dir: str = "./infra/", save_output: bool = False):

def update_module_docs(
tf_dir: str,
*,
recursive: bool = True,
readme: str = "README.md",
footer: bool = True,
header: bool = True,
special_case_words: List[str] = None,
extra_docs_names: List[str] = ["USAGE.md", "NOTES.md"],
git_repo: str = "https://github.com/slalom-ggp/dataops-infra",
):
"""
Expand All @@ -167,6 +177,8 @@ def update_module_docs(
readme : Optional (default="README.md"). The filename to create when generating docs.
footnote: Optional (default=True). 'True' to include the standard footnote.
special_case_words: Optional. A list of words to override special casing rules.
extra_docs_names: (Optional.) A list of filenames which, if found, will be appended
to each module's README.md file.
git_repo: Optional. The git repo path to use in rendering 'source' paths.

Returns:
Expand All @@ -175,7 +187,13 @@ def update_module_docs(
"""
markdown_text = ""
if ".git" not in tf_dir and ".terraform" not in tf_dir:
if [x for x in io.list_files(tf_dir) if x.endswith(".tf")]:
tf_files = [x for x in io.list_files(tf_dir) if x.endswith(".tf")]
extra_docs = [
x
for x in io.list_files(tf_dir)
if extra_docs_names and os.path.basename(x) in extra_docs_names
]
if tf_files:
module_title = _proper(
os.path.basename(tf_dir), special_case_words=special_case_words
)
Expand All @@ -195,12 +213,17 @@ def update_module_docs(
module_title=module_title, module_path=module_path
)
markdown_text += markdown_output
for extra_file in ["NOTES.md"]:
extra_filepath = f"{tf_dir}/{extra_file}"
if os.path.isfile(extra_filepath):
markdown_text += io.get_text_file_contents(extra_filepath) + "\n"
for extra_file in extra_docs:
markdown_text += io.get_text_file_contents(extra_file) + "\n"
if footer:
markdown_text += DOCS_FOOTER
markdown_text += DOCS_FOOTER.format(
src="\n".join(
[
"* [{f}]({f})".format(f=os.path.basename(tf_file))
for tf_file in tf_files
]
)
)
io.create_text_file(f"{tf_dir}/{readme}", markdown_text)
if recursive:
for folder in io.list_files(tf_dir):
Expand Down Expand Up @@ -332,7 +355,7 @@ def _log_issue(module_path, issue_desc, details_list):
return result_str


def change_upstream_source(
def update_catalog_source(
dir_to_update=".",
git_repo="https://github.com/slalom-ggp/dataops-infra",
branch="master",
Expand Down Expand Up @@ -380,6 +403,16 @@ def change_upstream_source(
jobs.run_command("terraform fmt -recursive", dir_to_update)


def deprecated(fn, msg):
"""Wrapper for deprecated function. Return the function after printing warning."""

def _fn(*args, **kwargs):
logging.warning(f"Deprecation warning: {msg}")
_fn(*args, **kwargs)

return _fn


def main():
fire.Fire(
{
Expand All @@ -388,7 +421,14 @@ def main():
"apply": apply,
"init+apply": init_and_apply,
"deploy": init_and_apply,
"change_upstream_source": change_upstream_source,
"update_catalog_source": update_catalog_source,
"change_upstream_source": deprecated(
update_catalog_source,
msg=(
"Command 'update_catalog_source' is deprecated. "
"Please use 'update_catalog_source' instead."
),
),
"update_module_docs": update_module_docs,
"get_tf_metadata": get_tf_metadata,
"check_tf_metadata": check_tf_metadata,
Expand Down