예제 #1
0
def pylit_build(infile, outfile):
    """Essentially: ``python3 -m pylit -t source/demo/data_quality.rst demo/test.py``
  
    The issue here is that we need to provide platform-specific paths.
    """
    if os.sep != '/':
        # Fix windows paths.
        infile = os.path.join(*infile.split('/'))
        outfile = os.path.join(*outfile.split('/'))
    pylit.main(txt2code=True, overwrite="yes", infile=infile, outfile=outfile)
예제 #2
0
def pylit_build_rst(pyFile, rstFile):
    """Essentially: ``python3 -m pylit -c demo/test.py source/demo/data_quality.rst``
    """
    try:
        pylit.main(txt2code=False,
                   overwrite="yes",
                   infile=rstFile,
                   outfile=pyFile,
                   args=[])
    except IOError as ex:
        print("Did not overwrite {pyFile}")
예제 #3
0
def pylit_build_py(pyFile, rstFile):
    """Essentially: ``python3 -m pylit -t source/demo/data_quality.rst demo/test.py``
    """
    try:
        pylit.main(txt2code=True,
                   overwrite="update",
                   infile=pyFile,
                   outfile=rstFile,
                   args=[])
    except SystemExit as ex:
        pass
예제 #4
0
def run_pylit():
    """Run pylit to build docs from some sources"""
    # Get location of files
    sphinx_source_dir = os.path.abspath(os.path.dirname(__file__))
    repo_dir = os.path.abspath(os.path.join(sphinx_source_dir, os.path.pardir, os.path.pardir))
    ci_source = os.path.join(repo_dir, "circle.yml")
    ci_text = os.path.join(sphinx_source_dir, "circle.rst")

    # Run pylit
    pylit.main(args=["-c", ci_source, ci_text])

    # Copy source to doc source dir (for inclusion in doc)
    shutil.copyfile(ci_source, os.path.join(sphinx_source_dir, "circle.yml"))
예제 #5
0
파일: update.py 프로젝트: slott56/my-euler
    def build( self, modulename ):
        arg_template= ("-c", "--overwrite=yes", "../{0}.py", "source/{0}.rst")
        args= [ a.format(modulename) for a in arg_template ]
        print( "python3.4 -m pylit", " ".join(args) )

        # Separate command...
        #try:
        #    text= subprocess.check_call( "/usr/local/bin/python3.4 -m pylit "+" ".join(args), shell=True )
        #except  subprocess.CalledProcessError  as exc:
        #    print( "ERROR", exc.output )
        #    raise

        # Better, but doesn't work when run under Komodo for some obscure reason.
        try:
            pylit.main( args )
        except Exception as exc:
            print( "Can't process {0}: {1}".format(modulename,exc) )
예제 #6
0
def weave(source, target):
    if not exists(target):
        makedirs(target)
    for f in glob(joinpath(source,'*')):
        #print "processing",f
        if f.endswith(".py") and ispylit(f):
            rstfile = joinpath(target, basename(f).replace('.py','.rst'))
            pyclean = joinpath(target, basename(f))
            if newer(rstfile, f):
                # Convert executable literate file to rst file with embedded code
                pylit.main(["--codeindent=4", f, rstfile])
                # Convert rest file with embedded code to clean code file
                pylit.main([rstfile, pyclean, "-s", "-t"])
        else:
            dest = joinpath(target, basename(f))
            if newer(dest, f):
                if f.endswith(".py"):
                    print("Warning: file %r is not a pylit file"%(f,))
                #print "copying",f,dest
                copyfile(f, dest)
예제 #7
0
def appendLiterateBlock(sourcePath, outfile):
   """Convert the source to reStructuredText and write it to the output file.
   
   Parameters:
      sourcePath - the path to a source file to be processed by PyLit. If the 
                   source isn't python this function can be updated to include 
                   an optional comment style parameter to configure PyLit. The 
                   default for PyLit is "# ".
      outfile - the result of the conversion will be written into outfile 
                wherever the current seek position happens to be.

   """

   outfile.write("#%s%s:\n%s\n\n" %\
                (os.path.sep,
                sourcePath,
                "-" * (len(sourcePath) + len(os.path.sep) + 2)))
   pylit.main([sourcePath, TMP_LIT])
   append(TMP_LIT, outfile)
   os.remove(TMP_LIT)
예제 #8
0
def weave(source, target):
    if not exists(target):
        makedirs(target)
    for f in glob(joinpath(source, '*')):
        if f.endswith('__pycache__') or f.endswith('pyc'):
            continue  # skip precompiled python files
        #print "processing",f
        if f.endswith(".py") and ispylit(f):
            rstfile = joinpath(target, basename(f).replace('.py', '.rst'))
            pyclean = joinpath(target, basename(f))
            if newer(rstfile, f):
                # Convert executable literate file to rst file with embedded code
                pylit.main([f, rstfile])
                # Convert rest file with embedded code to clean code file
                pylit.main([rstfile, pyclean, "-s", "-t"])
        else:
            dest = joinpath(target, basename(f))
            if newer(dest, f):
                if f.endswith(".py"):
                    print("Warning: file %r is not a pylit file" % (f, ))
                #print "copying",f,dest
                copyfile(f, dest)
예제 #9
0
def process():
    """Copy demo rst files (C++ and Python) from the DOLFIN source tree
    into the demo source tree, and process file with pylit

    """

    # Check that we can find pylint.py for converting foo.py.rst to
    # foo.py
    pylit_parser = "pylit.py"
    if os.path.isfile(pylit_parser):
        pass
    else:
        raise RuntimeError("Cannot find pylit.py")

    # Directories to scan
    subdirs = ["../../demo/documented"]

    # Iterate over subdirectories containing demos
    for subdir in subdirs:

        # Get list of demos (demo name , subdirectory)
        demos = [(dI, os.path.join(subdir, dI)) for dI in os.listdir(subdir)
                 if os.path.isdir(os.path.join(subdir, dI))]

        # Iterate over demos
        for demo, path in demos:

            # Make demo doc directory
            demo_dir = os.path.join('./demos/', demo)
            if not os.path.exists(demo_dir):
                os.makedirs(demo_dir)

            #for f in rst_files_common:
            #    shutil.copy(os.path.join(path, f), demo_dir)

            # Build list of rst and png files in demo source directory
            rst_files = [
                f for f in os.listdir(path) if os.path.splitext(f)[1] == ".rst"
            ]
            other_files = [
                f for f in os.listdir(path)
                if os.path.splitext(f)[1] in (".png", ".pdf", ".gif", ".py",
                                              ".gz", ".yaml", ".zip")
            ]

            # Create directory in documentation tree for demo
            demo_dir = os.path.join('./demos/', demo)
            if not os.path.exists(demo_dir):
                os.makedirs(demo_dir)

            # Copy .png and .py files into documentation demo directory
            for f in other_files:
                shutil.copy(os.path.join(path, f), demo_dir)

            # # Copy input folders
            # if "Input_Data" in os.listdir(path):
            #     input_path = os.path.join(path, "Input_Data")
            #     demo_input_dir = os.path.join(demo_dir, "Input_Data/")
            #     if not os.path.exists(demo_input_dir):
            #         os.makedirs(demo_input_dir)
            #     for f in os.listdir(input_path):
            #         shutil.copy(os.path.join(input_path, f), demo_input_dir)

            # Copy rst files into documentation demo directory
            for f in rst_files:
                shutil.copy(os.path.join(path, f), demo_dir)

                # Copy rst files into documentation demo directory and
            # process with Pylit
            for f in rst_files:
                shutil.copy(os.path.join(path, f), demo_dir)
                # Run pylit on py.rst files (files with 'double
                # extensions')
                if os.path.splitext(os.path.splitext(f)[0])[1] == ".py":
                    rst_file = os.path.join(demo_dir, f)
                    pylit.main([rst_file])
예제 #10
0
def process():
    """Copy demo rst files (C++ and Python) from the DOLFIN source tree
    into the demo source tree, and process file with pylit

    """

    # Check that we can find pylint.py for converting foo.py.rst to
    # foo.py
    pylit_parser = "../../../utils/pylit/pylit.py"
    if os.path.isfile(pylit_parser):
        pass
    else:
        raise RuntimeError("Cannot find pylit.py")

    # Directories to scan
    subdirs = ["../../demo/documented"]

    # Iterate over subdirectories containing demos
    for subdir in subdirs:

        # Get list of demos (demo name , subdirectory)
        demos = [(dI, os.path.join(subdir, dI)) for dI in os.listdir(subdir) if os.path.isdir(os.path.join(subdir, dI))]

        # Iterate over demos
        for demo, path in demos:

            # Make demo doc directory
            demo_dir = os.path.join('./demos/', demo)
            if not os.path.exists(demo_dir):
                os.makedirs(demo_dir)

            #for f in rst_files_common:
            #    shutil.copy(os.path.join(path, f), demo_dir)

            # Build list of rst and png files in demo source directory
            rst_files = [f for f in os.listdir(path) if os.path.splitext(f)[1] == ".rst" ]
            other_files = [f for f in os.listdir(path) if os.path.splitext(f)[1] in (".png", ".gif", ".py", ".gz")]

            # Create directory in documentation tree for demo
            demo_dir = os.path.join('./demos/', demo)
            if not os.path.exists(demo_dir):
                os.makedirs(demo_dir)

            # Copy .png and .py files into documentation demo directory
            for f in other_files:
                shutil.copy(os.path.join(path, f), demo_dir)

            # Copy rst files into documentation demo directory
            for f in rst_files:
                shutil.copy(os.path.join(path, f), demo_dir)

                # Copy rst files into documentation demo directory and
            # process with Pylit
            for f in rst_files:
                shutil.copy(os.path.join(path, f), demo_dir)

                # Run pylit on py.rst files (files with 'double
                # extensions')
                if os.path.splitext(os.path.splitext(f)[0])[1] in (".py"):
                    rst_file = os.path.join(demo_dir, f)
                    pylit.main([rst_file])
예제 #11
0
import os
import pylit

pylit.defaults.text_extensions = [".rst"]

path = os.path.dirname(os.path.realpath(__file__))
for file in os.listdir(path):
    if file.endswith(".py") and file.startswith("demo"):
        pylit.main([file])