示例#1
0
    def zip_tutorials(self):
        # make tutorials.zip

        # clean notebooks output
        for nb in DOCS.rglob("**/*.ipynb"):
            # This will erase all notebook output
            sh(
                f"jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace {nb}",
                silent=True,
            )

        # make zip of all ipynb
        def zipdir(path, dest, ziph):
            # ziph is zipfile handle
            for inb in path.rglob("**/*.ipynb"):
                if ".ipynb_checkpoints" in inb.parent.suffix:
                    continue
                basename = inb.stem
                sh(f"jupyter nbconvert {inb} --to notebook"
                   f" --ClearOutputPreprocessor.enabled=True"
                   f" --stdout > out_{basename}.ipynb")
                sh(f"rm {inb}", silent=True)
                sh(f"mv out_{basename}.ipynb {inb}", silent=True)
                arcnb = str(inb).replace(str(path), str(dest))
                ziph.write(inb, arcname=arcnb)

        zipf = zipfile.ZipFile("~notebooks.zip", "w", zipfile.ZIP_STORED)
        zipdir(SRC, "notebooks", zipf)
        zipdir(GALLERY / "auto_examples", Path("notebooks") / "examples", zipf)
        zipf.close()

        sh(f"mv ~notebooks.zip {DOWNLOADS}/{self.doc_version}-{PROJECTNAME}-notebooks.zip"
           )
示例#2
0
    def delnb(self):
        # Remove all ipynb before git commit

        for nb in SRC.rglob('**/*.ipynb'):
            sh.rm(nb)
        for nbch in SRC.glob('**/.ipynb_checkpoints'):
            sh(f'rm -r {nbch}')
示例#3
0
    def make_docs(self, builder="html", clean=False):
        # Make the html or latex documentation

        self.delnb()

        doc_version = self.doc_version

        if builder not in ["html", "latex"]:
            raise ValueError(
                'Not a supported builder: Must be "html" or "latex"')

        BUILDDIR = DOCREPO / builder

        print(
            f'{"-" * 80}\n'
            f"building {builder.upper()} documentation ({doc_version.capitalize()} version : {version})"
            f"\n in {BUILDDIR}"
            f'\n{"-" * 80}')

        # recreate dir if needed
        if clean:
            print("CLEAN:")
            self.clean(builder)
            # self.sync_notebook = True
            self.regenerate_api = True
        self.make_dirs()

        if self.regenerate_api:
            shutil.rmtree(API, ignore_errors=True)
            print(f"remove {API}")

        # run sphinx
        print(f"\n{builder.upper()} BUILDING:")
        srcdir = confdir = DOCS
        outdir = f"{BUILDDIR}/{doc_version}"
        doctreesdir = f"{DOCTREES}/{doc_version}"
        sp = Sphinx(srcdir, confdir, outdir, doctreesdir, builder)
        sp.verbosity = 1
        sp.build()

        print(f"\n{'-' * 130}\nBuild finished. The {builder.upper()} pages "
              f"are in {outdir}.")

        if doc_version == "stable":
            doc_version = "latest"
            # make also the latest identical
            sh(f"rm -rf {BUILDDIR}/latest")
            sh(f"cp -r  {BUILDDIR}/stable {BUILDDIR}/latest")

        if builder == "html":
            self.make_redirection_page()

        # a workaround to reduce the size of the image in the pdf document
        # TODO: v.0.2 probably better solution exists?
        if builder == "latex":
            self.resize_img(GALLERY, size=580.0)
示例#4
0
 def zipdir(path, dest, ziph):
     # ziph is zipfile handle
     for inb in path.rglob("**/*.ipynb"):
         if ".ipynb_checkpoints" in inb.parent.suffix:
             continue
         basename = inb.stem
         sh(f"jupyter nbconvert {inb} --to notebook"
            f" --ClearOutputPreprocessor.enabled=True"
            f" --stdout > out_{basename}.ipynb")
         sh(f"rm {inb}", silent=True)
         sh(f"mv out_{basename}.ipynb {inb}", silent=True)
         arcnb = str(inb).replace(str(path), str(dest))
         ziph.write(inb, arcname=arcnb)
示例#5
0
    def make_pdf(self):
        # Generate the PDF documentation

        doc_version = self.doc_version
        LATEXDIR = LATEX / doc_version
        print("Started to build pdf from latex using make.... "
              "Wait until a new message appear (it is a long! compilation) ")

        print("FIRST COMPILATION:")
        sh(f"cd {LATEXDIR}; lualatex -synctex=1 -interaction=nonstopmode spectrochempy.tex"
           )

        print("MAKEINDEX:")
        sh(f"cd {LATEXDIR}; makeindex spectrochempy.idx")

        print("SECOND COMPILATION:")
        sh(f"cd {LATEXDIR}; lualatex -synctex=1 -interaction=nonstopmode spectrochempy.tex"
           )

        print("move pdf file in the download dir")
        sh(f"cp {LATEXDIR / PROJECTNAME}.pdf {DOWNLOADS}/{doc_version}-{PROJECTNAME}.pdf"
           )
示例#6
0
 def delnb():
     # Remove all ipynb before git commit
     for nb in SRC.rglob("**/*.ipynb"):
         sh.rm(nb)
     for nbch in SRC.glob("**/.ipynb_checkpoints"):
         sh(f"rm -r {nbch}")