Solved: 04_data_external _get_config() failing

Currently, running through the external data notebook when I try _get_config():

#This cell is just to make the config file compatible with current fastai
config = _get_config()
if 'data_archive_path' not in config: config['data_archive_path'] = config['data_path']
config_path = Path(os.getenv('FASTAI_HOME', '~/.fastai')).expanduser()
config_file,config_bak = config_path/'config.yml',config_path/'config.yml.bak'
with open(config_file, 'w') as yaml_file: 
    yaml.dump(config, yaml_file, default_flow_style=False)

Issue:

No such file or directory: '/root/.fastai/config.yml'
# export
def _get_config():
    config_path = Path(os.getenv('FASTAI_HOME', '~/.fastai')).expanduser()
    config_file = config_path/'config.yml'
    if config_file.exists(): 
        with open(config_file, 'r') as yaml_file: 
            config = yaml.safe_load(yaml_file)
            if 'version' in config and config['version'] == 1: return config
    else: config = {} 
    #File inexistent or wrong version -> going to default
    config = {'data_path':    str(config_path/'data'),
              'archive_path': str(config_path/'archive'),
              'model_path':   str(config_path/'models'),
              'version':      1} 
    with open(config_file, 'w') as yaml_file: 
        yaml.dump(config, yaml_file, default_flow_style=False)
    return config

Currently trying to figure out why, Iā€™d think a simple solution such as w+ on the second call to with_open would work but it seems not to

Found the solution. We need to add the following:

if not config_path.exists(): os.mkdir(config_path)

Will submit a PR if that seems alright

Great. Probably config_path.mkdir(parents=True, exist_ok=True) would be better.

2 Likes

Done! Thanks Jeremy :slight_smile: