Skip to content

Commit

Permalink
Compilers must explicitly state that they use the .dep file for it to…
Browse files Browse the repository at this point in the history
… be always created and added as a target.
  • Loading branch information
felixfontein committed Oct 29, 2016
1 parent 6953d3d commit 022dbec
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 6 deletions.
6 changes: 5 additions & 1 deletion nikola/plugin_categories.py
Expand Up @@ -250,6 +250,7 @@ class PageCompiler(BasePlugin):
friendly_name = ''
demote_headers = False
supports_onefile = True
use_dep_file = False # If set to true, the .dep file is always written and added as a target
default_metadata = {
'title': '',
'slug': '',
Expand Down Expand Up @@ -277,7 +278,10 @@ def register_extra_dependencies(self, post):

def get_extra_targets(self, post, lang, dest):
"""Return a list of extra targets for the render_posts task when compiling the post for the specified language."""
return []
if self.use_dep_file:
return [post.base_path + '.dep']
else:
return []

def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
Expand Down
1 change: 1 addition & 0 deletions nikola/plugins/compile/html.py
Expand Up @@ -40,6 +40,7 @@ class CompileHtml(PageCompiler):

name = "html"
friendly_name = "HTML"
use_dep_file = True

def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
Expand Down
1 change: 1 addition & 0 deletions nikola/plugins/compile/ipynb.py
Expand Up @@ -70,6 +70,7 @@ class CompileIPynb(PageCompiler):
name = "ipynb"
friendly_name = "Jupyter/IPython Notebook"
demote_headers = True
use_dep_file = True
default_kernel = 'python2' if sys.version_info[0] == 2 else 'python3'

def set_site(self, site):
Expand Down
1 change: 1 addition & 0 deletions nikola/plugins/compile/markdown/__init__.py
Expand Up @@ -49,6 +49,7 @@ class CompileMarkdown(PageCompiler):
name = "markdown"
friendly_name = "Markdown"
demote_headers = True
use_dep_file = True
extensions = []
site = None

Expand Down
1 change: 1 addition & 0 deletions nikola/plugins/compile/pandoc.py
Expand Up @@ -44,6 +44,7 @@ class CompilePandoc(PageCompiler):

name = "pandoc"
friendly_name = "pandoc"
use_dep_file = True

def set_site(self, site):
"""Set Nikola site."""
Expand Down
1 change: 1 addition & 0 deletions nikola/plugins/compile/rest/__init__.py
Expand Up @@ -57,6 +57,7 @@ class CompileRest(PageCompiler):
name = "rest"
friendly_name = "reStructuredText"
demote_headers = True
use_dep_file = True
logger = None

def compile_string(self, data, source_path=None, is_two_file=True):
Expand Down
3 changes: 1 addition & 2 deletions nikola/plugins/task/posts.py
Expand Up @@ -84,14 +84,13 @@ def tl_ch():
k = p.split('####MAGIC####CONFIG:', 1)[-1]
deps_dict[k] = self.site.config.get(k)
dest = post.translated_base_path(lang)
dep_file = dest + '.dep'
file_dep = [p for p in post.fragment_deps(lang) if not p.startswith("####MAGIC####")]
extra_targets = post.compiler.get_extra_targets(post, lang, dest)
task = {
'basename': self.name,
'name': dest,
'file_dep': file_dep,
'targets': [dest, dep_file] + extra_targets,
'targets': [dest] + extra_targets,
'actions': [(post.compile, (lang, )),
(update_deps, (post, lang, )),
],
Expand Down
10 changes: 7 additions & 3 deletions nikola/post.py
Expand Up @@ -464,9 +464,13 @@ def register_depfile(self, dep, dest=None, lang=None):
def write_depfile(dest, deps_list):
"""Write a depfile for a given language."""
deps_path = dest + '.dep'
deps_list = [p for p in deps_list if p != dest] # Don't depend on yourself (#1671)
with io.open(deps_path, "w+", encoding="utf8") as deps_file:
deps_file.write('\n'.join(deps_list))
if deps_list or self.compiler.use_dep_file:
deps_list = [p for p in deps_list if p != dest] # Don't depend on yourself (#1671)
with io.open(deps_path, "w+", encoding="utf8") as deps_file:
deps_file.write('\n'.join(deps_list))
else:
if os.path.isfile(deps_path):
os.unlink(deps_path)

def _get_dependencies(self, deps_list):
deps = []
Expand Down

0 comments on commit 022dbec

Please sign in to comment.