Ejemplo n.º 1
0
 def test_merge_verbose(self):
     nb = merge_notebooks(FIXTURES_DIR, TARGET_NBS, verbose=True)
     self._validate_merged_three(nb)
     lines = sys.stdout.getvalue().splitlines()
     self.assertEqual(lines[0].strip(), "Merging notebooks...")
     for target, line in zip(TARGET_NBS, lines[1:4]):
         self.assertEqual(line.strip(), "Reading `{}`".format(target))
Ejemplo n.º 2
0
def run_functests(output_dir, lmenv_path):
    # Output directory of executed notebooks
    if not os.path.exists(output_dir):
        os.mkdir(output_dir)

    # Base directory of the functional tests.
    # That is, the directory where this script is located.
    base_path = os.path.dirname(os.path.realpath(__file__))

    # Copy .lmenv file to the functest directory
    copyfile(lmenv_path, os.path.join(base_path, '.lmenv'))

    # Tests
    tests = [
        'example_blank', 'example_quad', 'example_raycast', 'example_pt',
        'example_cpp', 'example_custom_renderer', 'example_serialization',
        'func_render_all', 'func_render_instancing', 'func_accel_consistency',
        'func_error_handling', 'func_obj_loader_consistency',
        'func_serial_consistency', 'func_update_asset', 'func_scheduler',
        'func_materials', 'func_lights', 'func_renderers', 'perf_accel',
        'perf_obj_loader', 'perf_serial'
    ]

    # Execute tests
    for test in tests:
        print(Fore.GREEN + "Running test [name='{}']".format(test) +
              Style.RESET_ALL,
              flush=True)

        # Read the requested notebook
        nb = jupytext.read(os.path.join(base_path, test + '.py'))

        # Execute the notebook
        ep = ExecutePreprocessor(timeout=600)
        ep.preprocess(nb, {'metadata': {'path': base_path}})

        # Write result
        with open(os.path.join(output_dir, test + '.ipynb'),
                  mode='w',
                  encoding='utf-8') as f:
            nbformat.write(nb, f)

    # Merge executed notebooks
    print(Fore.GREEN + "Merging notebooks" + Style.RESET_ALL)
    notebook_paths = [
        os.path.join(output_dir, test + '.ipynb') for test in tests
    ]
    nb = nbmerge.merge_notebooks(os.getcwd(), notebook_paths)
    with open(os.path.join(output_dir, 'merged.ipynb'),
              mode='w',
              encoding='utf-8') as f:
        nbformat.write(nb, f)

    # Notify success
    print(Fore.GREEN + "All tests have been executed successfully" +
          Style.RESET_ALL)
def merge_notebooks_function(path_to_notebooks='.',notebook_paths=['.\\Download_Data_Template.ipynb','.\\DeepBox.ipynb',
                                             '.\\Data_Curation.ipynb','.\\Liver_Model.ipynb'],
                             notebook_output_path=os.path.join('.','Click_Me.ipynb')):
    '''
    :param path_to_notebooks: Base_dir, rather unneeded
    :param notebook_paths: list of full paths to notebooks
    :param notebook_output_path: path to output notebook
    :return:
    '''
    merged = merge_notebooks(base_dir=path_to_notebooks,file_paths=notebook_paths, verbose=True)
    with io.open(notebook_output_path, 'w', encoding='utf8') as fp:
        write_notebook(merged, fp)

    return None
Ejemplo n.º 4
0
#
# All configuration values have a default; values that are commented out
# serve to show the default.

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
import nbmerge

#Merge example Notebooks into one notebook to keep the required structure
new_nb = nbmerge.merge_notebooks(
    './',
    ('./examples.ipynb',
     '../examples/operational_AEP_analysis/operational_AEP_analysis.ipynb',
     '../examples/turbine_analysis/Turbine_Toolkit_Examples.ipynb',
     '../examples/turbine_analysis/EngieTurbineData_Example.ipynb'))
nbmerge.write_notebook(new_nb, './examplesout.ipynb')

sys.path.insert(0, os.path.abspath('..'))

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
Ejemplo n.º 5
0
        print(Fore.GREEN + "Running test [name='{}']".format(test) +
              Style.RESET_ALL,
              flush=True)

        # Read the requested notebook
        nb = jupytext.read(os.path.join(base_path, test + '.py'))

        # Execute the notebook
        ep = ExecutePreprocessor(timeout=600)
        ep.preprocess(nb, {'metadata': {'path': base_path}})

        # Write result
        with open(os.path.join(args.output_dir, test + '.ipynb'),
                  mode='w',
                  encoding='utf-8') as f:
            nbformat.write(nb, f)

    # Merge executed notebooks
    print(Fore.GREEN + "Merging notebooks" + Style.RESET_ALL)
    notebook_paths = [
        os.path.join(args.output_dir, test + '.ipynb') for test in tests
    ]
    nb = nbmerge.merge_notebooks(os.getcwd(), notebook_paths)
    with open(os.path.join(args.output_dir, 'merged.ipynb'),
              mode='w',
              encoding='utf-8') as f:
        nbformat.write(nb, f)

    # Notify success
    print(Fore.GREEN + "All tests have been executed successfully" +
          Style.RESET_ALL)
Ejemplo n.º 6
0
#
import io
import os
import re
import sys

import nbmerge

# Merge example Notebooks into one notebook to keep the required structure
new_nb = nbmerge.merge_notebooks(
    "./",
    (
        "./examples.ipynb",
        "../examples/00_toolkit_examples.ipynb",
        "../examples/01_qc_data.ipynb",
        "../examples/02_plant_aep_analysis.ipynb",
        "../examples/02b_augmented_plant_aep_analysis.ipynb",
        "../examples/03_turbine_ideal_energy.ipynb",
        "../examples/04_electrical_losses.ipynb",
        "../examples/05_eya_gap_analysis.ipynb",
    ),
)
nbmerge.write_notebook(new_nb, "./examplesout.ipynb")

sys.path.insert(0, os.path.abspath(".."))

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
Ejemplo n.º 7
0
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
#import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# Prepare files
import nbmerge 
new_nb = nbmerge.merge_notebooks('./',('../examples.ipynb','../Turbine_Toolkit_Examples.ipynb','../EngieTurbineData_Example.ipynb'))
nbmerge.write_notebook(new_nb,'./out.ipynb')


# -- Project information -----------------------------------------------------

project = 'test_project'
copyright = '2019, sp'
author = 'sp'

# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '1'

Ejemplo n.º 8
0
 def test_merge_with_boundary_key(self):
     nb = merge_notebooks(FIXTURES_DIR, TARGET_NBS, boundary_key='xxx')
     self._validate_merged_three(nb)
     self.assertEqual(nb.cells[0].metadata['xxx'], '1_Intro.ipynb')
     self.assertEqual(nb.cells[2].metadata['xxx'], '2_Middle.ipynb')
     self.assertEqual(nb.cells[4].metadata['xxx'], '3_Conclusion.ipynb')
Ejemplo n.º 9
0
 def test_merge_defaults(self):
     self._validate_merged_three(merge_notebooks(FIXTURES_DIR, TARGET_NBS))
from nbmerge import merge_notebooks, write_notebook
import io, os

base_path = r'K:\Morfeus\BMAnderson\NCC_AAPM\Code'
file_names = ['Download_Data.ipynb','DeepBox.ipynb','Data_Curation.ipynb','Liver_Model.ipynb']
file_paths = [os.path.join(base_path,i) for i in file_names]
merged = merge_notebooks(base_dir=base_path,file_paths=file_paths, verbose=True)
with io.open(os.path.join(base_path,'Click_Me.ipynb'), 'w', encoding='utf8') as fp:
    write_notebook(merged, fp)