def build(all, wd): from paver.tasks import main as paver_main if wd: os.chdir(wd) else: os.chdir(findProjectRoot()) sys.path.insert(0, os.getcwd()) version = require("runestone")[0].version print("Building with Runestone {}".format(version)) with open('conf.py') as cf: ctext = cf.read() if not re.search(r"from runestone import.*setup", ctext): click.echo(click.style("Please update conf.py to import setup from runestone", fg='red'), err=True, color=True) click.echo("The current line probably looks like:\nfrom runestone import runestone_static_dirs, runestone_extensions") click.echo("Change it to:\nfrom runestone import runestone_static_dirs, runestone_extensions, setup") sys.exit(1) import pavement if not os.path.exists(pavement.options.build.builddir): os.makedirs(pavement.options.build.builddir) myargs = ["build"] if all: myargs.append("--all") paver_main(args=myargs)
def main(): import os import sys from paver.tasks import main as paver_main args = ['-f', os.path.join(os.path.dirname(__file__), 'pavement.py')] args = args + sys.argv[1:] paver_main(args)
def build(all): from paver.tasks import main as paver_main os.chdir(findProjectRoot()) myargs = ['build'] if all: myargs.append('--all') paver_main(args=myargs)
def build(all, wd): from paver.tasks import main as paver_main if wd: os.chdir(wd) else: os.chdir(findProjectRoot()) sys.path.insert(0, os.getcwd()) if not pathlib.Path( resource_filename("runestone", "dist/webpack_static_imports.json")).exists(): click.echo( "Error -- you are missing webpack_static_imports.json. Please make sure" ) click.echo("you have Runestone installed correctly.") click.echo("In a development environment, execute npm run build.") sys.exit(-1) version = require("runestone")[0].version print("Building with Runestone {}".format(version)) with open("conf.py", encoding="utf-8") as cf: ctext = cf.read() if not re.search(r"from runestone import.*(setup|script_files)", ctext): click.echo( click.style( """Please update conf.py to import setup or script_files and css_files from runestone. If you do not import setup you must provide your own.""", fg="red", ), err=True, color=True, ) click.echo( "The current line probably looks like:\nfrom runestone import runestone_static_dirs, runestone_extensions" ) click.echo( "Change it to:\nfrom runestone import runestone_static_dirs, runestone_extensions, setup" ) sys.exit(1) import pavement if not os.path.exists(pavement.options.build.builddir): os.makedirs(pavement.options.build.builddir) myargs = ["build"] if all: myargs.append("--all") paver_main(args=myargs)
def build(all): from paver.tasks import main as paver_main os.chdir(findProjectRoot()) sys.path.insert(0, os.getcwd()) import pavement if not os.path.exists(pavement.options.build.builddir): os.makedirs(pavement.options.build.builddir) myargs = ['build'] if all: myargs.append('--all') paver_main(args=myargs)
def build(all): from paver.tasks import main as paver_main os.chdir(findProjectRoot()) sys.path.insert(0, os.getcwd()) version = require("runestone")[0].version print("Building with Runestone {}".format(version)) import pavement if not os.path.exists(pavement.options.build.builddir): os.makedirs(pavement.options.build.builddir) myargs = ['build'] if all: myargs.append('--all') paver_main(args=myargs)
def run_sphinx(rvars=None, folder=None, application=None, http_host=None, base_course=None): # workingdir is the application folder workingdir = folder mylog = logging.getLogger('web2py.root') # sourcedir holds the all sources temporarily sourcedir = path.join(workingdir, 'build', rvars['projectname']) # create the custom_courses dir if it doesn't already exist if not os.path.exists(path.join(workingdir, 'custom_courses')): os.mkdir(path.join(workingdir, 'custom_courses')) # confdir holds the conf and index files confdir = path.join(workingdir, 'custom_courses', rvars['projectname']) custom_dir = confdir if not os.path.exists(custom_dir): os.mkdir(custom_dir) # ## check for base_course if base_course == None ### read conf.py and look for How to Think to determine coursetype if base_course == None: base_course = 'thinkcspy' # copy all the sources into the temporary sourcedir if os.path.exists(sourcedir): shutil.rmtree(sourcedir) shutil.copytree(path.join(workingdir, 'books', base_course), sourcedir) makePavement(http_host, rvars, sourcedir) shutil.copy(path.join(sourcedir,'pavement.py'),custom_dir) ######### # We're rebuilding a course ######### if rvars['coursetype'] == 'rebuildcourse': try: # copy the index and conf files to the sourcedir shutil.copy(path.join(confdir, 'pavement.py'), path.join(sourcedir, 'pavement.py')) shutil.copy(path.join(confdir, 'index.rst'), path.join(sourcedir, '_sources', 'index.rst')) # copy the assignments.rst file from confidir as it may contain assignments written # by the instructor shutil.copy(path.join(confdir, 'assignments.rst'), path.join(sourcedir, '_sources', 'assignments.rst')) if os.path.exists(path.join(confdir, 'toc.rst')): shutil.copy(path.join(confdir, 'toc.rst'), path.join(sourcedir, '_sources', 'toc.rst')) except OSError: # Either the sourcedir already exists (meaning this is probably devcourse, thinkcspy, etc, # or the conf.py or index.rst files are missing for some reason. raise OSError("missing paver, index, or assignments file") ######## # we're just copying one of the pre-existing books ######## else: # Save copies of files that the instructor may customize shutil.copy(path.join(sourcedir,'_sources', 'index.rst'),custom_dir) shutil.copy(path.join(sourcedir,'_sources', 'assignments.rst'),custom_dir) if os.path.exists(path.join(sourcedir,'_sources', 'toc.rst')): shutil.copy(path.join(sourcedir,'_sources', 'toc.rst'),custom_dir) ########### # Set up and run Paver build ########### from paver.tasks import main as paver_main os.chdir(sourcedir) paver_main(args=["build"]) try: shutil.copy('build_info',custom_dir) except IOError as copyfail: logging.debug("Failed to copy build_info_file") logging.debug(copyfail.message) if base_course == 'thinkcspy' or base_course == 'pip2': idxname = 'toc.rst' else: idxname = 'index.rst' # # Build the completion database # sys.path.insert(0,path.join(folder,'modules')) from chapternames import addChapterInfoFromScheduler, findChaptersSubChapters scd, ct = findChaptersSubChapters(path.join(sourcedir, '_sources', idxname)) addChapterInfoFromScheduler(scd, ct, rvars['projectname'],db) for root, dirs, files in os.walk(sourcedir): for fn in files: if fn.endswith('.rst'): fh = open(path.join(root, fn), 'r') populateSubchapter(root, fn, fh, sourcedir, rvars['projectname']) # # move the sourcedir/build/projectname folder into static # shutil.rmtree(os.path.join(workingdir,'static',rvars['projectname']),ignore_errors=True) shutil.move(os.path.join(sourcedir,'build',rvars['projectname']), os.path.join(workingdir,'static',rvars['projectname']) ) # # clean up # shutil.rmtree(sourcedir) donefile = open(os.path.join(custom_dir, 'done'), 'w') donefile.write('success') donefile.close()
def run_sphinx(rvars=None, folder=None, application=None, http_host=None, base_course=None): # workingdir is the application folder workingdir = folder # sourcedir holds the all sources temporarily sourcedir = path.join(workingdir, 'build', rvars['projectname']) rslogger.debug("Starting to build {}".format(rvars['projectname'])) # create the custom_courses dir if it doesn't already exist if not os.path.exists(path.join(workingdir, 'custom_courses')): os.mkdir(path.join(workingdir, 'custom_courses')) # confdir holds the conf and index files custom_dir = path.join(workingdir, 'custom_courses', rvars['projectname']) if not os.path.exists(custom_dir): os.mkdir(custom_dir) # ## check for base_course if base_course == None ### read conf.py and look for How to Think to determine coursetype if base_course == None: base_course = 'thinkcspy' # copy all the sources into the temporary sourcedir if os.path.exists(sourcedir): shutil.rmtree(sourcedir) shutil.copytree(path.join(workingdir, 'books', base_course), sourcedir) makePavement(http_host, rvars, sourcedir, base_course) shutil.copy(path.join(sourcedir,'pavement.py'),custom_dir) ######### # We're rebuilding a course ######### if rvars['coursetype'] == 'rebuildcourse': try: # copy the index and conf files to the sourcedir shutil.copy(path.join(custom_dir, 'pavement.py'), path.join(sourcedir, 'pavement.py')) shutil.copy(path.join(custom_dir, 'index.rst'), path.join(sourcedir, '_sources', 'index.rst')) except OSError: # Either the sourcedir already exists (meaning this is probably devcourse, thinkcspy, etc, # or the conf.py or index.rst files are missing for some reason. raise OSError("missing paver, index, or assignments file") ######## # we're just copying one of the pre-existing books ######## else: # Save copies of files that the instructor may customize shutil.copy(path.join(sourcedir,'_sources', 'index.rst'),custom_dir) ########### # Set up and run Paver build ########### from paver.tasks import main as paver_main old_cwd = os.getcwd() os.chdir(sourcedir) paver_main(args=["build"]) rslogger.debug("Finished build of {}".format(rvars['projectname'])) try: shutil.copy('build_info',custom_dir) except IOError as copyfail: rslogger.debug("Failed to copy build_info_file") rslogger.debug(copyfail.message) idxname = 'index.rst' # # move the sourcedir/build/projectname folder into static # shutil.rmtree(os.path.join(workingdir,'static',rvars['projectname']),ignore_errors=True) shutil.move(os.path.join(sourcedir,'build',rvars['projectname']), os.path.join(workingdir,'static',rvars['projectname']) ) # # clean up # # This will remove a directory that's versioned by Git, which marks some of its files as read-only on Windows. This causes rmtree to fail. So, provide a workaround per `SO <https://stackoverflow.com/questions/21261132/shutil-rmtree-to-remove-readonly-files>`_. def del_rw(function, path, excinfo): os.chmod(path, stat.S_IWRITE) if os.path.isdir(path): os.rmdir(path) else: os.remove(path) # Change away from sourcedir, to avoid an error like ``WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'E:\\Runestone\\web2py\\applications\\runestone\\build\\test_book10'``. os.chdir(old_cwd) shutil.rmtree(sourcedir, onerror=del_rw) rslogger.debug("Completely done with {}".format(rvars['projectname']))
def run_sphinx(rvars=None, folder=None, application=None, http_host=None, base_course=None): # workingdir is the application folder workingdir = folder mylog = logging.getLogger('web2py.root') # sourcedir holds the all sources temporarily sourcedir = path.join(workingdir, 'build', rvars['projectname']) # create the custom_courses dir if it doesn't already exist if not os.path.exists(path.join(workingdir, 'custom_courses')): os.mkdir(path.join(workingdir, 'custom_courses')) # confdir holds the conf and index files confdir = path.join(workingdir, 'custom_courses', rvars['projectname']) custom_dir = confdir if not os.path.exists(custom_dir): os.mkdir(custom_dir) # ## check for base_course if base_course == None ### read conf.py and look for How to Think to determine coursetype if base_course == None: base_course = 'thinkcspy' # copy all the sources into the temporary sourcedir if os.path.exists(sourcedir): shutil.rmtree(sourcedir) shutil.copytree(path.join(workingdir, 'books', base_course), sourcedir) makePavement(http_host, rvars, sourcedir) shutil.copy(path.join(sourcedir, 'pavement.py'), custom_dir) ######### # We're rebuilding a course ######### if rvars['coursetype'] == 'rebuildcourse': try: # copy the index and conf files to the sourcedir shutil.copy(path.join(confdir, 'pavement.py'), path.join(sourcedir, 'pavement.py')) shutil.copy(path.join(confdir, 'index.rst'), path.join(sourcedir, '_sources', 'index.rst')) # copy the assignments.rst file from confidir as it may contain assignments written # by the instructor shutil.copy(path.join(confdir, 'assignments.rst'), path.join(sourcedir, '_sources', 'assignments.rst')) if os.path.exists(path.join(confdir, 'toc.rst')): shutil.copy(path.join(confdir, 'toc.rst'), path.join(sourcedir, '_sources', 'toc.rst')) except OSError: # Either the sourcedir already exists (meaning this is probably devcourse, thinkcspy, etc, # or the conf.py or index.rst files are missing for some reason. raise OSError("missing paver, index, or assignments file") ######## # we're just copying one of the pre-existing books ######## else: # Save copies of files that the instructor may customize shutil.copy(path.join(sourcedir, '_sources', 'index.rst'), custom_dir) shutil.copy(path.join(sourcedir, '_sources', 'assignments.rst'), custom_dir) if os.path.exists(path.join(sourcedir, '_sources', 'toc.rst')): shutil.copy(path.join(sourcedir, '_sources', 'toc.rst'), custom_dir) ########### # Set up and run Paver build ########### from paver.tasks import main as paver_main os.chdir(sourcedir) paver_main(args=["build"]) try: shutil.copy('build_info', custom_dir) except IOError as copyfail: logging.debug("Failed to copy build_info_file") logging.debug(copyfail.message) if base_course == 'thinkcspy' or base_course == 'pip2': idxname = 'toc.rst' else: idxname = 'index.rst' # # Build the completion database # sys.path.insert(0, path.join(folder, 'modules')) from chapternames import addChapterInfoFromScheduler, findChaptersSubChapters scd, ct = findChaptersSubChapters(path.join(sourcedir, '_sources', idxname)) addChapterInfoFromScheduler(scd, ct, rvars['projectname'], db) for root, dirs, files in os.walk(sourcedir): for fn in files: if fn.endswith('.rst'): fh = open(path.join(root, fn), 'r') populateSubchapter(root, fn, fh, sourcedir, rvars['projectname']) # # move the sourcedir/build/projectname folder into static # shutil.rmtree(os.path.join(workingdir, 'static', rvars['projectname']), ignore_errors=True) shutil.move(os.path.join(sourcedir, 'build', rvars['projectname']), os.path.join(workingdir, 'static', rvars['projectname'])) # # clean up # shutil.rmtree(sourcedir) donefile = open(os.path.join(custom_dir, 'done'), 'w') donefile.write('success') donefile.close()
def build(): from paver.tasks import main as paver_main os.chdir(findProjectRoot()) sys.argv[0] = "build" paver_main()
def run_sphinx(rvars=None, folder=None, application=None, http_host=None, base_course=None): # workingdir is the application folder workingdir = folder # sourcedir holds the all sources temporarily sourcedir = path.join(workingdir, 'build', rvars['projectname']) rslogger.debug("Starting to build {}".format(rvars['projectname'])) # create the custom_courses dir if it doesn't already exist if not os.path.exists(path.join(workingdir, 'custom_courses')): os.mkdir(path.join(workingdir, 'custom_courses')) # confdir holds the conf and index files custom_dir = path.join(workingdir, 'custom_courses', rvars['projectname']) if not os.path.exists(custom_dir): os.mkdir(custom_dir) # ## check for base_course if base_course == None ### read conf.py and look for How to Think to determine coursetype if base_course == None: base_course = 'thinkcspy' # copy all the sources into the temporary sourcedir if os.path.exists(sourcedir): shutil.rmtree(sourcedir) shutil.copytree(path.join(workingdir, 'books', base_course), sourcedir) makePavement(http_host, rvars, sourcedir, base_course) shutil.copy(path.join(sourcedir, 'pavement.py'), custom_dir) ######### # We're rebuilding a course ######### if rvars['coursetype'] == 'rebuildcourse': try: # copy the index and conf files to the sourcedir shutil.copy(path.join(custom_dir, 'pavement.py'), path.join(sourcedir, 'pavement.py')) shutil.copy(path.join(custom_dir, 'index.rst'), path.join(sourcedir, '_sources', 'index.rst')) # copy the assignments.rst file from confidir as it may contain assignments written # by the instructor shutil.copy(path.join(custom_dir, 'assignments.rst'), path.join(sourcedir, '_sources', 'assignments.rst')) # this check should allow for backward compatibility if os.path.exists(os.path.join(custom_dir, 'assignments')): shutil.copytree( path.join(custom_dir, 'assignments'), path.join(sourcedir, '_sources', 'assignments')) except OSError: # Either the sourcedir already exists (meaning this is probably devcourse, thinkcspy, etc, # or the conf.py or index.rst files are missing for some reason. raise OSError("missing paver, index, or assignments file") ######## # we're just copying one of the pre-existing books ######## else: # Save copies of files that the instructor may customize shutil.copy(path.join(sourcedir, '_sources', 'index.rst'), custom_dir) shutil.copy(path.join(sourcedir, '_sources', 'assignments.rst'), custom_dir) ########### # Set up and run Paver build ########### from paver.tasks import main as paver_main os.chdir(sourcedir) paver_main(args=["build"]) rslogger.debug("Finished build of {}".format(rvars['projectname'])) try: shutil.copy('build_info', custom_dir) except IOError as copyfail: rslogger.debug("Failed to copy build_info_file") rslogger.debug(copyfail.message) idxname = 'index.rst' # # move the sourcedir/build/projectname folder into static # shutil.rmtree(os.path.join(workingdir, 'static', rvars['projectname']), ignore_errors=True) shutil.move(os.path.join(sourcedir, 'build', rvars['projectname']), os.path.join(workingdir, 'static', rvars['projectname'])) # # clean up # shutil.rmtree(sourcedir) rslogger.debug("Completely done with {}".format(rvars['projectname']))
def run_sphinx(rvars=None, folder=None, application=None, http_host=None, base_course=None): # workingdir is the application folder workingdir = folder # sourcedir holds the all sources temporarily sourcedir = path.join(workingdir, 'build', rvars['projectname']) rslogger.debug("Starting to build {}".format(rvars['projectname'])) # create the custom_courses dir if it doesn't already exist if not os.path.exists(path.join(workingdir, 'custom_courses')): os.mkdir(path.join(workingdir, 'custom_courses')) # confdir holds the conf and index files custom_dir = path.join(workingdir, 'custom_courses', rvars['projectname']) if not os.path.exists(custom_dir): os.mkdir(custom_dir) # ## check for base_course if base_course == None ### read conf.py and look for How to Think to determine coursetype if base_course == None: base_course = 'thinkcspy' # copy all the sources into the temporary sourcedir if os.path.exists(sourcedir): shutil.rmtree(sourcedir) shutil.copytree(path.join(workingdir, 'books', base_course), sourcedir) makePavement(http_host, rvars, sourcedir, base_course) shutil.copy(path.join(sourcedir,'pavement.py'),custom_dir) ######### # We're rebuilding a course ######### if rvars['coursetype'] == 'rebuildcourse': try: # copy the index and conf files to the sourcedir shutil.copy(path.join(custom_dir, 'pavement.py'), path.join(sourcedir, 'pavement.py')) except OSError: # Either the sourcedir already exists (meaning this is probably devcourse, thinkcspy, etc, # or the conf.py or index.rst files are missing for some reason. raise OSError("missing paver, index, or assignments file") ######## # we're just copying one of the pre-existing books ######## # else: # Save copies of files that the instructor may customize # shutil.copy(path.join(sourcedir,'_sources', 'index.rst'),custom_dir) ########### # Set up and run Paver build ########### from paver.tasks import main as paver_main old_cwd = os.getcwd() os.chdir(sourcedir) paver_main(args=["build"]) rslogger.debug("Finished build of {}".format(rvars['projectname'])) try: shutil.copy('build_info',custom_dir) except IOError as copyfail: rslogger.debug("Failed to copy build_info_file") rslogger.debug(copyfail.message) idxname = 'index.rst' # # move the sourcedir/build/projectname folder into static # # todo check if dest is a symlink and remove it instead of calling rmtree if os.path.islink(os.path.join(workingdir,'static',rvars['projectname'])): os.remove(os.path.join(workingdir,'static',rvars['projectname'])) else: shutil.rmtree(os.path.join(workingdir,'static',rvars['projectname']),ignore_errors=True) shutil.move(os.path.join(sourcedir,'build',rvars['projectname']), os.path.join(workingdir,'static',rvars['projectname']) ) # # clean up # # This will remove a directory that's versioned by Git, which marks some of its files as read-only on Windows. This causes rmtree to fail. So, provide a workaround per `SO <https://stackoverflow.com/questions/21261132/shutil-rmtree-to-remove-readonly-files>`_. def del_rw(function, path, excinfo): os.chmod(path, stat.S_IWRITE) if os.path.isdir(path): os.rmdir(path) else: os.remove(path) # Change away from sourcedir, to avoid an error like ``WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'E:\\Runestone\\web2py\\applications\\runestone\\build\\test_book10'``. os.chdir(old_cwd) shutil.rmtree(sourcedir, onerror=del_rw) rslogger.debug("Completely done with {}".format(rvars['projectname']))