From 89f86237e4c598c3249f5a09e43a3c6a812937da Mon Sep 17 00:00:00 2001 From: Niels Bantilan Date: Thu, 14 Dec 2023 09:43:55 -0500 Subject: [PATCH 1/4] monodocs - add DOCS_DEV_BUILD to avoid checkout out latest tag Signed-off-by: Niels Bantilan --- docs/_ext/import_projects.py | 12 +++++++----- docs/conf.py | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/_ext/import_projects.py b/docs/_ext/import_projects.py index 1cb46f08f5..46bfce5e98 100644 --- a/docs/_ext/import_projects.py +++ b/docs/_ext/import_projects.py @@ -26,6 +26,7 @@ class ImportProjectsConfig: flytekit_api_dir: str source_regex_mapping: dict = field(default_factory=dict) list_table_toc: List[str] = field(default_factory=list) + dev_build: bool = False @dataclass @@ -127,27 +128,28 @@ def import_projects(app: Sphinx, config: Config): if not hasattr(config, "html_context"): config.html_context = {} - show_repo_tags = False + show_repo_tags = not import_projects_config.dev_build for project in projects: if project.local: local_dir = srcdir / project.source try: repo = Repo(local_dir) - show_repo_tags = True except git.InvalidGitRepositoryError: repo = None else: local_dir = srcdir / import_projects_config.clone_dir / project.dest shutil.rmtree(local_dir, ignore_errors=True) repo = Repo.clone_from(project.source, local_dir) - show_repo_tags = True local_docs_path = local_dir / project.docs_path dest_docs_dir = srcdir / project.dest - # use the latest git tag when building docs - if repo: + # don't checkout/show latest tag on dev builds + if repo and show_repo_tags: + # use the latest git tag when building docs tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime) + if not tags: + raise RuntimeError(f"No tags found for {project.name}") tag = tags[-1] update_html_context(project, str(tag), str(tag.commit)[:7], config) repo.git.checkout(str(tag)) diff --git a/docs/conf.py b/docs/conf.py index 89692d1f78..e9ea2bbd51 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -337,6 +337,7 @@ "flytesnacks/tutorials", "flytesnacks/integrations", ], + "dev_build": bool(int(os.environ.get("DOCS_DEV_BUILD", 0))), } # Define these environment variables to use local copies of the projects. This From 423441ee06a78557cf207caed7ae7d1d9eaa5152 Mon Sep 17 00:00:00 2001 From: Niels Bantilan Date: Thu, 14 Dec 2023 10:14:23 -0500 Subject: [PATCH 2/4] opt for implicit handling if tags don't exist in the repo Signed-off-by: Niels Bantilan --- docs/_ext/import_projects.py | 24 +++++++++++++++--------- docs/conf.py | 1 - 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/_ext/import_projects.py b/docs/_ext/import_projects.py index 46bfce5e98..0940b43b39 100644 --- a/docs/_ext/import_projects.py +++ b/docs/_ext/import_projects.py @@ -26,7 +26,6 @@ class ImportProjectsConfig: flytekit_api_dir: str source_regex_mapping: dict = field(default_factory=dict) list_table_toc: List[str] = field(default_factory=list) - dev_build: bool = False @dataclass @@ -128,31 +127,38 @@ def import_projects(app: Sphinx, config: Config): if not hasattr(config, "html_context"): config.html_context = {} - show_repo_tags = not import_projects_config.dev_build + show_repo_tags = False for project in projects: if project.local: local_dir = srcdir / project.source try: repo = Repo(local_dir) + show_repo_tags = True except git.InvalidGitRepositoryError: repo = None else: local_dir = srcdir / import_projects_config.clone_dir / project.dest shutil.rmtree(local_dir, ignore_errors=True) repo = Repo.clone_from(project.source, local_dir) + show_repo_tags = True local_docs_path = local_dir / project.docs_path dest_docs_dir = srcdir / project.dest - # don't checkout/show latest tag on dev builds - if repo and show_repo_tags: - # use the latest git tag when building docs + if repo: tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime) if not tags: - raise RuntimeError(f"No tags found for {project.name}") - tag = tags[-1] - update_html_context(project, str(tag), str(tag.commit)[:7], config) - repo.git.checkout(str(tag)) + # If tags don't exist just use the current commit. This occurs + # when the git repo fetch depth is 0. + tag = None + commit = repo.head.commit + else: + tag = tags[-1] + tag_str = str(tag) + commit = str(tag.commit)[:7] + repo.git.checkout(tag_str) + + update_html_context(project, tag_str, commit, config) if project.refresh or not dest_docs_dir.exists(): shutil.rmtree(dest_docs_dir, ignore_errors=True) diff --git a/docs/conf.py b/docs/conf.py index e9ea2bbd51..89692d1f78 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -337,7 +337,6 @@ "flytesnacks/tutorials", "flytesnacks/integrations", ], - "dev_build": bool(int(os.environ.get("DOCS_DEV_BUILD", 0))), } # Define these environment variables to use local copies of the projects. This From 67c05eafe1c9947cf395d0d0ccf5daa0f9c79189 Mon Sep 17 00:00:00 2001 From: Niels Bantilan Date: Thu, 14 Dec 2023 10:20:31 -0500 Subject: [PATCH 3/4] set placeholder tag Signed-off-by: Niels Bantilan --- docs/_ext/import_projects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_ext/import_projects.py b/docs/_ext/import_projects.py index 0940b43b39..aa2de79e00 100644 --- a/docs/_ext/import_projects.py +++ b/docs/_ext/import_projects.py @@ -150,7 +150,7 @@ def import_projects(app: Sphinx, config: Config): if not tags: # If tags don't exist just use the current commit. This occurs # when the git repo fetch depth is 0. - tag = None + tag_str = "dev" commit = repo.head.commit else: tag = tags[-1] From efe3ad555477e972c48074676264fcb2bb124c5a Mon Sep 17 00:00:00 2001 From: Niels Bantilan Date: Thu, 14 Dec 2023 10:38:03 -0500 Subject: [PATCH 4/4] update comment Signed-off-by: Niels Bantilan --- docs/_ext/import_projects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_ext/import_projects.py b/docs/_ext/import_projects.py index aa2de79e00..214f6b5387 100644 --- a/docs/_ext/import_projects.py +++ b/docs/_ext/import_projects.py @@ -149,7 +149,7 @@ def import_projects(app: Sphinx, config: Config): tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime) if not tags: # If tags don't exist just use the current commit. This occurs - # when the git repo fetch depth is 0. + # when the git repo is a shallow clone. tag_str = "dev" commit = repo.head.commit else: