Ejemplo n.º 1
0
def filename_args(args, on_error=_default_on_error):
    """
    Return list of filenames given command-line arguments.

    @rtype:
      C{list} of L{Filename}
    """
    if args:
        return expand_py_files_from_args(args, on_error)
    elif not os.isatty(0):
        return [Filename.STDIN]
    else:
        syntax()
Ejemplo n.º 2
0
def _get_python_path(env_var_name, default_path, target_dirname):
    '''
    Expand an environment variable specifying pyflyby input config files.

      - Default to C{default_path} if the environment variable is undefined.
      - Process colon delimiters.
      - Replace "-" with C{default_path}.
      - Expand triple dots.
      - Recursively traverse directories.

    @rtype:
      C{tuple} of C{Filename}s
    '''
    pathnames = _get_env_var(env_var_name, default_path)
    if pathnames == ["EMPTY"]:
        # The special code PYFLYBY_PATH=EMPTY means we intentionally want to
        # use an empty PYFLYBY_PATH (and don't fall back to the default path,
        # nor warn about an empty path).
        return ()
    for p in pathnames:
        if re.match("/|[.]/|[.][.][.]/|~/", p):
            continue
        raise ValueError(
            "{env_var_name} components should start with / or ./ or ~/ or .../.  "
            "Use {env_var_name}=./{p} instead of {env_var_name}={p} if you really "
            "want to use the current directory.".format(
                env_var_name=env_var_name, p=p))
    pathnames = [os.path.expanduser(p) for p in pathnames]
    pathnames = _expand_tripledots(pathnames, target_dirname)
    pathnames = [Filename(fn) for fn in pathnames]
    pathnames = stable_unique(pathnames)
    pathnames = expand_py_files_from_args(pathnames)
    if not pathnames:
        logger.warning(
            "No import libraries found (%s=%r, default=%r)" %
            (env_var_name, os.environ.get(env_var_name), default_path))
    return tuple(pathnames)