Python os.path.expandvars() Examples

The following are code examples for showing how to use os.path.expandvars(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: rm-protection   Author: alanzchen   File: protect.py    MIT License 6 votes vote down vote up
def protect(protect_args=None):
    global c
    flags = ''
    option_end = False
    if not protect_args:
        protect_args = argv[1:]
    for arg in protect_args:
        if arg == '--':
            option_end = True
        elif (arg.startswith("-") and not option_end):
            flags = flags + arg[arg.rfind('-') + 1:]
        elif arg in c.invalid:
            pprint('"." and ".." may not be protected')
        else:
            path = abspath(expv(expu(arg)))
            evalpath = dirname(path) + "/." + basename(path) + c.suffix
            if not exists(path):
                pprint("Warning: " + path + " does not exist")
            with open(evalpath, "w") as f:
                question = input("Question for " + path + ": ")
                answer = input("Answer: ")
                f.write(question + "\n" + answer + "\n" + flags.upper()) 
Example 2
Project: bigcode-tools   Author: danhper   File: parallel_tokenizer.py    MIT License 6 votes vote down vote up
def tokenize_files(files_pattern: str, output: str, options: dict = None) -> None:
    if options is None:
        options = {}

    files_pattern = path.expandvars(path.expanduser(files_pattern))
    files = glob(files_pattern, recursive=True)
    total_count = len(files)
    logging.info("starting to tokenize %s files", total_count)

    queue = Queue(100) # type: Queue[QueueItem]

    write_results_process = Process(target=write_results, args=(queue, output, total_count))
    write_results_process.start()

    pool = Pool(None, process_file_init, [queue, options])
    pool.map(process_file, files)
    pool.close()
    pool.join()
    logging.debug("pool done, waiting for write results process")
    queue.put(None)
    write_results_process.join()
    logging.info("successfully processed %s files", queue.get()) 
Example 3
Project: pl2mind   Author: MRN-Code   File: test_rbm_smri.py    GNU General Public License v2.0 6 votes vote down vote up
def test_data():
    pylearn2_out_path = path.expandvars("$PYLEARN2_OUTS")
    assert pylearn2_out_path != "", ("PYLEARN2_OUTS environment variable is "
                                     "not set.")

    pylearn2_data_path = path.expandvars("$PYLEARN2_NI_PATH")
    assert pylearn2_data_path != "", ("PYLEARN2_NI_PATH environment"
                                      " variable is not set")

    data_path = serial.preprocess("${PYLEARN2_NI_PATH}/smri/")
    extras_path = serial.preprocess("${PYLEARN2_NI_PATH}/mri_extra/")

    try:
        assert path.isdir(data_path), data_path
        assert path.isdir(extras_path), extras_path
    except AssertionError as e:
        raise IOError("File or directory not found (%s), did you set your "
                      "PYLEARN2_NI_PATH correctly? (%s)" % (e, data_path)) 
Example 4
Project: pl2mind   Author: MRN-Code   File: test_rbm_mnist.py    GNU General Public License v2.0 6 votes vote down vote up
def test_data():
    pylearn2_data_path = path.expandvars("$PYLEARN2_DATA_PATH")
    assert pylearn2_data_path != "", ("PYLEARN2_DATA_PATH environment"
                                      " variable is not set")

    data_path = serial.preprocess("${PYLEARN2_DATA_PATH}/mnist/")
    try:
        assert path.isdir(data_path), data_path
        assert path.isfile(path.join(data_path, "t10k-images-idx3-ubyte")),\
            "t10k-images-idx3-ubyte"
        assert path.isfile(path.join(data_path, "t10k-labels-idx1-ubyte")),\
            "t10k-labels-idx1-ubyte"
        assert path.isfile(path.join(data_path, "train-images-idx3-ubyte")),\
            "train-images-idx3-ubyte"
        assert path.isfile(path.join(data_path, "train-labels-idx1-ubyte")),\
            "train-labels-idx1-ubyte"
    except AssertionError as e:
        raise IOError("File or directory not found (%s), did you set "
                      "PYLEARN2_DATA_PATH correctly? (%s)" % (e, data_path)) 
Example 5
Project: piu   Author: piranha   File: fstore.py    ISC License 6 votes vote down vote up
def __init__(self, base, create=False):
        self.base = op.expandvars(op.expanduser(base))
        if not op.exists(self.base):
            if create:
                os.mkdir(self.base)
            else:
                raise ValueError('%s does not exist' % base)

        if not op.isdir(self.base):
            raise ValueError('%s is not a directory' % base)

        try:
            self.index = tnetstring.loads(self.open('index.gz').read())
        except IOError:
            self.index = {}

    # API methods 
Example 6
Project: webrecorder   Author: webrecorder   File: session.py    Apache License 2.0 6 votes vote down vote up
def __init__(self, app, cork, redis, session_opts, access_cls=None, access_redis=None):
        super(RedisSessionMiddleware, self).__init__(app, session_opts['session.key'])
        self.redis = redis
        self.access_redis = access_redis
        self.cork = cork

        self.auto_login_user = os.environ.get('AUTO_LOGIN_USER')

        self.secret_key = expandvars(session_opts['session.secret'])

        self.key_template = session_opts['session.key_template']
        self.long_sessions_key = session_opts['session.long_sessions_key']

        self.durations = session_opts['session.durations']

        self.access_cls = access_cls 
Example 7
Project: ubelt   Author: Erotemic   File: util_path.py    Apache License 2.0 6 votes vote down vote up
def expandpath(path):
    """
    Shell-like environment variable and tilde path expansion.

    Less aggressive than truepath. Only expands environs and tilde. Does not
    change relative paths to absolute paths.

    Args:
        path (str | PathLike): string representation of a path

    Returns:
        str : expanded path

    Example:
        >>> import ubelt as ub
        >>> assert normpath(ub.expandpath('~/foo')) == join(ub.userhome(), 'foo')
        >>> assert ub.expandpath('foo') == 'foo'
    """
    path = expanduser(path)
    path = expandvars(path)
    return path 
Example 8
Project: isofit   Author: isofit   File: common.py    Apache License 2.0 6 votes vote down vote up
def recursive_reincode(j, shell_replace=True):
    if isinstance(j, dict):
        for key, value in j.items():
            j[key] = recursive_reincode(value)
        return j
    elif isinstance(j, list):
        for i, k in enumerate(j):
            j[i] = recursive_reincode(k)
        return j
    elif isinstance(j, tuple):
        return tuple([recursive_reincode(k) for k in j])
    else:
        if shell_replace and isinstance(j, str):
            try:
                j = expandvars(j)
            except IndexError:
                pass
        return j 
Example 9
Project: EasyClangComplete   Author: niosus   File: file.py    MIT License 6 votes vote down vote up
def expand_all(input_path,
                   wildcard_values={},
                   current_folder='',
                   expand_globbing=True):
        """Expand everything in this path.

        This returns a list of canonical paths.
        """
        expanded_path = path.expandvars(input_path)
        expanded_path = sublime.expand_variables(
            expanded_path, wildcard_values)
        expanded_path = File.canonical_path(expanded_path, current_folder)
        if not expanded_path:
            return []
        if expand_globbing:
            from glob import glob
            all_paths = glob(expanded_path)
        else:
            all_paths = [expanded_path]
        if len(all_paths) > 0 and all_paths[0] != input_path:
            log.debug("Populated '%s' to '%s'", input_path, all_paths)
            return all_paths
        elif expanded_path != input_path:
            log.debug("Populated '%s' to '%s'", input_path, expanded_path)
        return [expanded_path] 
Example 10
Project: go-avro-convert   Author: aerokite   File: release.py    MIT License 5 votes vote down vote up
def call(cmd, stdin=None, cwd=libbuild.REPO_ROOT, eoe=True):
    print(cwd + ' $ ' + cmd)
    status = subprocess.call([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd)
    if eoe:
        die(status)
    else:
        return status 
Example 11
Project: go-avro-convert   Author: aerokite   File: release.py    MIT License 5 votes vote down vote up
def check_output(cmd, stdin=None, cwd=libbuild.REPO_ROOT):
    print(cwd + ' $ ' + cmd)
    return subprocess.check_output([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd) 
Example 12
Project: go-avro-convert   Author: aerokite   File: make.py    MIT License 5 votes vote down vote up
def call(cmd, stdin=None, cwd=libbuild.REPO_ROOT):
    print(cmd)
    return subprocess.call([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd) 
Example 13
Project: go-avro-convert   Author: aerokite   File: make.py    MIT License 5 votes vote down vote up
def check_output(cmd, stdin=None, cwd=libbuild.REPO_ROOT):
    print(cmd)
    return subprocess.check_output([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd) 
Example 14
Project: mx   Author: graalvm   File: mx.py    GNU General Public License v2.0 5 votes vote down vote up
def expandvars_in_property(value):
    result = expandvars(value)
    if '$' in result or '%' in result:
        abort('Property contains an undefined environment variable: ' + value)
    return result


### ~~~~~~~~~~~~~ commands

# Builtin commands 
Example 15
Project: smaslennikov.github.io   Author: smaslennikov   File: grep.py    MIT License 5 votes vote down vote up
def get_file_by_pattern(pattern, all=False):
    """Returns the first log whose path matches 'pattern',
    if all is True returns all logs that matches."""
    if not pattern: return []
    #debug('get_file_by_filename: searching for %s.' %pattern)
    # do envvar expandsion and check file
    file = path.expanduser(pattern)
    file = path.expandvars(file)
    if path.isfile(file):
        return [file]
    # lets see if there's a matching log
    global home_dir
    file = path.join(home_dir, pattern)
    if path.isfile(file):
        return [file]
    else:
        from fnmatch import fnmatch
        file = []
        file_list = dir_list(home_dir)
        n = len(home_dir)
        for log in file_list:
            basename = log[n:]
            if fnmatch(basename, pattern):
                file.append(log)
        #debug('get_file_by_filename: got %s.' %file)
        if not all and file:
            file.sort()
            return [ file[-1] ]
        return file 
Example 16
Project: smaslennikov.github.io   Author: smaslennikov   File: grep.py    MIT License 5 votes vote down vote up
def get_file_by_pattern(pattern, all=False):
    """Returns the first log whose path matches 'pattern',
    if all is True returns all logs that matches."""
    if not pattern: return []
    #debug('get_file_by_filename: searching for %s.' %pattern)
    # do envvar expandsion and check file
    file = path.expanduser(pattern)
    file = path.expandvars(file)
    if path.isfile(file):
        return [file]
    # lets see if there's a matching log
    global home_dir
    file = path.join(home_dir, pattern)
    if path.isfile(file):
        return [file]
    else:
        from fnmatch import fnmatch
        file = []
        file_list = dir_list(home_dir)
        n = len(home_dir)
        for log in file_list:
            basename = log[n:]
            if fnmatch(basename, pattern):
                file.append(log)
        #debug('get_file_by_filename: got %s.' %file)
        if not all and file:
            file.sort()
            return [ file[-1] ]
        return file 
Example 17
Project: hello-grpc   Author: appscode   File: make.py    Apache License 2.0 5 votes vote down vote up
def call(cmd, stdin=None, cwd=libbuild.REPO_ROOT):
    print(cmd)
    return subprocess.call([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd) 
Example 18
Project: hello-grpc   Author: appscode   File: libbuild.py    Apache License 2.0 5 votes vote down vote up
def call(cmd, stdin=None, cwd=None):
    print(cmd)
    return subprocess.call([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd) 
Example 19
Project: hello-grpc   Author: appscode   File: libbuild.py    Apache License 2.0 5 votes vote down vote up
def check_output(cmd, stdin=None, cwd=None):
    print(cmd)
    return subprocess.check_output([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd) 
Example 20
Project: hello-grpc   Author: appscode   File: schema.py    Apache License 2.0 5 votes vote down vote up
def call(cmd, stdin=None, cwd=REPO_ROOT):
    print(cmd)
    subprocess.call([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd) 
Example 21
Project: python-netsurv   Author: sofia-netsurv   File: pathlib.py    MIT License 5 votes vote down vote up
def resolve_from_str(input, root):
    assert not isinstance(input, Path), "would break on py2"
    root = Path(root)
    input = expanduser(input)
    input = expandvars(input)
    if isabs(input):
        return Path(input)
    else:
        return root.joinpath(input) 
Example 22
Project: python-netsurv   Author: sofia-netsurv   File: pathlib.py    MIT License 5 votes vote down vote up
def resolve_from_str(input, root):
    assert not isinstance(input, Path), "would break on py2"
    root = Path(root)
    input = expanduser(input)
    input = expandvars(input)
    if isabs(input):
        return Path(input)
    else:
        return root.joinpath(input) 
Example 23
Project: dotfiles   Author: butlerx   File: grep.py    MIT License 5 votes vote down vote up
def get_file_by_pattern(pattern, all=False):
    """Returns the first log whose path matches 'pattern',
    if all is True returns all logs that matches."""
    if not pattern: return []
    #debug('get_file_by_filename: searching for %s.' %pattern)
    # do envvar expandsion and check file
    file = path.expanduser(pattern)
    file = path.expandvars(file)
    if path.isfile(file):
        return [file]
    # lets see if there's a matching log
    global home_dir
    file = path.join(home_dir, pattern)
    if path.isfile(file):
        return [file]
    else:
        from fnmatch import fnmatch
        file = []
        file_list = dir_list(home_dir)
        n = len(home_dir)
        for log in file_list:
            basename = log[n:]
            if fnmatch(basename, pattern):
                file.append(log)
        #debug('get_file_by_filename: got %s.' %file)
        if not all and file:
            file.sort()
            return [ file[-1] ]
        return file 
Example 24
Project: dotfiles   Author: butlerx   File: grep.py    MIT License 5 votes vote down vote up
def get_file_by_pattern(pattern, all=False):
    """Returns the first log whose path matches 'pattern',
    if all is True returns all logs that matches."""
    if not pattern: return []
    #debug('get_file_by_filename: searching for %s.' %pattern)
    # do envvar expandsion and check file
    file = path.expanduser(pattern)
    file = path.expandvars(file)
    if path.isfile(file):
        return [file]
    # lets see if there's a matching log
    global home_dir
    file = path.join(home_dir, pattern)
    if path.isfile(file):
        return [file]
    else:
        from fnmatch import fnmatch
        file = []
        file_list = dir_list(home_dir)
        n = len(home_dir)
        for log in file_list:
            basename = log[n:]
            if fnmatch(basename, pattern):
                file.append(log)
        #debug('get_file_by_filename: got %s.' %file)
        if not all and file:
            file.sort()
            return [ file[-1] ]
        return file 
Example 25
Project: 2019-1-OSS-L1   Author: 19-1-skku-oss   File: pathlib.py    MIT License 5 votes vote down vote up
def resolve_from_str(input, root):
    assert not isinstance(input, Path), "would break on py2"
    root = Path(root)
    input = expanduser(input)
    input = expandvars(input)
    if isabs(input):
        return Path(input)
    else:
        return root.joinpath(input) 
Example 26
Project: pisa   Author: IceCubeOpenSource   File: config_parser.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, fp, fpname, fpath=None):
        self._iter_stack = []
        """Stack for storing dicts with 'fp', 'fpname', 'fpath', 'lineno', and
        'line' for keeping track of the hierarchy of master config & included
        configs"""

        # It's ok to not find the fpname / fpname to not be a file for the
        # *master* config, since this could e.g. be a io.StringIO file-like
        # object (`read_string`) which comes from no actual file/resource on
        # disk.
        if not fpname and hasattr(fp, 'name'):
            fpname = fp.name

        if fpath is None:
            try:
                resource = find_resource(fpname)
            except IOError:
                pass
            else:
                if isfile(resource):
                    fpath = abspath(expanduser(expandvars(fpname)))

        if fpath is None:
            try:
                resource = find_resource(fpname)
            except IOError:
                pass
            else:
                if isfile(resource):
                    fpath = resource

        if fpath is None:
            self.fpaths_processed = []
        else:
            self.fpaths_processed = [fpath]

        self.fps_processed = [fp]

        record = dict(fp=fp, fpname=fpname, fpath=fpath, lineno=0, line='')
        self._iter_stack.append(record)
        self.file_hierarchy = OrderedDict([(fpname, OrderedDict())]) 
Example 27
Project: pl2mind   Author: MRN-Code   File: train_nice_smri_transposed.py    GNU General Public License v2.0 5 votes vote down vote up
def train_nice():
    vn = True
    center = True
    smri = MRI.MRI_Transposed(dataset_name="smri",
                              even_input=True)
    input_dim = smri.X.shape[1]

    p = path.abspath(path.dirname(__file__))
    yaml_file = path.join(p, "nice_smri_transposed.yaml")
    user = path.expandvars("$USER")
    save_path = serial.preprocess("/export/mialab/users/%s/pylearn2_outs/" % user)
    assert path.isdir(save_path)
    train(yaml_file, save_path, input_dim) 
Example 28
Project: pl2mind   Author: MRN-Code   File: train_nice_smri.py    GNU General Public License v2.0 5 votes vote down vote up
def train_nice(args):
    vn = True
    center = True
    if args.transposed:
        fmri = MRI.MRI_Transposed(dataset_name=args.dataset_name,
                                  even_input=True)
        input_dim = fmri.X.shape[1]
        del fmri
    else:
        data_path = serial.preprocess("${PYLEARN2_NI_PATH}/" + args.dataset_name)
        mask_file = path.join(data_path, "mask.npy")
        mask = np.load(mask_file)
        input_dim = (mask == 1).sum()
        if input_dim % 2 == 1:
            input_dim -= 1

    logging.info("Input shape: %d" % input_dim)

    p = path.abspath(path.dirname(__file__))
    yaml_file = path.join(p, "nice_%s.yaml" % args.dataset_name)
    user = path.expandvars("$USER")
    save_file = "nice_%s%s%s" % (args.dataset_name,
                                 "_transposed" if args.transposed else "",
                                 "_logistic" if args.logistic else "")
    save_path = serial.preprocess("/export/mialab/users/%s/pylearn2_outs/%s"
                                  % (user, save_file))
    variance_map_file = path.join(data_path, "variance_map.npy")
    if not path.isfile(variance_map_file):
        raise ValueError("Variance map file %s not found."
                         % variance_map_file)
    train(yaml_file, save_path, input_dim,
          args.transposed, args.logistic, variance_map_file) 
Example 29
Project: pl2mind   Author: MRN-Code   File: simple_train.py    GNU General Public License v2.0 5 votes vote down vote up
def main(args):
    logger.info("Getting dataset info for %s" % args.dataset_name)
    data_path = serial.preprocess("${PYLEARN2_NI_PATH}/" + args.dataset_name)
    mask_file = path.join(data_path, "mask.npy")
    mask = np.load(mask_file)
    input_dim = (mask == 1).sum()
    if input_dim % 2 == 1:
        input_dim -= 1
    mri = MRI.MRI_Standard(which_set="full",
                           dataset_name=args.dataset_name,
                           unit_normalize=True,
                           even_input=True,
                           apply_mask=True)
    variance_map_file = path.join(data_path, "variance_map.npy")
    mri_nifti.save_variance_map(mri, variance_map_file)

    user = path.expandvars("$USER")
    save_path = serial.preprocess("/export/mialab/users/%s/pylearn2_outs/%s"
                                  % (user, "nice_jobman_test"))

    file_params = {"save_path": save_path,
                   "variance_map_file": variance_map_file
                   }

    yaml_template = open(yaml_file).read()
    hyperparams = expand(flatten(nice_experiment.default_hyperparams(input_dim=input_dim)),
                         dict_type=ydict)

    for param in file_params:
        yaml_template = yaml_template.replace("%%(%s)s" % param, file_params[param])

    yaml = yaml_template % hyperparams

    logger.info("Training")
    train = yaml_parse.load(yaml)
    train.main_loop() 
Example 30
Project: pl2mind   Author: MRN-Code   File: simple_train.py    GNU General Public License v2.0 5 votes vote down vote up
def main(args):
    dataset_name = args.dataset_name

    logger.info("Getting dataset info for %s" % dataset_name)
    data_path = serial.preprocess("${PYLEARN2_NI_PATH}/" + dataset_name)
    mask_file = path.join(data_path, "mask.npy")
    mask = np.load(mask_file)
    input_dim = (mask == 1).sum()

    user = path.expandvars("$USER")
    save_path = serial.preprocess("/export/mialab/users/%s/pylearn2_outs/%s"
                                  % (user, "rbm_simple_test"))

    # File parameters are path specific ones (not model specific).
    file_params = {"save_path": save_path,
                   }

    yaml_template = open(yaml_file).read()
    hyperparams = expand(flatten(experiment.default_hyperparams(input_dim=input_dim)),
                         dict_type=ydict)

    # Set additional hyperparams from command line args
    if args.learning_rate is not None:
        hyperparams["learning_rate"] = args.learning_rate
    if args.batch_size is not None:
        hyperparams["batch_size"] = args.batch_size

    for param in file_params:
        yaml_template = yaml_template.replace("%%(%s)s" % param, file_params[param])

    yaml = yaml_template % hyperparams

    logger.info("Training")
    train = yaml_parse.load(yaml)
    train.main_loop() 
Example 31
Project: mechanic   Author: server-mechanic   File: config.py    GNU General Public License v3.0 5 votes vote down vote up
def __expand(self, path):
    path = path.replace("${MECHANIC_ROOT_DIR}", self.mechanicRootDir)
    path = expanduser(path)
    path = expandvars(path)
    return path 
Example 32
Project: pytest   Author: pytest-dev   File: pathlib.py    MIT License 5 votes vote down vote up
def resolve_from_str(input, root):
    assert not isinstance(input, Path), "would break on py2"
    root = Path(root)
    input = expanduser(input)
    input = expandvars(input)
    if isabs(input):
        return Path(input)
    else:
        return root.joinpath(input) 
Example 33
Project: webrecorder   Author: webrecorder   File: usermanager.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, redis, cork, config):
        self.redis = redis
        self.cork = cork
        self.config = config

        self.default_coll = config['default_coll']

        self.temp_prefix = config['temp_prefix']

        mailing_list = os.environ.get('MAILING_LIST', '').lower()
        self.mailing_list = mailing_list in ('true', '1', 'yes')
        self.default_list_endpoint = os.environ.get('MAILING_LIST_ENDPOINT', '')
        self.list_key = os.environ.get('MAILING_LIST_KEY', '')
        self.list_removal_endpoint = os.path.expandvars(
                                        os.environ.get('MAILING_LIST_REMOVAL', ''))
        self.payload = os.environ.get('MAILING_LIST_PAYLOAD', '')
        self.remove_on_delete = (os.environ.get('REMOVE_ON_DELETE', '')
                                 in ('true', '1', 'yes'))

        self.announce_list = os.environ.get('ANNOUNCE_MAILING_LIST_ENDPOINT', False)
        invites = expandvars(config.get('invites_enabled', 'true')).lower()
        self.invites_enabled = invites in ('true', '1', 'yes')

        try:
            self.redis.hsetnx('h:defaults', 'max_size', int(config['default_max_size']))
            self.redis.hsetnx('h:defaults', 'max_anon_size', int(config['default_max_anon_size']))
        except Exception as e:
            print('WARNING: Unable to init defaults: ' + str(e))

        self.all_users = UserTable(self.redis, self._get_access)

        self.invites = RedisTable(self.redis, 'h:invites') 
Example 34
Project: panflute   Author: sergiocorreia   File: autofilter.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_filter_dirs(hardcoded=True):
    """
    Return directories where we expect to find filters.

    If hardcoded=True use paths we know ex ante; if False ask Pandoc for a list
    """
    if hardcoded:
        if os.name == 'nt':
            d1 = [p.join(os.environ["APPDATA"], "pandoc", "filters")]
            return d1
        else:
            d1 = p.join(os.environ["HOME"], ".pandoc", "filters")
            d2 = p.join(os.environ["HOME"], ".local", "share", "pandoc", "filters")
            return [d1, d2]
    else:
        from .tools import run_pandoc
        
        # Extract $DATADIR
        info = run_pandoc(args=['--version']).splitlines()
        prefix = "Default user data directory: "
        info = [row for row in info if row.startswith(prefix)]
        assert len(info) == 1
        data_dir = info[0][len(prefix):]

        # data_dir might contain multiple folders:
        # Default user data directory: /home/runner/.local/share/pandoc or /home/runner/.pandoc/filters
        data_dir = data_dir.split(' or ')
        data_dir = [p.normpath(p.expanduser(p.expandvars(p.join(d, 'filters')))) for d in data_dir]
        return data_dir 
Example 35
Project: ncm2-pyclang   Author: ncm2   File: ncm2_pyclang.py    MIT License 5 votes vote down vote up
def args_from_clang_complete(filepath, cwd, args_file_path):
    filedir = dirname(filepath)

    clang_complete, directory = find_config([filedir, cwd], args_file_path)

    if not clang_complete:
        return None, None

    try:
        with open(clang_complete, "r") as f:
            cmd = shlex.split(" ".join(f.readlines()))

            cmd = [expanduser(expandvars(p)) for p in cmd]

            args = pick_useful_args_from_cmd(filepath, cmd)

            logger.info('.clang_complete args: [%s] cmd[%s]', args, cmd)
            return args, directory
    except Exception as ex:
        logger.exception('read config file %s failed.', clang_complete)

    return None, None

# linux kernel build init/main.o -> init/.main.o.cmd:
#
#   cmd_init/main.o := /usr/bin/ccache aarch64-linux-gnu-gcc -Wp,-MD,init/.main.o.d  -nostdinc -isystem /usr/lib/gcc-cross/aarch64-linux-gnu/7/include -I./arch/arm64/include -I./arch/arm64/include/generated  -I./include -I./arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -mlittle-endian -DKASAN_SHADOW_SCALE_SHIFT=3 -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Wno-format-security -std=gnu89 -mgeneral-regs-only -DCONFIG_AS_LSE=1 -fno-asynchronous-unwind-tables -mabi=lp64 -DKASAN_SHADOW_SCALE_SHIFT=3 -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-int-in-bool-context -Os -Wno-maybe-uninitialized --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-unused-but-set-variable -Wno-unused-const-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -g -pg -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -fno-function-sections -fno-data-sections    -DKBUILD_BASENAME='"main"' -DKBUILD_MODNAME='"main"' -c -o init/main.o init/main.c 
Example 36
Project: ubelt   Author: Erotemic   File: _util_deprecated.py    Apache License 2.0 5 votes vote down vote up
def truepath(path, real=False):
    """
    Normalizes a string representation of a path and does shell-like expansion.

    Args:
        path (str | PathLike): string representation of a path
        real (bool): if True, all symbolic links are followed. (default: False)

    Returns:
        str : normalized path

    Note:
        This function is similar to the composition of expanduser, expandvars,
        normpath, and (realpath if `real` else abspath). However, on windows
        backslashes are then replaced with forward slashes to offer a
        consistent unix-like experience across platforms.

        On windows expanduser will expand environment variables formatted as
        %name%, whereas on unix, this will not occur.

    Example:
        >>> from os.path import join
        >>> import ubelt as ub
        >>> assert ub.truepath('~/foo') == join(ub.userhome(), 'foo')
        >>> assert ub.truepath('~/foo') == ub.truepath('~/foo/bar/..')
        >>> assert ub.truepath('~/foo', real=True) == ub.truepath('~/foo')
    """
    path = expanduser(path)
    path = expandvars(path)
    if real:
        path = realpath(path)
    else:
        path = abspath(path)
    path = normpath(path)
    return path 
Example 37
Project: travis2docker   Author: Vauxoo   File: cli.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def yml_read(yml_path):
    yml_path_expanded = expandvars(expanduser(yml_path))
    if isdir(yml_path_expanded):
        yml_path_expanded = join(yml_path_expanded, '.travis.yml')
    if not isfile(yml_path_expanded):
        return
    with open(yml_path_expanded, "r") as f_yml:
        return f_yml.read() 
Example 38
Project: Deribit_funding_rate_indicator   Author: Dimasik007   File: examples_report.py    MIT License 5 votes vote down vote up
def __init__(self, config, report_path, diff_ref, examples):
        self.config = config
        report_path = expanduser(expandvars(report_path))
        self.report_path = abspath(report_path)
        self.examples = { e.path: e for e in examples }
        self.diff = diff_ref
        self.entries = []
        self.errors = self.failed = 0
        self.passed = self.skipped = 0
        self.xfailed = self.xpassed = 0 
Example 39
Project: mail2alert   Author: magnus-lycka   File: config.py    MIT License 5 votes vote down vote up
def expand_vars(structure):
    for key, value in structure.items():
        if isinstance(value, str):
            structure[key] = expandvars(value)
        elif isinstance(value, dict):
            expand_vars(value)
        elif isinstance(value, list):
            expand_list(value) 
Example 40
Project: mail2alert   Author: magnus-lycka   File: config.py    MIT License 5 votes vote down vote up
def expand_list(structure):
    for i, item in enumerate(structure):
        if isinstance(item, str):
            structure[i] = expandvars(item)
        elif isinstance(item, dict):
            expand_vars(item)
        elif isinstance(item, list):
            expand_list(item) 
Example 41
Project: pyCGNS   Author: pyCGNS   File: moption.py    GNU Lesser General Public License v2.1 5 votes vote down vote up
def _trpath(cls, path):
        return op.normpath(op.expanduser(op.expandvars(path))) 
Example 42
Project: PyFlow   Author: wonderworks-software   File: PathLib.py    Apache License 2.0 5 votes vote down vote up
def expandvars(path=("StringPin", "", {PinSpecifires.INPUT_WIDGET_VARIANT: "PathWidget"})):
        '''Return the argument with environment variables expanded. Substrings of the form $name or ${name} are replaced by the value of environment variable name. Malformed variable names and references to non-existing variables are left unchanged.
        On Windows, %name% expansions are supported in addition to $name and ${name}.'''
        return osPath.expandvars(path) 
Example 43
Project: pysh   Author: kkliebersbach   File: lexer.py    Apache License 2.0 5 votes vote down vote up
def t_VAR(t):
    r"\$\w+"
    t.value = expandvars(t.value)
    return t 
Example 44
Project: QSoME   Author: Goodpaster   File: run_embedding.py    Apache License 2.0 5 votes vote down vote up
def main():

    IntroText()

    run_args = arguments()
    file_path = abspath(expandvars(expanduser(run_args.inp_file)))
    nproc = run_args.ppn
    pmem = run_args.pmem
    scr_dir = run_args.scr_dir

    in_obj = inp_reader.InpReader(file_path)
    subsystems = []
    for i in range(len(in_obj.subsys_mols)):
        mol = in_obj.subsys_mols[i]
        env_method = in_obj.env_subsystem_kwargs[i].pop('env_method')
        env_kwargs = in_obj.env_subsystem_kwargs[i]
        if not "nproc" in env_kwargs.keys():
            env_kwargs['nproc'] = nproc
        if not "pmem" in env_kwargs.keys():
            env_kwargs['pmem'] = pmem
        if not "scr_dir" in env_kwargs.keys():
            env_kwargs['scrdir'] = scr_dir
        if in_obj.hl_subsystem_kwargs[i] is not None:
            hl_method = in_obj.hl_subsystem_kwargs[i].pop('hl_method')
            hl_kwargs = in_obj.hl_subsystem_kwargs[i]
            hl_kwargs.update(env_kwargs)
            subsys = cluster_subsystem.ClusterHLSubSystem(mol, env_method, hl_method,  **hl_kwargs)
        else:
            subsys = cluster_subsystem.ClusterEnvSubSystem(mol, env_method, **env_kwargs)

        subsystems.append(subsys)

    int_med = interaction_mediator.InteractionMediator(subsystems, supersystem_kwargs=in_obj.supersystem_kwargs, filename=in_obj.inp.filename)
    int_med.do_embedding()
    total_energy = int_med.get_emb_energy()

    return total_energy 
Example 45
Project: EDMarketConnector   Author: Marginal   File: prefs.py    GNU General Public License v2.0 5 votes vote down vote up
def displaypath(self, pathvar, entryfield):
        entryfield['state'] = tk.NORMAL	# must be writable to update
        entryfield.delete(0, tk.END)
        if platform=='win32':
            start = pathvar.get().lower().startswith(config.home.lower()) and len(config.home.split('\\')) or 0
            display = []
            components = normpath(pathvar.get()).split('\\')
            buf = ctypes.create_unicode_buffer(MAX_PATH)
            pidsRes = ctypes.c_int()
            for i in range(start, len(components)):
                try:
                    if (not SHGetLocalizedName('\\'.join(components[:i+1]), buf, MAX_PATH, ctypes.byref(pidsRes)) and
                        LoadString(ctypes.WinDLL(expandvars(buf.value))._handle, pidsRes.value, buf, MAX_PATH)):
                        display.append(buf.value)
                    else:
                        display.append(components[i])
                except:
                    display.append(components[i])
            entryfield.insert(0, '\\'.join(display))
        elif platform=='darwin' and NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get()):	# None if path doesn't exist
            if pathvar.get().startswith(config.home):
                display = ['~'] + NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get())[len(NSFileManager.defaultManager().componentsToDisplayForPath_(config.home)):]
            else:
                display = NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get())
            entryfield.insert(0, '/'.join(display))
        else:
            if pathvar.get().startswith(config.home):
                entryfield.insert(0, '~' + pathvar.get()[len(config.home):])
            else:
                entryfield.insert(0, pathvar.get())
        entryfield['state'] = 'readonly' 
Example 46
Project: Taigabot   Author: FrozenPigs   File: base.py    GNU General Public License v3.0 5 votes vote down vote up
def _expand_path(p):
    return osp.normpath(osp.abspath(osp.expandvars(osp.expanduser(p)))) 
Example 47
Project: analytics   Author: appscodelabs   File: make.py    Apache License 2.0 5 votes vote down vote up
def call(cmd, stdin=None, cwd=libbuild.REPO_ROOT):
    print(cmd)
    return subprocess.call([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd) 
Example 48
Project: analytics   Author: appscodelabs   File: make.py    Apache License 2.0 5 votes vote down vote up
def check_output(cmd, stdin=None, cwd=libbuild.REPO_ROOT):
    print(cmd)
    return subprocess.check_output([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd) 
Example 49
Project: analytics   Author: appscodelabs   File: libbuild.py    Apache License 2.0 5 votes vote down vote up
def call(cmd, stdin=None, cwd=None):
    print(cmd)
    return subprocess.call([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd) 
Example 50
Project: analytics   Author: appscodelabs   File: libbuild.py    Apache License 2.0 5 votes vote down vote up
def check_output(cmd, stdin=None, cwd=None):
    print(cmd)
    return subprocess.check_output([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd)