(cls, base_dir='.')
return config
Returns a Config instance using a base directory.
Returns a Config instance using a base directory.
Returns a Config instance using a base directory .
def from_base_dir(cls, base_dir='.'):
        """ Returns a Config instance using a base directory. """
        base_dir_path = Path(os.path.abspath(base_dir))
        candidate_paths = [base_dir_path, ] + list(base_dir_path.parents)
        existing_config_paths = []
        for candidate_path in candidate_paths:
            existing_config_paths = [
                os.path.join(str(candidate_path), filename)
                for filename in constants.ALLOWED_FILENAMES
                if os.path.exists(os.path.join(str(candidate_path), filename))]
            if existing_config_paths:
                break

        if not existing_config_paths:
            raise ConfigFileNotFoundError(
                'Unable to find a suitable configuration file in this directory. '
                'Are you in the right directory?\n'
                'The supported filenames are: {}'.format(', '.join(constants.ALLOWED_FILENAMES))
            )

        config_dirname, config_filename = os.path.split(existing_config_paths[0])
        if len(existing_config_paths) > 1:
            logger.warning('Multiple config files were found: {0}'.format(
                ', '.join([os.path.split(p)[1] for p in existing_config_paths])))
            logger.warning('Using: {0}'.format(config_filename))

        # Initializes the config instance.
        config = cls(config_dirname, config_filename)

        # Loads the YML.
        config.load()

        # Validates the content of the configuration. We chdir into the home directory of the
        # project in order to ensure that IsFile/IsDir validators keep working properly if the
        # config is initialized from a subfolder of the project.
        cwd = os.getcwd()
        os.chdir(config.homedir)

        # Performs variable substitution / interpolation in the configuration values.
        config.interpolate()

        try:
            config._dict = schema(config._dict)
        except Invalid as e:
            # Formats the voluptuous error
            path = ' @ %s' % '.'.join(map(str, e.path)) if e.path else ''
            msg = 'The LXDock file is invalid because: {0}'.format(e.msg + path)
            raise ConfigFileValidationError(msg)
        finally:
            os.chdir(cwd)

        config.extract_config_from_dict()

        return config
def from_base_dir ( cls , base_dir = '.' ) : base_dir_path = Path ( os . path . abspath ( base_dir ) ) candidate_paths = [ base_dir_path , ] + list ( base_dir_path . parents ) existing_config_paths = [ ] for candidate_path in candidate_paths : existing_config_paths = [ os . path . join ( str ( candidate_path ) , filename ) for filename in constants . ALLOWED_FILENAMES if os . path . exists ( os . path . join ( str ( candidate_path ) , filename ) ) ] if existing_config_paths : break if not existing_config_paths : raise ConfigFileNotFoundError ( 'Unable to find a suitable configuration file in this directory. ' 'Are you in the right directory?\n' 'The supported filenames are: {}' . format ( ', ' . join ( constants . ALLOWED_FILENAMES ) ) ) config_dirname , config_filename = os . path . split ( existing_config_paths [ 0 ] ) if len ( existing_config_paths ) > 1 : logger . warning ( 'Multiple config files were found: {0}' . format ( ', ' . join ( [ os . path . split ( p ) [ 1 ] for p in existing_config_paths ] ) ) ) logger . warning ( 'Using: {0}' . format ( config_filename ) ) # Initializes the config instance. config = cls ( config_dirname , config_filename ) # Loads the YML. config . load ( ) # Validates the content of the configuration. We chdir into the home directory of the # project in order to ensure that IsFile/IsDir validators keep working properly if the # config is initialized from a subfolder of the project. cwd = os . getcwd ( ) os . chdir ( config . homedir ) # Performs variable substitution / interpolation in the configuration values. config . interpolate ( ) try : config . _dict = schema ( config . _dict ) except Invalid as e : # Formats the voluptuous error path = ' @ %s' % '.' . join ( map ( str , e . path ) ) if e . path else '' msg = 'The LXDock file is invalid because: {0}' . format ( e . msg + path ) raise ConfigFileValidationError ( msg ) finally : os . chdir ( cwd ) config . extract_config_from_dict ( ) return config