Bug 1390693 - Fold `mach doc-upload` into `mach doc`; r?dustin draft
authorGregory Szorc <gps@mozilla.com>
Thu, 24 Aug 2017 11:31:54 -0700
changeset 652433 1b86f913f9102e3abc3d1e8ff1c020aad9a190ac
parent 652432 0061aa1f8cb9675b30c7db680e1f97334391b3f1
child 652434 44548d7131582b817723fb040e4a6819d14096fc
push id76055
push usergszorc@mozilla.com
push dateThu, 24 Aug 2017 20:42:35 +0000
reviewersdustin
bugs1390693
milestone57.0a1
Bug 1390693 - Fold `mach doc-upload` into `mach doc`; r?dustin We now have an --upload flag to control whether upload is performed. We don't inline it because we want to maintain a "firewall" between regular docs and all the extra packages and imports needed for S3. MozReview-Commit-ID: DVKhsS545gp
taskcluster/ci/source-test/doc.yml
tools/docs/mach_commands.py
--- a/taskcluster/ci/source-test/doc.yml
+++ b/taskcluster/ci/source-test/doc.yml
@@ -35,16 +35,16 @@ doc-upload:
     run-on-projects: [mozilla-central]
     worker-type: aws-provisioner-v1/gecko-t-linux-xlarge
     worker:
         docker-image: {in-tree: "lint"}
         max-run-time: 1800
         taskcluster-proxy: true
     run:
         using: run-task
-        command: cd /home/worker/checkouts/gecko && ./mach doc-upload
+        command: cd /home/worker/checkouts/gecko && ./mach doc --upload --no-open
     scopes:
         - secrets:get:project/releng/gecko/build/level-{level}/gecko-docs-upload
     when:
         files-changed:
             - '**/*.py'
             - '**/*.rst'
             - 'tools/docs/**'
--- a/tools/docs/mach_commands.py
+++ b/tools/docs/mach_commands.py
@@ -33,18 +33,20 @@ class Documentation(MachCommandBase):
     @CommandArgument('--archive', action='store_true',
                      help='Write a gzipped tarball of generated docs')
     @CommandArgument('--no-open', dest='auto_open', default=True,
                      action='store_false',
                      help="Don't automatically open HTML docs in a browser.")
     @CommandArgument('--http', const=':6666', metavar='ADDRESS', nargs='?',
                      help='Serve documentation on an HTTP server, '
                           'e.g. ":6666".')
+    @CommandArgument('--upload', action='store_true',
+                     help='Upload generated files to S3')
     def build_docs(self, what=None, format=None, outdir=None, auto_open=True,
-                   http=None, archive=False):
+                   http=None, archive=False, upload=False):
         self._activate_virtualenv()
         self.virtualenv_manager.install_pip_package('sphinx_rtd_theme==0.1.6')
 
         import sphinx
         import webbrowser
         import moztreedocs
 
         if not outdir:
@@ -81,16 +83,19 @@ class Documentation(MachCommandBase):
                 generated.append(savedir)
 
             if archive:
                 archive_path = os.path.join(outdir,
                                             '%s.tar.gz' %  project)
                 moztreedocs.create_tarball(archive_path, savedir)
                 print('Archived to %s' % archive_path)
 
+            if upload:
+                self._s3_upload(savedir)
+
             index_path = os.path.join(savedir, 'index.html')
             if not http and auto_open and os.path.isfile(index_path):
                 webbrowser.open(index_path)
 
         if generated:
             print('\nGenerated documentation:\n%s\n' % '\n'.join(generated))
 
         if failed:
@@ -119,30 +124,21 @@ class Documentation(MachCommandBase):
 
     def _find_doc_dir(self, path):
         search_dirs = ('doc', 'docs')
         for d in search_dirs:
             p = os.path.join(path, d)
             if os.path.isfile(os.path.join(p, 'conf.py')):
                 return p
 
-    @Command('doc-upload', category='devenv',
-        description='Generate and upload documentation from the tree.')
-    @CommandArgument('what', nargs='*', metavar='DIRECTORY [, DIRECTORY]',
-        help='Path(s) to documentation to build and upload.')
-    def upload_docs(self, what=None):
-        self._activate_virtualenv()
+    def _s3_upload(self, root):
         self.virtualenv_manager.install_pip_package('boto3==1.4.4')
 
-        outdir = os.path.join(self.topobjdir, 'docs')
-        self.build_docs(what=what, outdir=outdir, format='html')
-
         from moztreedocs import distribution_files
         from moztreedocs.upload import s3_upload
-        files = distribution_files(os.path.join(outdir, 'html',
-                                                'Mozilla_Source_Tree_Docs'))
+        files = distribution_files(root)
         s3_upload(files)
 
 
 def die(msg, exit_code=1):
     msg = '%s: %s' % (sys.argv[0], msg)
     print(msg, file=sys.stderr)
     return exit_code