Skip to content

Commit

Permalink
Merge pull request #11 from antazoey/fix/missing-resources
Browse files Browse the repository at this point in the history
fix: issue where `_static` was not updating on publish
  • Loading branch information
antazoey authored Sep 17, 2024
2 parents 4abd93c + 11eaa2f commit 0086855
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
10 changes: 8 additions & 2 deletions sphinx_ape/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -204,5 +209,6 @@ 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):
shutil.rmtree(dst_path, ignore_errors=True)
sphinx_build(dst_path, self.docs_path)
3 changes: 2 additions & 1 deletion sphinx_ape/sphinx_ext/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def setup(app: Sphinx):
app.config.plausible_domain = "docs.apeworx.io"

# Configure the HTML workings.
static_dir = Path(__file__).parent.parent.parent / "_static"
static_dir = Path(__file__).parent.parent / "_static"

app.config.html_theme = "shibuya"
app.config.html_favicon = str(static_dir / "favicon.ico")
app.config.html_baseurl = package_name
Expand Down
40 changes: 33 additions & 7 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -89,15 +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)
# 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()
Expand All @@ -106,11 +120,17 @@ 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.
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"
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)
Expand All @@ -126,3 +146,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}"

0 comments on commit 0086855

Please sign in to comment.