def on_any_event(self, event): if not isinstance(event, events.DirModifiedEvent): time.sleep(0.05) print 'Rebuilding documentation...', config = load_config(options=self.options) build(config, live_server=True) print ' done'
def test_copying_media(self): docs_dir = tempfile.mkdtemp() site_dir = tempfile.mkdtemp() try: # Create a markdown file, image, dot file and dot directory. open(os.path.join(docs_dir, 'index.md'), 'w').close() open(os.path.join(docs_dir, 'img.jpg'), 'w').close() open(os.path.join(docs_dir, '.hidden'), 'w').close() os.mkdir(os.path.join(docs_dir, '.git')) open(os.path.join(docs_dir, '.git/hidden'), 'w').close() conf = config.validate_config({ 'site_name': 'Example', 'docs_dir': docs_dir, 'site_dir': site_dir }) build.build(conf) # Verify only the markdown (coverted to html) and the image are copied. self.assertTrue(os.path.isfile(os.path.join(site_dir, 'index.html'))) self.assertTrue(os.path.isfile(os.path.join(site_dir, 'img.jpg'))) self.assertFalse(os.path.isfile(os.path.join(site_dir, '.hidden'))) self.assertFalse(os.path.isfile(os.path.join(site_dir, '.git/hidden'))) finally: shutil.rmtree(docs_dir) shutil.rmtree(site_dir)
def run_build(theme_name, output, config_file, quiet): """ Given a theme name and output directory use the configuration for the MkDocs documentation and overwrite the site_dir and theme. If no output is provided, serve the documentation on each theme, one at a time. """ options = { 'theme': theme_name, } if config_file is None: config_file = open(MKDOCS_CONFIG, 'rb') if not quiet: print("Using config: {0}".format(config_file.name)) if not os.path.exists(output): os.makedirs(output) options['site_dir'] = os.path.join(output, theme_name) if not quiet: print("Building {0}".format(theme_name)) try: conf = config.load_config(config_file=config_file, **options) config_file.close() build.build(conf) build.build(conf, dump_json=True) except Exception: print("Error building: {0}".format(theme_name), file=sys.stderr) raise
def build_command(clean, config_file, strict, theme): """Build the MkDocs documentation""" build.build(load_config( config_file=config_file, strict=strict, theme=theme ), clean_site_dir=clean)
def gh_deploy_command(config_file, clean): """Deply your documentation to GitHub Pages""" config = load_config( config_file=config_file ) build.build(config, clean_site_dir=clean) gh_deploy.gh_deploy(config)
def test_copying_media(self): docs_dir = tempfile.mkdtemp() site_dir = tempfile.mkdtemp() try: # Create a markdown file, image, dot file and dot directory. open(os.path.join(docs_dir, 'index.md'), 'w').close() open(os.path.join(docs_dir, 'img.jpg'), 'w').close() open(os.path.join(docs_dir, '.hidden'), 'w').close() os.mkdir(os.path.join(docs_dir, '.git')) open(os.path.join(docs_dir, '.git/hidden'), 'w').close() conf = config.validate_config({ 'site_name': 'Example', 'docs_dir': docs_dir, 'site_dir': site_dir }) build.build(conf) # Verify only the markdown (coverted to html) and the image are copied. self.assertTrue( os.path.isfile(os.path.join(site_dir, 'index.html'))) self.assertTrue(os.path.isfile(os.path.join(site_dir, 'img.jpg'))) self.assertFalse(os.path.isfile(os.path.join(site_dir, '.hidden'))) self.assertFalse( os.path.isfile(os.path.join(site_dir, '.git/hidden'))) finally: shutil.rmtree(docs_dir) shutil.rmtree(site_dir)
def gh_deploy_command(config_file, clean, message, remote_branch): """Deply your documentation to GitHub Pages""" config = load_config( config_file=config_file, remote_branch=remote_branch ) build.build(config, clean_site_dir=clean) gh_deploy.gh_deploy(config, message=message)
def builder(): log.info("Building documentation...") config = load_config( config_file=config_file, dev_addr=dev_addr, strict=strict, theme=theme, ) config['site_dir'] = tempdir build(config, live_server=True) return config
def build_command(clean, config_file, strict, theme, site_dir): """Build the MkDocs documentation""" try: build.build(load_config( config_file=config_file, strict=strict, theme=theme, site_dir=site_dir ), clean_site_dir=clean) except exceptions.ConfigurationError as e: # Avoid ugly, unhelpful traceback raise SystemExit('\n' + str(e))
def gh_deploy_command(config_file, clean, message, remote_branch): """Deply your documentation to GitHub Pages""" try: config = load_config( config_file=config_file, remote_branch=remote_branch ) build.build(config, clean_site_dir=clean) gh_deploy.gh_deploy(config, message=message) except exceptions.ConfigurationError as e: # Avoid ugly, unhelpful traceback raise SystemExit('\n' + str(e))
def json_command(clean, config_file, strict): """Build the MkDocs documentation to JSON files Rather than building your documentation to HTML pages, this outputs each page in a simple JSON format. This command is useful if you want to index your documentation in an external search engine. """ build.build(load_config( config_file=config_file, strict=strict ), dump_json=True, clean_site_dir=clean)
def serve(config, options=None): """ Start the devserver, and rebuild the docs whenever any changes take effect. """ # Create a temporary build directory, and set some options to serve it tempdir = tempfile.mkdtemp() options['site_dir'] = tempdir # Only use user-friendly URLs when running the live server options['use_directory_urls'] = True # Perform the initial build config = load_config(options=options) build(config, live_server=True) # Note: We pass any command-line options through so that we # can re-apply them if the config file is reloaded. event_handler = BuildEventHandler(options) config_event_handler = ConfigEventHandler(options) # We could have used `Observer()`, which can be faster, but # `PollingObserver()` works more universally. observer = PollingObserver() observer.schedule(event_handler, config['docs_dir'], recursive=True) for theme_dir in config['theme_dir']: if not os.path.exists(theme_dir): continue observer.schedule(event_handler, theme_dir, recursive=True) observer.schedule(config_event_handler, '.') observer.start() class TCPServer(socketserver.TCPServer): allow_reuse_address = True class DocsDirectoryHandler(FixedDirectoryHandler): base_dir = config['site_dir'] host, port = config['dev_addr'].split(':', 1) server = TCPServer((host, int(port)), DocsDirectoryHandler) print('Running at: http://%s:%s/' % (host, port)) print('Live reload enabled.') print('Hold ctrl+c to quit.') try: server.serve_forever() except KeyboardInterrupt: print('Stopping server...') # Clean up observer.stop() observer.join() shutil.rmtree(tempdir) print('Quit complete')
def gh_deploy_command(config_file, clean, message, remote_branch, remote_name): """Deploy your documentation to GitHub Pages""" try: config = load_config( config_file=config_file, remote_branch=remote_branch, remote_name=remote_name ) build.build(config, clean_site_dir=clean) gh_deploy.gh_deploy(config, message=message) except exceptions.ConfigurationError as e: # Avoid ugly, unhelpful traceback raise SystemExit('\n' + str(e))
def run_build(theme_name, output=None, config_file=None, quiet=False): """ Given a theme name and output directory use the configuration for the MkDocs documentation and overwrite the site_dir and theme. If no output is provided, serve the documentation on each theme, one at a time. """ should_serve = output is None options = {} if not serve: if not os.path.exists(output): os.makedirs(output) options['site_dir'] = os.path.join(output, theme_name) if config_file is None: config_file = open(MKDOCS_CONFIG, 'rb') if not quiet: print("Using config: {0}".format(config_file)) cli.configure_logging() conf = config.load_config(config_file=config_file, theme=theme_name) if should_serve: if not quiet: print("Serving {0}".format(theme_name)) try: serve.serve(conf) except KeyboardInterrupt: return else: if not quiet: print("Building {0}".format(theme_name)) try: with capture_stdout() as out: build.build(conf) build.build(conf, dump_json=True) except Exception: print("Failed building {0}".format(theme_name), file=sys.stderr) raise if not quiet: print(''.join(out))
def _build(cfg, pathspec, tags, site_dir=None): c = { 'extra': { 'current_version': pathspec, 'all_versions': tags, } } if site_dir is not None: c['site_dir'] = site_dir try: cfg.load_dict(c) build.build(cfg, clean_site_dir=True) except Exception: log.exception("Failed to build '%s'", pathspec)
def json_command(clean, config_file, strict): """Build the MkDocs documentation to JSON files Rather than building your documentation to HTML pages, this outputs each page in a simple JSON format. This command is useful if you want to index your documentation in an external search engine. """ log.warning("The json command is deprcated and will be removed in a future " "MkDocs release. For details on updating: " "http://www.mkdocs.org/about/release-notes/") build.build(load_config( config_file=config_file, strict=strict ), dump_json=True, clean_site_dir=clean)
def main(cmd, args, options=None): """ Build the documentation, and optionally start the devserver. """ if cmd == 'serve': config = load_config(options=options) serve(config, options=options) elif cmd == 'build': config = load_config(options=options) build(config) elif cmd == 'gh-deploy': config = load_config(options=options) build(config) gh_deploy(config) elif cmd == 'new': new(args, options) else: print('mkdocs [help|new|build|serve|gh-deploy] {options}')
def serve(config, options=None): """ Start the devserver, and rebuild the docs whenever any changes take effect. """ # Create a temporary build directory, and set some options to serve it tempdir = tempfile.mkdtemp() options['site_dir'] = tempdir # Only use user-friendly URLs when running the live server options['use_directory_urls'] = True # Perform the initial build config = load_config(options=options) build(config, live_server=True) # Note: We pass any command-line options through so that we # can re-apply them if the config file is reloaded. event_handler = BuildEventHandler(options) config_event_handler = ConfigEventHandler(options) observer = observers.Observer() observer.schedule(event_handler, config['docs_dir'], recursive=True) for theme_dir in config['theme_dir']: observer.schedule(event_handler, theme_dir, recursive=True) observer.schedule(config_event_handler, '.') observer.start() class TCPServer(socketserver.TCPServer): allow_reuse_address = True class DocsDirectoryHandler(FixedDirectoryHandler): base_dir = config['site_dir'] host, port = config['dev_addr'].split(':', 1) server = TCPServer((host, int(port)), DocsDirectoryHandler) print('Running at: http://%s:%s/' % (host, port)) print('Live reload enabled.') print('Hold ctrl+c to quit.') server.serve_forever() # Clean up observer.stop() observer.join() shutil.rmtree(tempdir)
def test_copying_media(self): docs_dir = tempfile.mkdtemp() site_dir = tempfile.mkdtemp() try: # Create a non-empty markdown file, image, dot file and dot directory. f = open(os.path.join(docs_dir, 'index.md'), 'w') f.write( dedent(""" page_title: custom title # Heading 1 This is some text. # Heading 2 And some more text. """)) f.close() open(os.path.join(docs_dir, 'img.jpg'), 'w').close() open(os.path.join(docs_dir, '.hidden'), 'w').close() os.mkdir(os.path.join(docs_dir, '.git')) open(os.path.join(docs_dir, '.git/hidden'), 'w').close() conf = config_base.Config(schema=config_defaults.DEFAULT_SCHEMA) conf.load_dict({ 'site_name': 'Example', 'docs_dir': docs_dir, 'site_dir': site_dir }) conf.validate() build.build(conf) # Verify only the markdown (coverted to html) and the image are copied. self.assertTrue( os.path.isfile(os.path.join(site_dir, 'index.html'))) self.assertTrue(os.path.isfile(os.path.join(site_dir, 'img.jpg'))) self.assertFalse(os.path.isfile(os.path.join(site_dir, '.hidden'))) self.assertFalse( os.path.isfile(os.path.join(site_dir, '.git/hidden'))) finally: shutil.rmtree(docs_dir) shutil.rmtree(site_dir)
def json_command(clean, config_file, strict, site_dir): """Build the MkDocs documentation to JSON files Rather than building your documentation to HTML pages, this outputs each page in a simple JSON format. This command is useful if you want to index your documentation in an external search engine. """ log.warning( "The json command is deprcated and will be removed in a future " "MkDocs release. For details on updating: " "http://www.mkdocs.org/about/release-notes/") build.build(load_config(config_file=config_file, strict=strict, site_dir=site_dir), dump_json=True, clean_site_dir=clean)
def serve(config, options=None): """ Start the devserver, and rebuild the docs whenever any changes take effect. """ # Create a temporary build directory, and set some options to serve it tempdir = tempfile.mkdtemp() options['site_dir'] = tempdir # Only use user-friendly URLs when running the live server options['use_directory_urls'] = True # Perform the initial build config = load_config(options=options) build(config, live_server=True) # Note: We pass any command-line options through so that we # can re-apply them if the config file is reloaded. event_handler = BuildEventHandler(options) config_event_handler = ConfigEventHandler(options) observer = observers.Observer() observer.schedule(event_handler, config['docs_dir'], recursive=True) observer.schedule(event_handler, config['theme_dir'], recursive=True) observer.schedule(config_event_handler, '.') observer.start() class TCPServer(socketserver.TCPServer): allow_reuse_address = True class DocsDirectoryHandler(FixedDirectoryHandler): base_dir = config['site_dir'] host, port = config['dev_addr'].split(':', 1) server = TCPServer((host, int(port)), DocsDirectoryHandler) print('Running at: http://%s:%s/' % (host, port)) print('Live reload enabled.') print('Hold ctrl+c to quit.') server.serve_forever() # Clean up observer.stop() observer.join() shutil.rmtree(tempdir)
def test_copying_media(self): docs_dir = tempfile.mkdtemp() site_dir = tempfile.mkdtemp() try: # Create a non-empty markdown file, image, dot file and dot directory. f = open(os.path.join(docs_dir, 'index.md'), 'w') f.write(dedent(""" page_title: custom title # Heading 1 This is some text. # Heading 2 And some more text. """)) f.close() open(os.path.join(docs_dir, 'img.jpg'), 'w').close() open(os.path.join(docs_dir, '.hidden'), 'w').close() os.mkdir(os.path.join(docs_dir, '.git')) open(os.path.join(docs_dir, '.git/hidden'), 'w').close() conf = config_base.Config(schema=config_defaults.DEFAULT_SCHEMA) conf.load_dict({ 'site_name': 'Example', 'docs_dir': docs_dir, 'site_dir': site_dir }) conf.validate() build.build(conf) # Verify only the markdown (coverted to html) and the image are copied. self.assertTrue(os.path.isfile(os.path.join(site_dir, 'index.html'))) self.assertTrue(os.path.isfile(os.path.join(site_dir, 'img.jpg'))) self.assertFalse(os.path.isfile(os.path.join(site_dir, '.hidden'))) self.assertFalse(os.path.isfile(os.path.join(site_dir, '.git/hidden'))) finally: shutil.rmtree(docs_dir) shutil.rmtree(site_dir)
def main(cmd, args, options=None): """ Build the documentation, and optionally start the devserver. """ clean_site_dir = 'clean' in options if cmd == 'serve': config = load_config(options=options) serve(config, options=options) elif cmd == 'build': config = load_config(options=options) build(config, clean_site_dir=clean_site_dir) elif cmd == 'json': config = load_config(options=options) build(config, dump_json=True, clean_site_dir=clean_site_dir) elif cmd == 'gh-deploy': config = load_config(options=options) build(config, clean_site_dir=clean_site_dir) gh_deploy(config) elif cmd == 'new': new(args, options) else: config = load_config(options=options) event = events.CLI(config, cmd, args, options) event.broadcast() if not event.consumed: std = ['help', 'new', 'build', 'serve', 'gh-deply', 'json'] cmds = '|'.join(std + list(events.CLI.commands)) print('mkdocs [%s] {options}' % cmds)
def json_command(clean, config_file, strict, site_dir): """Build the MkDocs documentation to JSON files Rather than building your documentation to HTML pages, this outputs each page in a simple JSON format. This command is useful if you want to index your documentation in an external search engine. """ log.warning("The json command is deprcated and will be removed in a future " "MkDocs release. For details on updating: " "http://www.mkdocs.org/about/release-notes/") try: build.build(load_config( config_file=config_file, strict=strict, site_dir=site_dir ), dump_json=True, clean_site_dir=clean) except exceptions.ConfigurationError as e: # Avoid ugly, unhelpful traceback raise SystemExit('\n' + str(e))
def json_command(clean, config_file, strict, site_dir): """Build the MkDocs documentation to JSON files Rather than building your documentation to HTML pages, this outputs each page in a simple JSON format. This command is useful if you want to index your documentation in an external search engine. """ log.warning("The json command is deprecated and will be removed in a future " "MkDocs release. For details on updating: " "http://www.mkdocs.org/about/release-notes/") try: build.build(load_config( config_file=config_file, strict=strict, site_dir=site_dir ), dump_json=True, clean_site_dir=clean) except exceptions.ConfigurationError as e: # Avoid ugly, unhelpful traceback raise SystemExit('\n' + str(e))
def test_copying_media(self): docs_dir = tempfile.mkdtemp() site_dir = tempfile.mkdtemp() try: # Create a non-empty markdown file, image, dot file and dot directory. f = open(os.path.join(docs_dir, "index.md"), "w") f.write( dedent( """ page_title: custom title # Heading 1 This is some text. # Heading 2 And some more text. """ ) ) f.close() open(os.path.join(docs_dir, "img.jpg"), "w").close() open(os.path.join(docs_dir, ".hidden"), "w").close() os.mkdir(os.path.join(docs_dir, ".git")) open(os.path.join(docs_dir, ".git/hidden"), "w").close() conf = config.validate_config({"site_name": "Example", "docs_dir": docs_dir, "site_dir": site_dir}) build.build(conf) # Verify only the markdown (coverted to html) and the image are copied. self.assertTrue(os.path.isfile(os.path.join(site_dir, "index.html"))) self.assertTrue(os.path.isfile(os.path.join(site_dir, "img.jpg"))) self.assertFalse(os.path.isfile(os.path.join(site_dir, ".hidden"))) self.assertFalse(os.path.isfile(os.path.join(site_dir, ".git/hidden"))) finally: shutil.rmtree(docs_dir) shutil.rmtree(site_dir)
def serve(config, options=None): """ Start the devserver, and rebuild the docs whenever any changes take effect. """ # Create a temporary build directory, and set some options to serve it tempdir = tempfile.mkdtemp() options["site_dir"] = tempdir # Perform the initial build config = load_config(options=options) build(config) # Note: We pass any command-line options through so that we # can re-apply them if the config file is reloaded. event_handler = BuildEventHandler(options) config_event_handler = ConfigEventHandler(options) observer = observers.Observer() observer.schedule(event_handler, config["docs_dir"], recursive=True) observer.schedule(event_handler, config["theme_dir"], recursive=True) observer.schedule(config_event_handler, ".") observer.start() class TCPServer(SocketServer.TCPServer): allow_reuse_address = True class DocsDirectoryHandler(FixedDirectoryHandler): base_dir = config["site_dir"] host, port = config["dev_addr"].split(":", 1) server = TCPServer((host, int(port)), DocsDirectoryHandler) print "Running at: http://%s:%s/" % (host, port) server.serve_forever() # Clean up observer.stop() observer.join() shutil.rmtree(tempdir)
def main(cmd, args, options=None): """ Build the documentation, and optionally start the devserver. """ if cmd == 'serve': config = load_config(options=options) serve(config, options=options) elif cmd == 'build': config = load_config(options=options) build(config) elif cmd == 'json': config = load_config(options=options) build(config, dump_json=True) elif cmd == 'gh-deploy': config = load_config(options=options) build(config) gh_deploy(config) elif cmd == 'new': new(args, options) else: print('mkdocs [help|new|build|serve|gh-deploy|json] {options}')
def main(cmd, args, options=None): """ Build the documentation, and optionally start the devserver. """ clean_site_dir = 'clean' in options if cmd == 'serve': config = load_config(options=options) serve(config, options=options) elif cmd == 'build': config = load_config(options=options) build(config, clean_site_dir=clean_site_dir) elif cmd == 'json': config = load_config(options=options) build(config, dump_json=True, clean_site_dir=clean_site_dir) elif cmd == 'gh-deploy': config = load_config(options=options) build(config, clean_site_dir=clean_site_dir) gh_deploy(config) elif cmd == 'new': new(args, options) else: print('mkdocs [help|new|build|serve|gh-deploy|json] {options}')
def main(cmd, args, options=None): """ Build the documentation, and optionally start the devserver. """ clean_site_dir = 'clean' in options if cmd == 'serve': config = load_config(options=options) serve(config, options=options) elif cmd == 'build': config = load_config(options=options) build(config, clean_site_dir=clean_site_dir) elif cmd == 'json': config = load_config(options=options) build(config, dump_json=True, clean_site_dir=clean_site_dir) elif cmd == 'gh-deploy': config = load_config(options=options) build(config, clean_site_dir=clean_site_dir) gh_deploy(config) elif cmd == 'new': new(args, options) else: print('MkDocs (version {0})'.format(__version__)) print('mkdocs [help|new|build|serve|gh-deploy|json] {options}')
def on_any_event(self, event): if not isinstance(event, events.DirModifiedEvent): print 'Rebuilding documentation...', config = load_config(options=self.options) build(config) print ' done'
def on_any_event(self, event): if not isinstance(event, events.DirModifiedEvent): print "Rebuilding documentation...", config = load_config(options=self.options) build(config) print " done"
def builder(): build(config, live_server=True)
def on_any_event(self, event): if not isinstance(event, events.DirModifiedEvent): print('Rebuilding documentation...', end='') config = load_config(options=self.options) build(config, live_server=True) print(' done')
def builder(): config = load_config(options=options) build(config, live_server=True)
def gh_deploy_command(config_file, clean, message, remote_branch): """Deply your documentation to GitHub Pages""" config = load_config(config_file=config_file, remote_branch=remote_branch) build.build(config, clean_site_dir=clean) gh_deploy.gh_deploy(config, message=message)