Exemple #1
0
def test_profile(profile_name,infile, reference_file):
    loader = PyFileConfigLoader(profile_name+'.nbcv',path=[os.path.join(os.getcwdu(),'profile/')])
    config = loader.load_config()
    C = ConverterTemplate(config=config)
    output,resources = C.from_filename(infile)
    with io.open(reference_file,'r') as f:
        compfiles(output,f.read())
Exemple #2
0
def test_profile(profile_name,infile, reference_file):
    loader = PyFileConfigLoader(profile_name+'.py',path=[os.path.join(os.getcwdu(),'profile/')])
    config = loader.load_config()
    C = ConverterTemplate(config=config)
    output,resources = C.from_filename(infile)
    with io.open(reference_file,'r') as f:
        compfiles(output,f.read())
def check_null_profile(profile):
    loader = PyFileConfigLoader(
        profile, path=[os.path.join(os.getcwdu(), 'profile/test')])
    config = loader.load_config()
    C = ConverterTemplate(config=config)
    result, _ = C.from_filename('tests/ipynbref/IntroNumPy.orig.ipynb')
    nt.assert_equal(result.strip('\n'), '')
Exemple #4
0
    def run(self):
        """Convert a notebook in one step"""
        ipynb_file = (self.extra_args or [None])[2]

        # If you are writting a custom transformer, append it to the dictionary
        # below.
        userpreprocessors = {}

        # Create the converter
        C = ConverterTemplate(config=self.config, preprocessors=userpreprocessors)

        output, resources = C.from_filename(ipynb_file)
        if self.stdout:
            print(output.encode("utf-8"))

        out_root = ipynb_file[:-6].replace(".", "_").replace(" ", "_")

        if self.write:
            with io.open(os.path.join(out_root + "." + self.fileext), "w") as f:
                f.write(output)

        binkeys = resources.get("figures", {}).get("binary", {}).keys()
        textkeys = resources.get("figures", {}).get("text", {}).keys()
        if binkeys or textkeys:
            if self.write:
                files_dir = out_root + "_files"
                if not os.path.exists(out_root + "_files"):
                    os.mkdir(files_dir)
                for key in binkeys:
                    with io.open(os.path.join(files_dir, key), "wb") as f:
                        f.write(resources["figures"]["binary"][key])
                for key in textkeys:
                    with io.open(os.path.join(files_dir, key), "w") as f:
                        f.write(resources["figures"]["text"][key])

            elif self.stdout:
                print("""====================== Keys in Resources ==================================""")
                print(resources["figures"].keys())
                print(
                    """
===========================================================================
you are responsible from writing those data do a file in the right place if
they need to be.
===========================================================================
                  """
                )
Exemple #5
0
    def run(self):
        """Convert a notebook in one step"""
        ipynb_file = (self.extra_args or [None])[2]

        # If you are writting a custom transformer, append it to the dictionary
        # below.
        userpreprocessors = {}

        # Create the converter
        C = ConverterTemplate(config=self.config, preprocessors=userpreprocessors)

        output, resources = C.from_filename(ipynb_file)
        if self.stdout :
            print(output.encode('utf-8'))

        out_root = ipynb_file[:-6].replace('.', '_').replace(' ', '_')

        if self.write :
            files_dir = out_root + '_files'
            file_base = os.path.basename(out_root)
            if not os.path.exists(files_dir):
                os.mkdir(files_dir)
            with io.open(os.path.join(files_dir, file_base + '.' + self.fileext), 'w') as f:
                f.write(output)

        binkeys = resources.get('figures', {}).get('binary', {}).keys()
        textkeys = resources.get('figures', {}).get('text', {}).keys()
        if binkeys or textkeys :
            if self.write:

                for key in binkeys:
                    with io.open(os.path.join(files_dir, key), 'wb') as f:
                        f.write(resources['figures']['binary'][key])
                for key in textkeys:
                    with io.open(os.path.join(files_dir, key), 'w') as f:
                        f.write(resources['figures']['text'][key])

            elif self.stdout:
                print('''====================== Keys in Resources ==================================''')
                print(resources['figures'].keys())
                print("""
===========================================================================
you are responsible from writing those data do a file in the right place if
they need to be.
===========================================================================
                  """)
Exemple #6
0
    def run(self):
        """Convert a notebook in one step"""
        ipynb_file = (self.extra_args or [None])[2]

        # If you are writting a custom transformer, append it to the dictionary
        # below.
        userpreprocessors = {}
        
        # Create the converter
        C = ConverterTemplate(config=self.config, preprocessors=userpreprocessors)

        output, resources = C.from_filename(ipynb_file)
        if self.stdout :
            print(output.encode('utf-8'))

        out_root = ipynb_file[:-6].replace('.', '_').replace(' ', '_')

        if self.write :
            with io.open(os.path.join(out_root+'.'+self.fileext), 'w') as f:
                f.write(output)

        binkeys = resources.get('figures', {}).get('binary',{}).keys()
        textkeys = resources.get('figures', {}).get('text',{}).keys()
        if binkeys or textkeys :
            if self.write:
                files_dir = out_root+'_files'
                if not os.path.exists(out_root+'_files'):
                    os.mkdir(files_dir)
                for key in binkeys:
                    with io.open(os.path.join(files_dir, key), 'wb') as f:
                        f.write(resources['figures']['binary'][key])
                for key in textkeys:
                    with io.open(os.path.join(files_dir, key), 'w') as f:
                        f.write(resources['figures']['text'][key])

            elif self.stdout:
                print('''====================== Keys in Resources ==================================''')
                print(resources['figures'].keys())
                print("""
===========================================================================
you are responsible from writing those data do a file in the right place if
they need to be.
===========================================================================
                  """)
Exemple #7
0
def check_null_profile(profile):
    loader = PyFileConfigLoader(profile, path=[os.path.join(os.getcwdu(),'profile/test')])
    config = loader.load_config()
    C = ConverterTemplate(config=config)
    result,_ = C.from_filename('tests/ipynbref/IntroNumPy.orig.ipynb')
    nt.assert_equal(result.strip('\n'),'')