Ejemplo n.º 1
0
def tests(ctx, nose=True):
    """
    Runs the unit tests with *Nose* or *Pytest*.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.
    nose : bool, optional
        Whether to use *Nose* or *Pytest*.

    Returns
    -------
    bool
        Task success.
    """

    if nose:
        message_box('Running "Nosetests"...')
        ctx.run(f'nosetests --with-doctest --with-coverage '
                f'--cover-package={PYTHON_PACKAGE_NAME} {PYTHON_PACKAGE_NAME}')
    else:
        message_box('Running "Pytest"...')
        ctx.run(f'py.test --disable-warnings --doctest-modules '
                f'{PYTHON_PACKAGE_NAME}')
Ejemplo n.º 2
0
def clean(ctx, docs=True, bytecode=False):
    """
    Cleans the project.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.
    docs : bool, optional
        Whether to clean the *docs* directory.
    bytecode : bool, optional
        Whether to clean the bytecode files, e.g. *.pyc* files.

    Returns
    -------
    bool
        Task success.
    """
    message_box('Cleaning project...')

    patterns = ['build', '*.egg-info', 'dist']

    if docs:
        patterns.append('docs/_build')
        patterns.append('docs/generated')

    if bytecode:
        patterns.append('**/*.pyc')

    for pattern in patterns:
        ctx.run(f'rm -rf {pattern}')
Ejemplo n.º 3
0
def docker_remove(ctx):
    """
    Stops and remove the *docker* container.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.

    Returns
    -------
    bool
        Task success.
    """

    message_box('Stopping "docker" container...')
    try:
        ctx.run(f'docker stop {CONTAINER}')
    except Failure:
        pass

    message_box('Removing "docker" container...')
    try:
        ctx.run(f'docker rm {CONTAINER}')
    except Failure:
        pass
Ejemplo n.º 4
0
def print_aces_taxonomy():
    """
    Prints *aces-dev* taxonomy:

    -   The *aces-dev* *CTL* transforms are discovered by traversing the
        directory defined by the :attr:`opencolorio_config_aces.config.\
reference.ACES_CTL_TRANSFORMS_ROOT` attribute using the
        :func:`opencolorio_config_aces.discover_aces_ctl_transforms`
        definition.
    -   The *CTL* transforms are classified by *family* e.g.
        *output_transform*, and *genus* e.g. *dcdm* using the
        :func:`opencolorio_config_aces.classify_aces_ctl_transforms`
        definition.
    -   The resulting datastructure is printed.
    """

    classified_ctl_transforms = classify_aces_ctl_transforms(
        discover_aces_ctl_transforms())

    for family, genera in classified_ctl_transforms.items():
        message_box(family, print_callable=logging.info)
        for genus, ctl_transforms in genera.items():
            logging.info(f'[ {genus} ]')
            for name, ctl_transform in ctl_transforms.items():
                logging.info(f'\t( {name} )')
                if isinstance(ctl_transform, CTLTransform):
                    logging.info(f'\t\t"{ctl_transform.source}"'
                                 f' --> '
                                 f'"{ctl_transform.target}"')
                elif isinstance(ctl_transform, CTLTransformPair):
                    logging.info(
                        f'\t\t"{ctl_transform.forward_transform.source}"'
                        f' <--> '
                        f'"{ctl_transform.forward_transform.target}"')
Ejemplo n.º 5
0
def preflight(ctx):
    """
    Performs the preflight tasks, i.e. *formatting* and *quality*.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.

    Returns
    -------
    bool
        Task success.
    """

    message_box('Finishing "Preflight"...')
Ejemplo n.º 6
0
def requirements(ctx):
    """
    Exports the *requirements.txt* file.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.

    Returns
    -------
    bool
        Task success.
    """

    message_box('Exporting "requirements.txt" file...')
    ctx.run('poetry run pip freeze > requirements.txt')
Ejemplo n.º 7
0
def docker_build(ctx):
    """
    Builds the *docker* image.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.

    Returns
    -------
    bool
        Task success.
    """

    message_box('Building "docker" image...')
    ctx.run(f'docker build -t {ORG}/{CONTAINER}:latest '
            f'-t {ORG}/{CONTAINER}:v{APPLICATION_VERSION} .')
Ejemplo n.º 8
0
def build_reference_config(ctx):
    """
    Builds the *aces-dev* reference *OpenColorIO* Config.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.

    Returns
    -------
    bool
        Task success.
    """

    message_box(f'Building the "aces-dev" reference *OpenColorIO* config...')
    with ctx.cd('opencolorio_config_aces/config/reference/generate'):
        ctx.run('python config.py')
def requirements(ctx):
    """
    Exports the *requirements.txt* file.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.

    Returns
    -------
    bool
        Task success.
    """

    message_box('Exporting "requirements.txt" file...')
    ctx.run('poetry run pip list --format=freeze | '
            'egrep -v "opencolorio-config-aces" '
            '> requirements.txt')
Ejemplo n.º 10
0
def run_in_container(ctx, command):
    """
    Runs given command in *docker* container.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.
    command : unicode
        Command to run in the *docker* container.

    Returns
    -------
    bool
        Task success.
    """

    message_box(f'Running "docker" container with "{command}" command...')
    ctx.run(f'docker run -v ${{PWD}}:/home/{ORG}/{GITHUB_REPOSITORY_NAME} '
            f'{ORG}/{CONTAINER}:latest {command}')
Ejemplo n.º 11
0
def quality(ctx, flake8=True):
    """
    Checks the codebase with *Flake8*.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.
    flake8 : bool, optional
        Whether to check the codebase with *Flake8*.

    Returns
    -------
    bool
        Task success.
    """

    if flake8:
        message_box('Checking codebase with "Flake8"...')
        ctx.run('flake8 opencolorio_config_aces --exclude=aces-dev')
Ejemplo n.º 12
0
def formatting(ctx, yapf=True):
    """
    Formats the codebase with *Yapf*.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.
    yapf : bool, optional
        Whether to format the codebase with *Yapf*.

    Returns
    -------
    bool
        Task success.
    """

    if yapf:
        message_box('Formatting codebase with "Yapf"...')
        ctx.run(
            'yapf -p -i -r '
            '--exclude \'.git\' '
            '--exclude \'opencolorio_config_aces/config/reference/aces-dev\' .'
        )
Ejemplo n.º 13
0
def docs(ctx, html=True, pdf=True):
    """
    Builds the documentation.

    Parameters
    ----------
    ctx : invoke.context.Context
        Context.
    html : bool, optional
        Whether to build the *HTML* documentation.
    pdf : bool, optional
        Whether to build the *PDF* documentation.

    Returns
    -------
    bool
        Task success.
    """

    with ctx.cd('.'):
        message_box('Updating "index.rst" file...')
        readme_file_path = os.path.join(ctx.cwd, 'README.rst')
        with open(readme_file_path, 'r') as readme_file:
            readme_file_content = readme_file.read()

        readme_file_content = readme_file_content.replace(
            '.. {MANUAL-URL}', """
.. toctree::
    :maxdepth: 3

    manual
"""[1:-1])

        index_file_path = os.path.join(ctx.cwd, 'docs', 'index.rst')
        with open(index_file_path, 'w') as index_file:
            index_file.write(readme_file_content)

    with ctx.cd('docs'):
        if html:
            message_box('Building "HTML" documentation...')
            ctx.run('make html')

        if pdf:
            message_box('Building "PDF" documentation...')
            ctx.run('make latexpdf')
Ejemplo n.º 14
0
    build_directory = os.path.join(opencolorio_config_aces.__path__[0], '..',
                                   'build')

    if not os.path.exists(build_directory):
        os.makedirs(build_directory)

    filename = os.path.join(build_directory, 'aces_conversion_graph.png')

    ctl_transforms = discover_aces_ctl_transforms()
    classified_ctl_transforms = classify_aces_ctl_transforms(ctl_transforms)
    filtered_ctl_transforms = filter_ctl_transforms(classified_ctl_transforms)

    graph = build_aces_conversion_graph(filtered_ctl_transforms)
    print(graph.nodes)

    message_box('Retrieving a "CTL" Transform from a Node')
    print(node_to_ctl_transform(graph, 'ODT/P3D60_48nits'))

    message_box('Retrieving a Node from a "CTL" Transform')
    print(
        ctl_transform_to_node(graph,
                              node_to_ctl_transform(graph,
                                                    'ODT/P3D60_48nits')))

    message_box('Filtering "output_transform" Family')
    pprint(
        filter_nodes(
            graph,
            [lambda x: True if x.family == 'output_transform' else False]))

    message_box('Filtering "p3" Genus')