[Python-modules-commits] [sphinx] 01/02: dh_sphinxdoc: Add support for singlehtml builds.

Dmitry Shachnev mitya57 at moszumanska.debian.org
Sun Sep 17 17:54:06 UTC 2017


This is an automated email from the git hooks/post-receive script.

mitya57 pushed a commit to branch debian/master
in repository sphinx.

commit 6310ab72409d4e490b6e8b9f3979a18a6450b750
Author: Dmitry Shachnev <mitya57 at gmail.com>
Date:   Sun Sep 17 19:19:35 2017 +0300

    dh_sphinxdoc: Add support for singlehtml builds.
    
    Closes: #872863.
---
 debian/changelog                 |  1 +
 debian/dh-sphinxdoc/dh_sphinxdoc | 83 ++++++++++++++++++++++++++++------------
 2 files changed, 59 insertions(+), 25 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index f145c0e..9590b73 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,7 @@ sphinx (1.6.3-2) UNRELEASED; urgency=medium
     in setuptools metadata (no_require_websupport.diff).
   * Backport upstream patch to fix crash with new python2.7
     (upstream_fix_crash_on_parallel_build.diff; closes: #869098).
+  * dh_sphinxdoc: Add support for singlehtml builds (closes: #872863).
 
  -- Dmitry Shachnev <mitya57 at debian.org>  Sat, 19 Aug 2017 18:30:31 +0300
 
diff --git a/debian/dh-sphinxdoc/dh_sphinxdoc b/debian/dh-sphinxdoc/dh_sphinxdoc
index 0ec5b2a..5d53ac5 100755
--- a/debian/dh-sphinxdoc/dh_sphinxdoc
+++ b/debian/dh-sphinxdoc/dh_sphinxdoc
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 
 # Copyright © 2011 Jakub Wilk <jwilk at debian.org>
-#           © 2014 Dmitry Shachnev <mitya57 at debian.org>
+#           © 2014-2017 Dmitry Shachnev <mitya57 at debian.org>
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are
@@ -189,17 +189,42 @@ sub looks_like_sphinx_doc($)
     return 1;
 }
 
-sub sanity_check($)
+sub looks_like_sphinx_singlehtml_doc($)
 {
-    local $/;
     my ($path) = @_;
-    my $indexfn = "$path/searchindex.js";
-    open(F, '<', $indexfn) or error("cannot open $indexfn");
-    my $index = <F>;
-    close(F);
-    $index =~ m{^Search[.]setIndex[(].*?filenames:\["(.*?)"\].*[)]$} or error("$indexfn doesn't look like a Sphinx search index");
-    $index = $1;
-    my $searchfn = "$path/search.html";
+    return 0 unless -f "$path/objects.inv";
+    return 0 unless -d "$path/_static";
+    # There should be exactly one HTML file in singlehtml build.
+    my @html_files = glob("$path/*.html");
+    return 0 if @html_files != 1;
+    # If searchindex.js exists, it is likely a broken html, not singlehtml.
+    return 0 if -f "$path/searchindex.js";
+    return 1;
+}
+
+sub sanity_check($$)
+{
+    local $/;
+    my ($path, $is_singlehtml) = @_;
+    my $searchfn;
+    my $index;
+    if ($is_singlehtml)
+    {
+        my @html_files = glob("$path/*.html");
+        # There is no search.html in singlehtml build, so we take the main HTML
+        # file for sanity checking and retrieving JS files.
+        $searchfn = $html_files[0];
+    }
+    else
+    {
+        my $indexfn = "$path/searchindex.js";
+        open(F, '<', $indexfn) or error("cannot open $indexfn");
+        $index = <F>;
+        close(F);
+        $index =~ m{^Search[.]setIndex[(].*?filenames:\["(.*?)"\].*[)]$} or error("$indexfn doesn't look like a Sphinx search index");
+        $index = $1;
+        $searchfn = "$path/search.html";
+    }
     open(F, '<', $searchfn) or error("cannot open $searchfn");
     my $search = <F>;
     close F;
@@ -215,26 +240,32 @@ sub sanity_check($)
         $sourcelink_suffix = ".txt";
     }
     my ($url_root) = $search =~ m{URL_ROOT:\s*'([^']*)'};
-    (%js and $loads_searchindex and defined $has_source and defined $url_root) or error("$searchfn doesn't look like a Sphinx search page");
+    %js or error("$searchfn does not include any JavaScript code");
+    $is_singlehtml or $loads_searchindex or error("$searchfn does not load searchindex.js");
+    defined $has_source or error("DOCUMENTATION_OPTIONS does not define HAS_SOURCE");
+    defined $url_root or error("DOCUMENTATION_OPTIONS does not define URL_ROOT");
     $has_source = $has_source eq 'true';
     $url_root =~ m{^([a-z]+:/)?/} and error("URL_ROOT in $searchfn is not relative");
     for my $js (keys(%js))
     {
         -f "$path/$js" or -l "$path/$js" or error("$path/$js is missing");
     }
-    for my $page (split(/","/, $index))
+    unless ($is_singlehtml)
     {
-        # Append sourcelink_suffix if the page name does not already end with it.
-        (my $sourcepage = $page) =~ s/(?<!$sourcelink_suffix)$/$sourcelink_suffix/;
-        -f "$path/_sources/$sourcepage"
-            or excludefile("$path/_sources/$sourcepage")
-            or error("$path/_sources/$sourcepage is missing")
-            if $has_source;
-        # Get the page basename before appending .html.
-        $page =~ s/\.[a-z]+$//;
-        -f "$path/$page.html"
-            or excludefile("$path/$page.html")
-            or error("$path/$page.html is missing");
+        for my $page (split(/","/, $index))
+        {
+            # Append sourcelink_suffix if the page name does not already end with it.
+            (my $sourcepage = $page) =~ s/(?<!$sourcelink_suffix)$/$sourcelink_suffix/;
+            -f "$path/_sources/$sourcepage"
+                or excludefile("$path/_sources/$sourcepage")
+                or error("$path/_sources/$sourcepage is missing")
+                if $has_source;
+            # Get the page basename before appending .html.
+            $page =~ s/\.[a-z]+$//;
+            -f "$path/$page.html"
+                or excludefile("$path/$page.html")
+                or error("$path/$page.html is missing");
+        }
     }
     if (opendir(D, "$path/_static/"))
     {
@@ -412,8 +443,10 @@ sub list_built_using($)
 sub fix_sphinx_doc($$)
 {
     my ($package, $path) = @_;
-    return 0 if not looks_like_sphinx_doc($path);
-    my @js = sanity_check($path);
+    my $is_html = looks_like_sphinx_doc($path);
+    my $is_singlehtml = looks_like_sphinx_singlehtml_doc($path);
+    return 0 if not ($is_html or $is_singlehtml);
+    my @js = sanity_check($path, $is_singlehtml);
     my @rtd_deps = process_rtd($path);
     my @deps = fix_symlinks($path, @js);
     my @built_using = list_built_using($path);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/sphinx.git



More information about the Python-modules-commits mailing list