Skip to content

Commit

Permalink
implement alternative file overwriting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DianaBanta committed Feb 17, 2025
1 parent 0eab53a commit 5ee4e16
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling", "hatch-vcs", "setuptools>=61.0"]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
Expand Down Expand Up @@ -73,6 +73,3 @@ build.hooks.vcs.version-file = "src/teachbooks_sphinx_thebe/_version.py"
testpaths = [
"tests",
]

[tool.hatch.build.hooks.custom]
path = "src/teachbooks_sphinx_thebe/build_hook.py"
21 changes: 21 additions & 0 deletions src/teachbooks_sphinx_thebe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from docutils import nodes
from sphinx.util import logging
import shutil
import sysconfig
# import src.teachbooks_sphinx_thebe.build_hook as overwrite_files

from wcmatch import glob

Expand Down Expand Up @@ -347,6 +349,23 @@ def copy_over_files(app, exception):
),
)

def overwrite_files():
site_packages = sysconfig.get_paths()["purelib"]
sphinx_thebe_path = os.path.join(site_packages, "sphinx_thebe")
teachbooks_path = os.path.dirname(__file__) # Dynamically gets the package location
print("---------------")
print("teachbooks path: ", teachbooks_path, ", sphinx thebe path: ", sphinx_thebe_path)
print("---------------")
if os.path.exists(sphinx_thebe_path):
shutil.rmtree(sphinx_thebe_path)

if not teachbooks_path:
print("Couldn't find teachbooks path!")
return

shutil.move(teachbooks_path, sphinx_thebe_path)
print("Files overwritten successfully!")


def setup(app):
logger.verbose("Adding copy buttons to code blocks...")
Expand Down Expand Up @@ -388,6 +407,8 @@ def setup(app):
override=True,
)

overwrite_files()

return {
"version": __version__,
"parallel_read_safe": True,
Expand Down
17 changes: 0 additions & 17 deletions src/teachbooks_sphinx_thebe/build_hook.py

This file was deleted.

0 comments on commit 5ee4e16

Please sign in to comment.