コード例 #1
0
def create_nb_proj(project: str = 'project',
                   description: str = 'notebook project',
                   relative_to: str = '.',
                   sub_folders: bool = True):
    ''' Create notebook project.

    This function uses the default configuration file ('config.json') to
    create a default jupyter project folder.

    Examples
    --------

    .. code-block::
        create_nb_proj('eoin_dev')

    Parameters:
    -----------
    project
        project folder name.
    description
        project description.
    relative_to
        relative path to current folder (default '.')


    Returns:
    --------
    None
    '''
    project_path = Path(relative_to).absolute().parent / project

    # Check whether project folder exists
    if project_path.exists():
        raise FileExistsError(f'project: {project_path} already exists!')

    # create project directory
    try:
        project_path.mkdir(parents=True, exist_ok=False)
    except FileExistsError as e:
        logger.info(e)

    # Copy package default config.json and adjust as needed.
    config_file = 'config.json'
    config = get_config(config_file, info=False)

    config['project'] = description
    config['meta']['project'] = description
    logger.debug(config)

    # Write to the project default folder
    new_config = project_path / config_file

    with open(new_config, "w") as f:
        json.dump(config, f)

    if sub_folders:
        create_nb_folders(project=project,
                          relative_to=relative_to)

    logger.info(f'{project} folder created.')
コード例 #2
0
ファイル: odbc.py プロジェクト: miketarpey/piper
def connections(file_name=None, return_type='dataframe'):
    ''' get all available defined database environments

    Parameters
    ----------
    file_name
        json formatted connections file (similar to tnsnames.ora)
        if None (default) uses ../src/config.json
    return type
        return object type: 'dataframe'(default) 'dictionary'

    Returns
    -------
    dictionary or dataframe

    Examples
    --------

    .. code-block::

        df = connections(return_type='dataframe')
        dict_config = connections(return_type='dictionary')

    '''
    if file_name == None:
        default_config = get_config('config.json')
        file_name = default_config['connections']['location']

    config = get_config(file_name, info=False)
    logger.debug(config)

    if return_type == 'dictionary':
        return config

    if return_type == 'dataframe':
        df = (pd.DataFrame(config).T).fillna('')

        if 'pw' in df.columns:
            df = df.drop(columns=['pw'])

        lowercase_cols = ['schema', 'sid', 'user']
        for col in lowercase_cols:
            if col in df.columns:
                df[col] = df[col].str.lower()

    return df
コード例 #3
0
    def get_styles(self, file_name=None):
        ''' Retrieve dictionary of styles allowing easy access to styles by name. '''

        if file_name is None:
            config = get_config('config.json')
        else:
            config = get_config(file_name)

        styles_dict = get_config(config['excel']['formats'])

        base_fmt = {'font_name': 'Calibri', 'font_size': 11}

        def set_format(v):
            v.update(deepcopy(base_fmt))
            return self.wb.add_format(v)

        styles = {k: set_format(v) for k, v in styles_dict.items()}
        default = {'sheet_default': set_format(base_fmt)}
        styles = {**styles, **default}

        return styles
コード例 #4
0
    def get_metadata(self, meta_file=None):
        ''' Get XL metadata

        Parameters
        ----------
        meta_file
            If None defaults to 'config.json'

        Returns
        -------
            Dictionary of xl meta information.


        '''

        if meta_file is None:
            config = get_config('config.json', info=False)
        else:
            xl_meta = get_config(meta_file, info=False)

        xl_meta = get_config(config['excel']['meta'], info=False)

        return xl_meta
コード例 #5
0
ファイル: test_utils.py プロジェクト: miketarpey/piper
def test_get_config_valid_with_info(get_complete_config):

    file_name = 'piper/temp/test_config.json'

    # Convert dictionary to json format, write to test temp config file
    json_data = json.dumps(get_complete_config)
    with open(file_name, 'w') as f:
        f.write(json_data)

    # Read the data back and load to dict object
    with open(file_name, 'r') as f:
        expected = json.load(f)

    actual = get_config(file_name, info=True)

    assert expected == actual
コード例 #6
0
ファイル: test_utils.py プロジェクト: miketarpey/piper
def test_get_config_file_name_invalid_returns_NONE():

    assert get_config(file_name='invalid', info=False) is None