예제 #1
0
def setup(app):
    jmt.init(jm, globals())

    app.add_config_value('recommonmark_config', {
        'auto_toc_tree_section': 'Contents',
        'enable_eval_rst': True
    }, True)
    app.add_transform(AutoStructify)
    for folder in jm.get_exercise_folders():
        jm.zip_folder(folder)
    jm.zip_folders('exams/*/solutions', lambda x: '%s-%s-exam' %
                   (jm.filename, x.split('/')[-2]))

    # Build Project
    def remap(x):
        if x == 'requirements.txt':
            return 'NAME-SURNAME-ID/requirements.txt'
        elif x.startswith('project/'):
            return 'NAME-SURNAME-ID/%s' % x[len('project/'):]
        else:
            return x

    jm.zip_paths(['project', 'requirements.txt'],
                 '_static/generated/project-template',
                 remap=remap)
예제 #2
0
def test_preprocessor_force():
    jm = make_jm()
    jmt.init(jm)
    
    
    nb_fn = '_test/test-chapter/force-preprocess.ipynb'
    
    resources = make_nb_resources(nb_fn)

    d = '_build/test/.doctrees/nbsphinx/'
    if not os.path.isdir(d):
        os.makedirs(d)

    exp = nbsphinx.Exporter()

    nb_orig = nbformat.read(nb_fn, nbformat.NO_CONVERT)
    
    assert 'stripped!' in nb_orig.cells[2].source
    assert 'purged!' in nb_orig.cells[3].source
    
    nb_new, new_res = exp.from_notebook_node(nb_orig, resources)
        
    stripped_count = 0
    for cell in nb_orig.cells: 
        if 'stripped!' in cell.source:
            stripped_count += 1                    
        assert '#jupman-strip' not in cell.source 
        assert '#jupman-preprocess' not in cell.source
        assert 'purged!' not in cell.source        
    
    assert stripped_count == 1
예제 #3
0
def test_preprocessor_normal():
    jm = make_jm()
    jmt.init(jm)
    
    nb_fn = '_test/test-chapter/replacements.ipynb'
    
    resources = make_nb_resources(nb_fn)

    d = '_build/test/.doctrees/nbsphinx/'
    if not os.path.isdir(d):
        os.makedirs(d)

    exp = nbsphinx.Exporter()

    nb_orig = nbformat.read(nb_fn, nbformat.NO_CONVERT)
    
    assert 'stay!' in nb_orig.cells[10].source    
    
    nb_new, new_res = exp.from_notebook_node(nb_orig, resources)
    
    assert 'stay!' in nb_orig.cells[10].source            
예제 #4
0
def setup(app):
    jmt.init(jm)

    # temporary hack to have graph-drawing stuff
    jmt.info('Copying soft.py ...')
    import shutil
    shutil.copy('soft.py', 'graph-formats/')
    shutil.copy('soft.py', 'binary-relations/')
    shutil.copy('soft.py', 'visualization/')

    if 'googleanalytics_id' in globals() and globals()['googleanalytics_id']:
        print("Found googleanalytics_id")
        import googleanalytics
        googleanalytics.setup(app)
    else:
        print('No valid googleanalytics_id was found, skipping it')

    app.add_config_value('recommonmark_config', {
        'auto_toc_tree_section': 'Contents',
        'enable_eval_rst': True
    }, True)
    app.add_transform(AutoStructify)
    for folder in jm.get_exercise_folders():
        jm.zip_folder(folder)
    #jm.zip_folders('exams/*/solutions',
    #                lambda x:  '%s-%s-exam' % (jm.filename, x.split('/')[-2]))
    #jm.zip_folders('challenges/*/', renamer = lambda x: '%s-challenge' % x.split('/')[1])
    #jm.zip_paths(['project'], '_static/generated/project-template')

    def sub(x):
        if x == 'requirements.txt':
            return 'NAME-SURNAME-ID/requirements.txt'
        elif x.startswith('project/'):
            return 'NAME-SURNAME-ID/%s' % x[len('project/'):]
        else:
            return x

    """
예제 #5
0
def test_preprocessor_sol():
    jm = make_jm()
    jmt.init(jm)
    
    
    nb_fn = '_test/test-chapter/nb-sol.ipynb'
    
    resources = make_nb_resources(nb_fn)

    d = '_build/test/.doctrees/nbsphinx/'
    if not os.path.isdir(d):
        os.makedirs(d)

    exp = nbsphinx.Exporter()

    nb_orig = nbformat.read(nb_fn, nbformat.NO_CONVERT)
    
    purged_count = 0
    stripped_count = 0
    for cell in nb_orig.cells:        
        
        if 'stripped!8' in cell.source:
            stripped_count += 1
        if 'purged!9' in cell.source:
            purged_count += 1
                
    assert purged_count == 1    
    assert stripped_count == 1
    
        
    nb_new, new_res = exp.from_notebook_node(nb_orig, resources)
        
    stripped_count = 0
    for cell in nb_orig.cells: 
        if 'stripped!8' in cell.source:
            stripped_count += 1        
            assert not 'purged!9' in cell.source
    assert stripped_count == 1