Repository: getnikola/nikola

Issue:
update a listing's file don't update mother page
Hi,

if it updates a file in listing directory, nikola build only rebuilds listing outpot, the page/s where that listing is used dont update. Its necessary same dummy change in it to force a nikola build update of that "mother" page.

Saludos

update a listing's file don't update mother page
Hi,

if it updates a file in listing directory, nikola build only rebuilds listing outpot, the page/s where that listing is used dont update. Its necessary same dummy change in it to force a nikola build update of that "mother" page.

Saludos



Discussion:
The listings directive doesn't add the listing source to the rest dependencies. Need to figure out how to do that.

The listings directive doesn't add the listing source to the rest dependencies. Need to figure out how to do that.


Resolving patch:
diff --git a/nikola/plugins/compile/rest/listing.py b/nikola/plugins/compile/rest/listing.py
--- a/nikola/plugins/compile/rest/listing.py
+++ b/nikola/plugins/compile/rest/listing.py
@@ -90,8 +90,10 @@ class Listing(CodeBlock):
 
     def run(self):
         fname = self.arguments.pop(0)
-        with codecs_open(os.path.join('listings', fname), 'rb+', 'utf8') as fileobject:
+        fpath = os.path.join('listings', fname)
+        with codecs_open(fpath, 'rb+', 'utf8') as fileobject:
             self.content = fileobject.read().splitlines()
+        self.state.document.settings.record_dependencies.add(fpath)
         self.trim_content()
         target = urlunsplit(("link", 'listing', fname, '', ''))
         generated_nodes = (
diff --git a/nikola/plugins/task/localsearch/__init__.py b/nikola/plugins/task/localsearch/__init__.py
--- a/nikola/plugins/task/localsearch/__init__.py
+++ b/nikola/plugins/task/localsearch/__init__.py
@@ -88,7 +88,6 @@ def save_data():
             with codecs.open(dst_path, "wb+", "utf8") as fd:
                 fd.write(output)
 
-
         yield {
             "basename": str(self.name),
             "name": dst_path,
@@ -100,8 +99,6 @@ def save_data():
         # file is changed.  We cheat, and depend on the sitemap task,
         # to run everytime a new file is added.
 
-
-
         # Copy all the assets to the right places
         asset_folder = os.path.join(os.path.dirname(__file__), "files")
         for task in copy_tree(asset_folder, kw["output_folder"]):


Test patch:
diff --git a/tests/test_rst_compiler.py b/tests/test_rst_compiler.py
--- a/tests/test_rst_compiler.py
+++ b/tests/test_rst_compiler.py
@@ -96,6 +96,7 @@ class ReSTExtensionTestCase(BaseTestCase):
     """ Base class for testing ReST extensions """
 
     sample = 'foo'
+    deps = None
 
     def setUp(self):
         """ Parse cls.sample into a HTML document tree """
@@ -109,6 +110,7 @@ def setHtmlFromRst(self, rst):
         tmpdir = tempfile.mkdtemp()
         inf = os.path.join(tmpdir, 'inf')
         outf = os.path.join(tmpdir, 'outf')
+        depf = os.path.join(tmpdir, 'outf.dep')
         with codecs.open(inf, 'wb+', 'utf8') as f:
             f.write(rst)
         self.html = self.compiler.compile_html(inf, outf)
@@ -116,6 +118,12 @@ def setHtmlFromRst(self, rst):
             self.html = f.read()
         os.unlink(inf)
         os.unlink(outf)
+        if os.path.isfile(depf):
+            with codecs.open(depf, 'r', 'utf8') as f:
+                self.assertEqual(self.deps, f.read())
+            os.unlink(depf)
+        else:
+            self.assertEqual(self.deps, None)
         os.rmdir(tmpdir)
         self.html_doc = html.parse(StringIO(self.html))
 
@@ -268,6 +276,7 @@ def test_youtube(self):
 class ListingTestCase(ReSTExtensionTestCase):
     """ Listing test case and CodeBlock alias tests """
 
+    deps = None
     sample1 = '.. listing:: nikola.py python'
     sample2 = '.. code-block:: python\n\n   import antigravity'
     sample3 = '.. sourcecode:: python\n\n   import antigravity'
@@ -286,10 +295,12 @@ def fake_open(*a, **kw):
 
     def test_listing(self):
         """ Test that we can render a file object contents without errors """
+        self.deps = 'listings/nikola.py'
         self.setHtmlFromRst(self.sample1)
 
     def test_codeblock_alias(self):
         """ Test CodeBlock aliases """
+        self.deps = None
         self.setHtmlFromRst(self.sample2)
         self.setHtmlFromRst(self.sample3)