From 3e4927ce2679419683e8167f1518069eb3f9cf9a Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Mon, 9 Sep 2024 14:03:19 -0500 Subject: [PATCH 1/6] test: ensure static content --- tests/test_build.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/test_build.py b/tests/test_build.py index a6f9cf5..c3830e8 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -30,7 +30,7 @@ def assert_build_path(path: Path, expected: str): class TestDocumentationBuilder: - @pytest.fixture(autouse=True) + @pytest.fixture def mock_sphinx(self, mocker): def run_mock_sphinx(path, *args, **kwargs): path.mkdir(parents=True) @@ -45,16 +45,21 @@ def run_mock_sphinx(path, *args, **kwargs): def mock_git(self, mocker): return mocker.patch("sphinx_ape.build.git") - def test_build_latest(self, mock_sphinx, temp_path): + def test_build_latest(self, temp_path): builder = DocumentationBuilder(mode=BuildMode.LATEST, base_path=temp_path) + builder.init() # so there is something to build. builder.build() - call_path = mock_sphinx.call_args[0][0] - assert_build_path(call_path, "latest") + assert builder.latest_path.is_dir() + # Ensure re-direct exists and points to latest/. assert builder.index_file.is_file() expected_content = REDIRECT_HTML.format("latest") assert builder.index_file.read_text() == expected_content + # Ensure static content exists. + assert (builder.latest_path / "_static").is_dir() + assert (builder.latest_path / "_static" / "logo_green.svg").is_file() + def test_build_release(self, mock_sphinx, mock_git, temp_path): tag = "v1.0.0" mock_git.return_value = tag @@ -89,6 +94,7 @@ def test_publish_merge_to_main(self, temp_path, mock_git): tag = "v1.0.0" mock_git.return_value = tag builder = DocumentationBuilder(mode=BuildMode.MERGE_TO_MAIN, base_path=temp_path) + builder.init() # Ensure built first. builder.build() builder.publish(push=False) @@ -111,6 +117,7 @@ def test_publish_release(self, temp_path, mock_git): tag = "v1.0.0" mock_git.return_value = tag builder = DocumentationBuilder(mode=BuildMode.RELEASE, base_path=temp_path) + builder.init() # Ensure built first. builder.build() builder.publish(push=False) From 7559c5a5e1c07041ec34428feee43c6759f03a0e Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Mon, 9 Sep 2024 14:13:36 -0500 Subject: [PATCH 2/6] test: ensure statics getting built --- tests/test_build.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_build.py b/tests/test_build.py index c3830e8..b768486 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -112,6 +112,11 @@ def test_publish_merge_to_main(self, temp_path, mock_git): assert not tag_dir.is_dir() # Stable only gets built on releases. assert not stable_dir.is_dir() + # Ensure static content exists. + static_dir = latest_dir / "_static" + assert static_dir.is_dir(), "Missing 'latest/_static'" + logo = static_dir / "logo_green.svg" + assert logo.is_file(), "Missing logo: 'latest/_static/logo_green.svg'" def test_publish_release(self, temp_path, mock_git): tag = "v1.0.0" @@ -133,3 +138,9 @@ def test_publish_release(self, temp_path, mock_git): assert latest_dir.is_dir() assert tag_dir.is_dir() assert index_file.is_file() + # Ensure static content exists. + for directory in (latest_dir, stable_dir, tag_dir): + static_dir = directory / "_static" + assert static_dir.is_dir(), f"Missing static: {directory.name}" + logo = static_dir / "logo_green.svg" + assert logo.is_file(), f"Missing logo: {directory.name}" From 5d567386849a8bbae954661fcad7b8fe9be61b0b Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Mon, 9 Sep 2024 14:53:51 -0500 Subject: [PATCH 3/6] fix: refresh issue --- sphinx_ape/build.py | 9 +++++++-- tests/test_build.py | 18 +++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/sphinx_ape/build.py b/sphinx_ape/build.py index 966710e..17b4968 100644 --- a/sphinx_ape/build.py +++ b/sphinx_ape/build.py @@ -143,7 +143,12 @@ def _publish(self, repository: Optional[str] = None, push: bool = True): # the mode parameter. for path in self.build_path.iterdir(): if path.is_dir() and not path.name.startswith(".") and path.name != "doctest": - shutil.copytree(path, gh_pages_path / path.name, dirs_exist_ok=True) + dst_path = gh_pages_path / path.name + if dst_path.is_dir(): + shutil.rmtree(dst_path) + + shutil.copytree(path, dst_path) + elif (path.name == "index.html") and path.is_file(): gh_pages_path.mkdir(exist_ok=True) (gh_pages_path / "index.html").write_text(path.read_text()) @@ -204,5 +209,5 @@ def _setup_redirect(self): self.index_file.unlink(missing_ok=True) self.index_file.write_text(REDIRECT_HTML.format(redirect)) - def _sphinx_build(self, dst_path): + def _sphinx_build(self, dst_path: Path): sphinx_build(dst_path, self.docs_path) diff --git a/tests/test_build.py b/tests/test_build.py index b768486..dd99cb2 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -94,16 +94,24 @@ def test_publish_merge_to_main(self, temp_path, mock_git): tag = "v1.0.0" mock_git.return_value = tag builder = DocumentationBuilder(mode=BuildMode.MERGE_TO_MAIN, base_path=temp_path) - builder.init() - # Ensure built first. - builder.build() - builder.publish(push=False) gh_pages_path = temp_path / "gh-pages" nojekyll_file = gh_pages_path / ".nojekyll" stable_dir = gh_pages_path / "stable" latest_dir = gh_pages_path / "latest" tag_dir = gh_pages_path / tag index_file = gh_pages_path / builder.index_file.name + static_dir = latest_dir / "_static" + + # Create a random file in _static to show it doesn't matter. + static_dir.mkdir(exist_ok=True, parents=True) + random_file = static_dir / "randomfile.txt" + random_file.write_text("this should be fine.") + + # Ensure built first. + builder.init() + builder.build() + builder.publish(push=False) + assert gh_pages_path.is_dir() assert nojekyll_file.is_file() assert latest_dir.is_dir() @@ -113,10 +121,10 @@ def test_publish_merge_to_main(self, temp_path, mock_git): # Stable only gets built on releases. assert not stable_dir.is_dir() # Ensure static content exists. - static_dir = latest_dir / "_static" assert static_dir.is_dir(), "Missing 'latest/_static'" logo = static_dir / "logo_green.svg" assert logo.is_file(), "Missing logo: 'latest/_static/logo_green.svg'" + assert not random_file.is_file() def test_publish_release(self, temp_path, mock_git): tag = "v1.0.0" From 8faa8b82eba2a0e391ff431c60367832fac943b8 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Mon, 9 Sep 2024 14:56:59 -0500 Subject: [PATCH 4/6] fix: try rmtree first --- sphinx_ape/build.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sphinx_ape/build.py b/sphinx_ape/build.py index 17b4968..47b90ab 100644 --- a/sphinx_ape/build.py +++ b/sphinx_ape/build.py @@ -210,4 +210,5 @@ def _setup_redirect(self): self.index_file.write_text(REDIRECT_HTML.format(redirect)) def _sphinx_build(self, dst_path: Path): + shutil.rmtree(dst_path, ignore_errors=True) sphinx_build(dst_path, self.docs_path) From 757bc8e3f15579462436beb4c1a86857c127cb8c Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 11 Sep 2024 10:53:02 -0500 Subject: [PATCH 5/6] chore: log --- sphinx_ape/sphinx_ext/plugin.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sphinx_ape/sphinx_ext/plugin.py b/sphinx_ape/sphinx_ext/plugin.py index 28a7f32..982d392 100644 --- a/sphinx_ape/sphinx_ext/plugin.py +++ b/sphinx_ape/sphinx_ext/plugin.py @@ -54,6 +54,10 @@ def setup(app: Sphinx): # Configure the HTML workings. static_dir = Path(__file__).parent.parent.parent / "_static" + + # Logging to DEBUG problems when this doesn't work in CI/CD. + logger.info(f"STATIC DIRECTORY: {static_dir}") + app.config.html_theme = "shibuya" app.config.html_favicon = str(static_dir / "favicon.ico") app.config.html_baseurl = package_name From 11eaa2f5b2cc7ecd6dd4116cfbaefd7139ba59ae Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Tue, 17 Sep 2024 16:57:56 -0500 Subject: [PATCH 6/6] fix: wrong path --- setup.py | 2 +- {_static => sphinx_ape/_static}/custom.css | 0 {_static => sphinx_ape/_static}/favicon.ico | Bin {_static => sphinx_ape/_static}/logo.gif | Bin {_static => sphinx_ape/_static}/logo_green.svg | 0 {_static => sphinx_ape/_static}/logo_grey.svg | 0 sphinx_ape/sphinx_ext/plugin.py | 5 +---- 7 files changed, 2 insertions(+), 5 deletions(-) rename {_static => sphinx_ape/_static}/custom.css (100%) rename {_static => sphinx_ape/_static}/favicon.ico (100%) rename {_static => sphinx_ape/_static}/logo.gif (100%) rename {_static => sphinx_ape/_static}/logo_green.svg (100%) rename {_static => sphinx_ape/_static}/logo_grey.svg (100%) diff --git a/setup.py b/setup.py index 8e36cc8..5eceec0 100644 --- a/setup.py +++ b/setup.py @@ -81,7 +81,7 @@ zip_safe=False, keywords="ethereum", packages=find_packages(exclude=["tests", "tests.*"]), - package_data={"sphinx_ape": ["py.typed"]}, + package_data={"sphinx_ape": ["py.typed", "_static/*"]}, classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", diff --git a/_static/custom.css b/sphinx_ape/_static/custom.css similarity index 100% rename from _static/custom.css rename to sphinx_ape/_static/custom.css diff --git a/_static/favicon.ico b/sphinx_ape/_static/favicon.ico similarity index 100% rename from _static/favicon.ico rename to sphinx_ape/_static/favicon.ico diff --git a/_static/logo.gif b/sphinx_ape/_static/logo.gif similarity index 100% rename from _static/logo.gif rename to sphinx_ape/_static/logo.gif diff --git a/_static/logo_green.svg b/sphinx_ape/_static/logo_green.svg similarity index 100% rename from _static/logo_green.svg rename to sphinx_ape/_static/logo_green.svg diff --git a/_static/logo_grey.svg b/sphinx_ape/_static/logo_grey.svg similarity index 100% rename from _static/logo_grey.svg rename to sphinx_ape/_static/logo_grey.svg diff --git a/sphinx_ape/sphinx_ext/plugin.py b/sphinx_ape/sphinx_ext/plugin.py index 982d392..85f325c 100644 --- a/sphinx_ape/sphinx_ext/plugin.py +++ b/sphinx_ape/sphinx_ext/plugin.py @@ -53,10 +53,7 @@ def setup(app: Sphinx): app.config.plausible_domain = "docs.apeworx.io" # Configure the HTML workings. - static_dir = Path(__file__).parent.parent.parent / "_static" - - # Logging to DEBUG problems when this doesn't work in CI/CD. - logger.info(f"STATIC DIRECTORY: {static_dir}") + static_dir = Path(__file__).parent.parent / "_static" app.config.html_theme = "shibuya" app.config.html_favicon = str(static_dir / "favicon.ico")