How to use the portray.api function in portray

To help you get started, we’ve selected a few portray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github timothycrosley / portray / tests / test_api.py View on Github external
def test_as_html(temporary_dir, project_dir, chdir):
    with chdir(temporary_dir):
        # Directory with no project
        with pytest.raises(exceptions.NoProjectFound):
            api.as_html()

        # Rendering should succeed as soon as a project is within the directory
        temp_project_dir = os.path.join(temporary_dir, "portray")
        shutil.copytree(project_dir, temp_project_dir)
        with chdir(temp_project_dir):
            api.as_html()

            # Rendering a second time should fail
            with pytest.raises(exceptions.DocumentationAlreadyExists):
                api.as_html()

            # Unless we enable overwritting destination
            api.as_html(overwrite=True)

            # Or, we output to a different location
            with tempfile.TemporaryDirectory() as new_temp_directory:
github timothycrosley / portray / tests / test_api.py View on Github external
def test_as_html(temporary_dir, project_dir, chdir):
    with chdir(temporary_dir):
        # Directory with no project
        with pytest.raises(exceptions.NoProjectFound):
            api.as_html()

        # Rendering should succeed as soon as a project is within the directory
        temp_project_dir = os.path.join(temporary_dir, "portray")
        shutil.copytree(project_dir, temp_project_dir)
        with chdir(temp_project_dir):
            api.as_html()

            # Rendering a second time should fail
            with pytest.raises(exceptions.DocumentationAlreadyExists):
                api.as_html()

            # Unless we enable overwritting destination
            api.as_html(overwrite=True)

            # Or, we output to a different location
            with tempfile.TemporaryDirectory() as new_temp_directory:
                api.as_html(output_dir=os.path.join(new_temp_directory, "site"))
github timothycrosley / portray / portray / cli.py View on Github external
it should maintain 1:1 compatibility with the programmatic API definition in the
[API module](/reference/portray/api)

- `portray as_html`: Renders the project as HTML into the `site` or other specified output directory
- `portray in_browser`: Runs a server with the rendered documentation pointing a browser to it
- `portray server`: Starts a local development server (by default at localhost:8000)
- `portray project_configuration`: Returns back the project configuration as determined by` portray`
"""
from pprint import pprint

import hug

from portray import api, logo

cli = hug.cli(api=hug.API(__name__, doc=logo.ascii_art))
cli(api.as_html)
cli.output(pprint)(api.project_configuration)
cli(api.server)
cli(api.in_browser)
cli(api.on_github_pages)