当前位置: 首页>>代码示例>>Python>>正文


Python pathlib.PurePath方法代码示例

本文整理汇总了Python中pathlib.PurePath方法的典型用法代码示例。如果您正苦于以下问题:Python pathlib.PurePath方法的具体用法?Python pathlib.PurePath怎么用?Python pathlib.PurePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pathlib的用法示例。


在下文中一共展示了pathlib.PurePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: validate_url

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def validate_url(wrapped, instance, args, kwargs):
    """Enforces argument named "url" to be relative path.

    Check that it is instance of str or os.PathLike and that it represents
    relative path.
    """
    try:
        # Use -1 since self is not included in the args.
        url = args[getfullargspec(wrapped).args.index("url") - 1]
    except IndexError:
        url = kwargs.get("url")
    if not isinstance(url, (str, PathLike)):
        raise TypeError("Argument 'url' must be a string or path-like object")
    if PurePath(url).is_absolute():
        raise ValueError("Argument 'url' must be a relative path")
    return wrapped(*args, **kwargs) 
开发者ID:genialis,项目名称:resolwe,代码行数:18,代码来源:baseconnector.py

示例2: validate_urls

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def validate_urls(wrapped, instance, args, kwargs):
    """Enforces argument named "urls" to be a list of relative paths."""
    try:
        # Use -1 since self is not included in the args.
        urls = args[getfullargspec(wrapped).args.index("urls") - 1]
    except IndexError:
        urls = kwargs.get("urls")
    # Check that URLS is really a list of strings.
    if not isinstance(urls, list):
        raise TypeError("Argument urls must be a list of strings or path-like objects")
    if not all(isinstance(url, (str, PathLike)) for url in urls):
        raise TypeError("Argument urls must be a list of strings or path-like objects")
    # Check that all URLS are relative.
    if any(PurePath(url).is_absolute() for url in urls):
        raise ValueError("Paths must be relative.")
    return wrapped(*args, *kwargs) 
开发者ID:genialis,项目名称:resolwe,代码行数:18,代码来源:baseconnector.py

示例3: load_conda_build_config

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def load_conda_build_config(platform=None, trim_skip=True):
    """
    Load conda build config while considering global pinnings from conda-forge.
    """
    config = api.Config(
        no_download_source=True,
        set_build_id=False)

    # get environment root
    env_root = PurePath(shutil.which("bioconda-utils")).parents[1]
    # set path to pinnings from conda forge package
    config.exclusive_config_files = [
        os.path.join(env_root, "conda_build_config.yaml"),
        os.path.join(
            os.path.dirname(__file__),
            'bioconda_utils-conda_build_config.yaml'),
    ]
    for cfg in chain(config.exclusive_config_files, config.variant_config_files or []):
        assert os.path.exists(cfg), ('error: {0} does not exist'.format(cfg))
    if platform:
        config.platform = platform
    config.trim_skip = trim_skip
    return config 
开发者ID:bioconda,项目名称:bioconda-utils,代码行数:25,代码来源:utils.py

示例4: load_exp_matrix

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def load_exp_matrix(fname: str, transpose: bool = False,
                    return_sparse: bool = False,
                    attribute_name_cell_id: str = ATTRIBUTE_NAME_CELL_IDENTIFIER,
                    attribute_name_gene: str = ATTRIBUTE_NAME_GENE) -> pd.DataFrame:
    """
    Load expression matrix from disk.

    Supported file formats are CSV, TSV and LOOM.

    :param fname: The name of the file that contains the expression matrix.
    :param transpose: Is the expression matrix stored as (rows = genes x columns = cells)?
    :param return_sparse: Returns a sparse matrix when loading from loom
    :return: A 2-dimensional dataframe (rows = cells x columns = genes).
    """
    extension = PurePath(fname).suffixes
    if is_valid_suffix(extension, 'grn'):
        if '.loom' in extension:
            return load_exp_matrix_as_loom(fname, return_sparse, attribute_name_cell_id, attribute_name_gene)
        else:
            df = pd.read_csv(fname, sep=suffixes_to_separator(extension), header=0, index_col=0)
            return df.T if transpose else df
    else:
        raise ValueError("Unknown file format \"{}\".".format(fname)) 
开发者ID:aertslab,项目名称:pySCENIC,代码行数:25,代码来源:utils.py

示例5: save_matrix

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def save_matrix(df: pd.DataFrame, fname: str, transpose: bool = False) -> None:
    """
    Save matrix to disk.

    Supported file formats are CSV, TSV and LOOM.

    :param df: A 2-dimensional dataframe (rows = cells x columns = genes).
    :param fname: The name of the file to be written.
    :param transpose: Should the expression matrix be stored as (rows = genes x columns = cells)?
    """
    extension = PurePath(fname).suffixes
    if is_valid_suffix(extension, 'aucell'):
        if '.loom' in extension:
            return save_df_as_loom(df, fname)
        else:
            (df.T if transpose else df).to_csv(fname, sep=suffixes_to_separator(extension))
    else:
        raise ValueError("Unknown file format \"{}\".".format(fname)) 
开发者ID:aertslab,项目名称:pySCENIC,代码行数:20,代码来源:utils.py

示例6: load_modules

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def load_modules(fname: str) -> Sequence[Type[GeneSignature]]:
    # Loading from YAML is extremely slow. Therefore this is a potential performance improvement.
    # Potential improvements are switching to JSON or to use a CLoader:
    # https://stackoverflow.com/questions/27743711/can-i-speedup-yaml
    # The alternative for which was opted in the end is binary pickling.
    extension = PurePath(fname).suffixes
    if is_valid_suffix(extension, 'ctx_yaml'):
        return load_from_yaml(fname)
    elif '.dat' in extension:
        with openfile(fname, 'rb') as f:
            return pickle.load(f)
    elif '.gmt' in extension:
        sep = guess_separator(fname)
        return GeneSignature.from_gmt(fname,
                                      field_separator=sep,
                                      gene_separator=sep)
    else:
        raise ValueError("Unknown file format for \"{}\".".format(fname)) 
开发者ID:aertslab,项目名称:pySCENIC,代码行数:20,代码来源:utils.py

示例7: _format_value

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def _format_value(v):
    if isinstance(v, bool):
        return 'true' if v else 'false'
    if isinstance(v, int) or isinstance(v, long):
        return unicode(v)
    if isinstance(v, float):
        if math.isnan(v) or math.isinf(v):
            raise ValueError("{0} is not a valid TOML value".format(v))
        else:
            return repr(v)
    elif isinstance(v, unicode) or isinstance(v, bytes):
        return _escape_string(v)
    elif isinstance(v, datetime.datetime):
        return format_rfc3339(v)
    elif isinstance(v, list):
        return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))
    elif isinstance(v, dict):
        return '{{{0}}}'.format(', '.join('{} = {}'.format(_escape_id(k), _format_value(obj)) for k, obj in v.items()))
    elif isinstance(v, _path_types):
        return _escape_string(str(v))
    else:
        raise RuntimeError(v) 
开发者ID:pantsbuild,项目名称:pex,代码行数:24,代码来源:writer.py

示例8: remount_workspace_new_timestamp

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def remount_workspace_new_timestamp(
        self, workspace_id: EntryID, original_timestamp: Pendulum, target_timestamp: Pendulum
    ) -> PurePath:
        """
        Mount the workspace at target_timestamp, and unmount the workspace at the original
        timestamp if it is not None. If both timestamps are equals, do nothing.
        """
        # TODO : use different workspaces for temp mount
        if original_timestamp == target_timestamp:
            try:
                return self._mountpoint_tasks[(workspace_id, target_timestamp)].value
            except KeyError:
                pass
        new_workspace = await self._load_workspace_timestamped(workspace_id, target_timestamp)

        runner_task = await self._mount_workspace_helper(new_workspace, target_timestamp)
        if original_timestamp is not None:
            if (workspace_id, original_timestamp) not in self._mountpoint_tasks:
                raise MountpointNotMounted(f"Workspace `{workspace_id}` not mounted.")

            await self._mountpoint_tasks[(workspace_id, original_timestamp)].cancel_and_join()
        return runner_task.value 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:24,代码来源:manager.py

示例9: backup

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def backup(folder,level="full"):

	selected_files = user_files["minimal"] if level == "minimal" else user_files["minimal"] + user_files["full"]
	real_files = []
	for g in selected_files:
		real_files += glob.glob(datadir(g))

	log("Creating backup of " + str(len(real_files)) + " files...")

	now = datetime.utcnow()
	timestr = now.strftime("%Y_%m_%d_%H_%M_%S")
	filename = "maloja_backup_" + timestr + ".tar.gz"
	archivefile = os.path.join(folder,filename)
	assert not os.path.exists(archivefile)
	with tarfile.open(name=archivefile,mode="x:gz") as archive:
		for f in real_files:
			p = PurePath(f)
			r = p.relative_to(datadir())
			archive.add(f,arcname=r)
	log("Backup created!") 
开发者ID:krateng,项目名称:maloja,代码行数:22,代码来源:backup.py

示例10: bread

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def bread(fd):
    # type: (Union[bytes, str, pathlib.Path, pathlib.PurePath, TextIO, BinaryIO]) -> bytes
    """Return bdecoded data from filename, file, or file-like object.

    if fd is a bytes/string or pathlib.Path-like object, it is opened and
    read, otherwise .read() is used. if read() not available, exception
    raised.
    """
    if isinstance(fd, (bytes, str)):
        with open(fd, 'rb') as fd:
            return bdecode(fd.read())
    elif pathlib is not None and isinstance(fd, (pathlib.Path, pathlib.PurePath)):
        with open(str(fd), 'rb') as fd:
            return bdecode(fd.read())
    else:
        return bdecode(fd.read()) 
开发者ID:alfa-addon,项目名称:addon,代码行数:18,代码来源:__init__.py

示例11: bwrite

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def bwrite(data, fd):
    # type: (Union[Tuple, List, OrderedDict, Dict, bool, int, str, bytes], Union[bytes, str, pathlib.Path, pathlib.PurePath, TextIO, BinaryIO]) -> None
    """Write data in bencoded form to filename, file, or file-like object.

    if fd is bytes/string or pathlib.Path-like object, it is opened and
    written to, otherwise .write() is used. if write() is not available,
    exception raised.
    """
    if isinstance(fd, (bytes, str)):
        with open(fd, 'wb') as fd:
            fd.write(bencode(data))
    elif pathlib is not None and isinstance(fd, (pathlib.Path, pathlib.PurePath)):
        with open(str(fd), 'wb') as fd:
            fd.write(bencode(data))
    else:
        fd.write(bencode(data)) 
开发者ID:alfa-addon,项目名称:addon,代码行数:18,代码来源:__init__.py

示例12: copy_files_to_zip

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def copy_files_to_zip(self, dst_file_name, src_dir, is_logs):
        dst = os.path.join(os.getcwd(), dst_file_name)
        mode = 'w' if not os.path.isfile(dst) else 'a'
        optional_dir_name = self.test_config.config_file.replace('.', '_')
        if is_logs is True:
            log_dir = os.path.join(src_dir, optional_dir_name)
            glob_path = glob.glob(os.path.join(log_dir, '*.txt'))
            glob_path.extend(glob.glob(os.path.join(log_dir, '*.log')))
            glob_path.extend(glob.glob(os.path.join(log_dir, 'crashdumps/*')))
        else:
            glob_path = glob.glob(os.path.join(src_dir, 'actual.*'))
        with zipfile.ZipFile(dst, mode, zipfile.ZIP_DEFLATED) as myzip:
            for actual in glob_path:
                path = pathlib.PurePath(actual)
                file_to_be_zipped = path.name
                inner_output = os.path.join(optional_dir_name, file_to_be_zipped)
                myzip.write(actual, inner_output) 
开发者ID:tableau,项目名称:connector-plugin-sdk,代码行数:19,代码来源:tdvt.py

示例13: _get_staging_location

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def _get_staging_location(self):
    if self._gcs_staging_checked:
      return self._gcs_staging

    # Configure the GCS staging bucket
    if self._gcs_staging is None:
      try:
        gcs_bucket = _get_project_id()
      except:
        raise ValueError('Cannot get the Google Cloud project ID, please specify the gcs_staging argument.')
      self._gcs_staging = 'gs://' + gcs_bucket + '/' + GCS_STAGING_BLOB_DEFAULT_PREFIX
    else:
      from pathlib import PurePath
      path = PurePath(self._gcs_staging).parts
      if len(path) < 2 or not path[0].startswith('gs'):
        raise ValueError('Error: {} should be a GCS path.'.format(self._gcs_staging))
      gcs_bucket = path[1]
    from ._gcs_helper import GCSHelper
    GCSHelper.create_gcs_bucket_if_not_exist(gcs_bucket)
    self._gcs_staging_checked = True
    return self._gcs_staging 
开发者ID:kubeflow,项目名称:pipelines,代码行数:23,代码来源:_container_builder.py

示例14: fspath

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def fspath(path):
        """
        Return the string representation of the path.
        If str or bytes is passed in, it is returned unchanged.
        This code comes from PEP 519, modified to support earlier versions of
        python.

        This is required for python < 3.6.
        """
        if isinstance(path, (py.builtin.text, py.builtin.bytes)):
            return path

        # Work from the object's type to match method resolution of other magic
        # methods.
        path_type = type(path)
        try:
            return path_type.__fspath__(path)
        except AttributeError:
            if hasattr(path_type, '__fspath__'):
                raise
            try:
                import pathlib
            except import_errors:
                pass
            else:
                if isinstance(path, pathlib.PurePath):
                    return py.builtin.text(path)

            raise TypeError("expected str, bytes or os.PathLike object, not "
                            + path_type.__name__) 
开发者ID:pytest-dev,项目名称:py,代码行数:32,代码来源:common.py

示例15: default

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePath [as 别名]
def default():
    par = {"ALYX_LOGIN": "test_user",
           "ALYX_PWD": "TapetesBloc18",
           "ALYX_URL": "https://test.alyx.internationalbrainlab.org",
           "CACHE_DIR": str(PurePath(Path.home(), "Downloads", "FlatIron")),
           "FTP_DATA_SERVER": "ftp://ibl.flatironinstitute.org",
           "FTP_DATA_SERVER_LOGIN": "iblftp",
           "FTP_DATA_SERVER_PWD": None,
           "HTTP_DATA_SERVER": "http://ibl.flatironinstitute.org",
           "HTTP_DATA_SERVER_LOGIN": "iblmember",
           "HTTP_DATA_SERVER_PWD": None,
           "GLOBUS_CLIENT_ID": None,
           }
    return iopar.from_dict(par) 
开发者ID:int-brain-lab,项目名称:ibllib,代码行数:16,代码来源:params.py


注:本文中的pathlib.PurePath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。