Skip to content

Commit

Permalink
fix(template): Cleanup symlink causes unnecessary rebuild in next build
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverRainZ committed Jun 26, 2024
1 parent 1aa4e7e commit 3fe4f21
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/sphinxnotes/any/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,27 @@ def _on_builder_inited(cls, app:Sphinx):
cls._srcdir = path.join(app.srcdir, reldir)
cls._reldir = path.join('/', reldir) # abspath relatived to srcdir

# Cleanup possible residual symlink.
if path.islink(cls._srcdir):
os.unlink(cls._srcdir)
if path.exists(cls._srcdir):
os.remove(cls._srcdir)
# Link them.
ensuredir(cls._outdir)
os.symlink(cls._outdir, cls._srcdir)
# Link srcdir -> outdir when needed.
if not path.exists(cls._srcdir):
os.symlink(cls._outdir, cls._srcdir)
elif not path.islink(cls._srcdir):
os.remove(cls._srcdir)
os.symlink(cls._outdir, cls._srcdir)

logger.debug(f'[any] srcdir: {cls._srcdir}')
logger.debug(f'[any] outdir: {cls._outdir}')


@classmethod
def _on_build_finished(cls, app:Sphinx, exception):
os.unlink(cls._srcdir)
# NOTE: no need to clean up the symlink, it will cause unnecessary
# rebuild because file is mssiing from Sphinx's srcdir. Logs like:
#
# [build target] changed 'docname' missing dependency 'xxx.jpg'
#
# os.unlink(cls._srcdir)
pass


def __init__(self, *args, **kwargs):
Expand Down

0 comments on commit 3fe4f21

Please sign in to comment.