Exemplo n.º 1
0
def command_build_documentation(incontext, options):
    documentation_directory = os.path.abspath(options.output)

    with utils.Chdir(paths.SCRIPTS_DIR):

        # Look up the python files to document.
        files = glob.glob("*.py") + glob.glob("plugins/*.py")
        modules = [os.path.splitext(f)[0] for f in files]

        # Generate the Python documentation.
        for f in files:
            logging.info("Generating documentation for '%s'...", f)
            output_directory = os.path.join(documentation_directory,
                                            os.path.dirname(f))
            utils.makedirs(output_directory)
            result = subprocess.run([
                "pdoc", "--html", "--output-dir", output_directory, "--force",
                f
            ],
                                    capture_output=True)
            logging.debug(result.stdout)
            if result.returncode:
                exit(result.stderr)
            elif result.stderr:
                logging.warning(result.stderr)

        # Create an index page.
        with open(os.path.join(documentation_directory, "index.html"),
                  "w") as fh:
            template = jinja2.Template(INDEX_TEMPLATE)
            fh.write(template.render(modules=modules))
Exemplo n.º 2
0
def command_serve(incontext, options):
    builder_context = commands.build.WatchingBuilder(
        incontext) if options.watch else contextlib.nullcontext()
    with builder_context, utils.Chdir(
            incontext.configuration.site.destination.files_directory):
        httpd = http.server.HTTPServer(('', options.port),
                                       http.server.SimpleHTTPRequestHandler)
        logging.info("Listening on %s...", options.port)
        try:
            httpd.serve_forever()
        except KeyboardInterrupt:
            return
Exemplo n.º 3
0
 def render(self, document):
     with utils.Chdir(
             self.service_directory
     ) as current_directory, self.website.app.test_request_context():
         logging.info("[render] %s", document.url)
         response, query_tracker = self.website.documents(path=document.url)
         hashes = [hash for query, hash in query_tracker.queries.items()]
         _, extension = os.path.splitext(document.template)
         destination_directory = os.path.join(self.files_directory,
                                              document.url[1:])
         destination = os.path.join(destination_directory,
                                    "index" + extension)
         utils.makedirs(destination_directory)
         with open(destination, "wb") as fh:
             fh.write(response.data)
         return destination, query_tracker.queries, hashes
Exemplo n.º 4
0
 def __init__(self, incontext):
     self.incontext = incontext
     self.service_directory = paths.SERVICE_DIR
     self.templates_path = incontext.configuration.site.paths.templates
     self.service_path = os.path.join(self.service_directory, "website.py")
     self.files_directory = incontext.configuration.site.destination.files_directory
     with utils.Chdir(self.service_directory):
         website_spec = importlib.util.spec_from_file_location(
             "website", self.service_path)
         website = importlib.util.module_from_spec(website_spec)
         website_spec.loader.exec_module(website)
         self.website = website
         for name, f in incontext.context_functions.items():
             self.website.app.jinja_env.globals.update(**{name: f})
         self.website.initialize(
             templates_path=self.templates_path,
             store_path=incontext.configuration.site.destination.store_path,
             config=incontext.configuration.site.config)
Exemplo n.º 5
0
def command_documentation(incontext, options):
    documentation_directory = os.path.abspath(options.output)

    with utils.Chdir(paths.INCONTEXT_DIRECTORY):

        # Look up the python files to document.
        files = utils.find(
            paths.INCONTEXT_DIRECTORY,
            extensions=[".py"],
            transform=lambda x: os.path.relpath(x, paths.INCONTEXT_DIRECTORY))
        modules = [os.path.splitext(f)[0] for f in files]

        # Generate the Python documentation.
        for f in files:
            logging.info("Generating documentation for '%s'...", f)
            output_directory = os.path.join(documentation_directory,
                                            os.path.dirname(f))
            utils.makedirs(output_directory)
            environment = dict(os.environ)
            environment["PYTHONPATH"] = paths.PLUGINS_DIR
            result = subprocess.run([
                "pdoc", "--html", "--output-dir", output_directory, "--force",
                f
            ],
                                    capture_output=True,
                                    env=environment)
            logging.debug(result.stdout)
            if result.returncode:
                exit(result.stderr)
            elif result.stderr:
                logging.warning(result.stderr)

        # Create an index page.
        with open(os.path.join(documentation_directory, "index.html"),
                  "w") as fh:
            template = jinja2.Template(INDEX_TEMPLATE)
            fh.write(template.render(modules=modules))
Exemplo n.º 6
0
 def run(self, args):
     with utils.Chdir(self.path):
         run_incontext(args, plugins_directory=paths.PLUGINS_DIR)
Exemplo n.º 7
0
 def inner(*args, **kwargs):
     with tempfile.TemporaryDirectory() as path, utils.Chdir(path):
         return f(*args, **kwargs)
Exemplo n.º 8
0
 def documents(self):
     with utils.Chdir(self.service_directory):
         return self.website.app.jinja_env.site.posts()