Read a file from the directory where setup.py resides
427226
def read(fname):
    '''
    
    '''
    file_path = os.path.join(SETUP_DIRNAME, fname)
    with codecs.open(file_path, encoding='utf-8') as rfh:
        return rfh.read()
42520
def load_experiment(folder, return_path=False):
    '''
    '''
    fullpath = os.path.abspath(folder)
    config = "%s/config.json" %(fullpath)
    if not os.path.exists(config):
        bot.error("config.json could not be found in %s" %(folder))
        config = None
    if return_path is False and config is not None:
        config = read_json(config)
    return config
280762
def try_read(self, config_dir=None, **kwargs):
        
        if isinstance(config_dir, basestring):
            config_dir = (config_dir,)

        for cdir in config_dir:
            try:
                self.read(cdir, **kwargs)
                return cdir

            except IOError as e:
                pass
559445
def _read_from_paths():
    
    home = os.environ.get("HOME", "")
    home_path = os.path.join(home, _SETTINGS_PATH)
    etc_path = os.path.join("/etc", _SETTINGS_PATH)
    env_path = os.environ.get("SETTINGS_PATH", "")

    read_path = None
    if env_path and os.path.exists(env_path):
        read_path = env_path
    elif home and os.path.exists(home_path):
        read_path = home_path
    elif os.path.exists(etc_path):
        read_path = etc_path

    if not read_path:
        return "{}"

    with open(read_path) as f:
        return f.read()
607708
def _load_config(configfile, section=None):
    '''
    '''
    if os.path.exists(configfile):
        config = read_config(configfile)
        if section is not None:
            if section in config:
                return config._sections[section]
            else:
                bot.warning('%s not found in %s' %(section, configfile))
        return config
735870
def read_file(self):
        

        # don't try to parse config file if we don't have one set
        if not self._cfg_path:
            return

        try:
            cfg_fp = open(self._cfg_path, 'r')
            self.readfp(cfg_fp)
        except IOError as exc:
            raise NipapConfigError(str(exc))
103859
def read_file(rel_path, paths=None, raw=False, as_list=False, as_iter=False,
              *args, **kwargs):
    '''
        
    '''
    if not rel_path:
        raise ValueError("rel_path can not be null!")
    paths = str2list(paths)
    # try looking the file up in a directory called static relative
    # to SRC_DIR, eg assuming metrique git repo is in ~/metrique
    # we'd look in ~/metrique/static
    paths.extend([STATIC_DIR, os.path.join(SRC_DIR, 'static')])
    paths = [os.path.expanduser(p) for p in set(paths)]
    for path in paths:
        path = os.path.join(path, rel_path)
        logger.debug("trying to read: %s " % path)
        if os.path.exists(path):
            break
    else:
        raise IOError("path %s does not exist!" % rel_path)
    args = args if args else ['rU']
    fd = open(path, *args, **kwargs)
    if raw:
        return fd

    if as_iter:
        return read_in_chunks(fd)
    else:
        fd_lines = fd.readlines()

    if as_list:
        return fd_lines
    else:
        return ''.join(fd_lines)
220459
def read(self, config_dir=None, clear=False, config_file=None):
        

        if config_file:
            data_file = os.path.basename(config_file)
            data_path = os.path.dirname(config_file)

            if clear:
                self.clear()

            config = munge.load_datafile(data_file, data_path, default=None)

            if not config:
                raise IOError("Config file not found: %s" % config_file)

            munge.util.recursive_update(self.data, config)
            self._meta_config_dir = data_path
            return
        else:
            return super(Config, self).read(config_dir=config_dir, clear=clear)
375201
def _read(self, directory, filename, session, path, name, extension,
              spatial=None, spatialReferenceID=None, replaceParamFile=None):
        
        yml_events = []
        with open(path) as fo:
            yml_events = yaml.load(fo)

        for yml_event in yml_events:
            if os.path.exists(os.path.join(directory, yml_event.subfolder)):
                orm_event = yml_event.as_orm()
                if not self._similar_event_exists(orm_event.subfolder):
                    session.add(orm_event)
                    self.events.append(orm_event)

        session.commit()
1354457
def read(cls, origin, relpath, **kwargs):
        
        path = origin / relpath
        with path.open('rb') as f:
            return cls.from_file(f, origin, relpath, **kwargs)
1171552
function setup() {

    // check if config directory is given
    if( _config_path !== -1 ) {

      // get path
      var config_path = path.resolve( process.argv[ _config_path + 1 ] );

      // check if directory exists and is a valid directory
      fs.stat( config_path, function( err, stats ) {
        if( err && err.code === "ENOENT" ) {
          process.stdout.write( "The given directory doesn't exists.\n".red );
        } else if( err ) {

          // unknown error
          process.stdout.write( (err.message + "\n").red );
        } else if( !stats.isDirectory() ) {
          process.stdout.write( "The given config directory is not an actual directory.\n".red );
        } else {
          readConfigDir( config_path );
        }
      } );
      return;
    }

    // ask for config directory
    ask( "Where are your config files? ", function( c_path ) {
        readConfigDir( c_path );
    } );
}
91949
def load(self, patterns, dirs, ignore=None):
        
        for dir_ in dirs:
            dir_root = dir_
            if os.path.exists(os.path.join(dir_, "__init__.py")):
                dir_root = os.path.abspath(os.path.join(dir_, os.pardir))

            for path in self.find_files(patterns=patterns, dirs=[dir_], ignore=ignore):
                data = self.read_file(path=path)
                if data:
                    data["relative_path"] = os.path.relpath(path, dir_root)
                    self.paths[path] = data
1063336
def read_env(path=None, environ=None, recurse=True):
    
    environ = environ if environ is not None else os.environ

    # By default, start search from the same file this function is called
    if path is None:
        frame = inspect.currentframe().f_back
        caller_dir = os.path.dirname(frame.f_code.co_filename)
        path = os.path.join(os.path.abspath(caller_dir), ENV)
    if recurse:
        current = path
        pardir = os.path.abspath(os.path.join(current, os.pardir))
        while current != pardir:
            target = os.path.join(current, ENV)
            if os.path.exists(target):
                path = os.path.abspath(target)
                break
            else:
                current = os.path.abspath(os.path.join(current, os.pardir))
                pardir = os.path.abspath(os.path.join(current, os.pardir))
        if not path:
            raise FileNotFoundError('Could not find a .env file')

    with open(path, 'r') as fp:
        content = fp.read()
    parsed = parse_env(content)
    for key, value in parsed.items():
        environ.setdefault(key, value)
166520
def is_installable_dir(path):
    """"""
    if not os.path.isdir(path):
        return False
    setup_py = os.path.join(path, "setup.py")
    if os.path.isfile(setup_py):
        return True
    return False
627196
def read_config(conf_dir=DEFAULT_CONFIG_DIR):
    ""

    conf_path = os.path.expanduser(conf_dir)
    if not os.path.exists(conf_path):
        # only throw if not default
        if conf_dir != DEFAULT_CONFIG_DIR:
            raise IOError("Config directory not found at %s" % (conf_path, ))

    return munge.load_datafile('config', conf_path, default=None)
796247
def check_path():
    """"""
    dirname = osp.abspath(osp.join(osp.dirname(__file__), osp.pardir))
    if dirname not in sys.path:
        show_warning("Spyder must be installed properly "
                     "(e.g. from source: 'python setup.py install'),\n"
                     "or directory '%s' must be in PYTHONPATH "
                     "environment variable." % dirname)
1012427
def parse_setup(filepath):
    ''''''
    # TODO: Need to parse setup.cfg and merge with the data from below

    # Monkey patch setuptools.setup to capture keyword arguments
    setup_kwargs = {}

    def setup_interceptor(**kwargs):
        setup_kwargs.update(kwargs)

    import setuptools
    setuptools_setup = setuptools.setup
    setuptools.setup = setup_interceptor

    # Manually compile setup.py
    with open(filepath, 'r') as f:
        code = compile(f.read(), '', 'exec')
    setup = ModuleType('setup')
    exec(code, setup.__dict__)

    # Remove monkey patch
    setuptools.setup = setuptools_setup
    return setup_kwargs