當前位置: 首頁>>代碼示例>>Python>>正文


Python Path.cwd方法代碼示例

本文整理匯總了Python中pathlib.Path.cwd方法的典型用法代碼示例。如果您正苦於以下問題:Python Path.cwd方法的具體用法?Python Path.cwd怎麽用?Python Path.cwd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pathlib.Path的用法示例。


在下文中一共展示了Path.cwd方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: find_package

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def find_package(name: str) -> Tuple[Optional[Path], Path]:
    """Finds packages install prefix (or None) and it's containing Folder
    """
    module = name.split(".")[0]
    loader = pkgutil.get_loader(module)
    if name == "__main__" or loader is None:
        package_path = Path.cwd()
    else:
        if hasattr(loader, "get_filename"):
            filename = loader.get_filename(module)  # type: ignore
        else:
            __import__(name)
            filename = sys.modules[name].__file__
        package_path = Path(filename).resolve().parent
        if hasattr(loader, "is_package"):
            is_package = loader.is_package(module)  # type: ignore
            if is_package:
                package_path = Path(package_path).resolve().parent
    sys_prefix = Path(sys.prefix).resolve()
    try:
        package_path.relative_to(sys_prefix)
    except ValueError:
        return None, package_path
    else:
        return sys_prefix, package_path 
開發者ID:pgjones,項目名稱:quart,代碼行數:27,代碼來源:helpers.py

示例2: _split_segments

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def _split_segments(in_file):
    from pathlib import Path
    import numpy as np
    import nibabel as nb

    segimg = nb.load(in_file)
    data = np.int16(segimg.dataobj)
    hdr = segimg.header.copy()
    hdr.set_data_dtype('uint8')

    out_files = []
    for i, label in enumerate(("GM", "WM", "CSF"), 1):
        out_fname = str(Path.cwd() / f"aseg_label-{label}_mask.nii.gz")
        segimg.__class__(data == i, segimg.affine, hdr).to_filename(out_fname)
        out_files.append(out_fname)

    return out_files 
開發者ID:nipreps,項目名稱:smriprep,代碼行數:19,代碼來源:anatomical.py

示例3: download_result

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def download_result(self, target: Union[str, Path] = None) -> Path:
        """
        Download single job result to the target file path or into folder (current working dir by default).
        
        Fails if there are multiple result files.

        :param target: String or path where the file should be downloaded to.
        """
        assets = self._download_get_assets()
        if len(assets) != 1:
            raise OpenEoClientException(
                "Expected one result file to download, but got {c}: {u!r}".format(c=len(assets), u=assets))
        filename, metadata = assets.popitem()
        url = metadata["href"]

        target = Path(target or Path.cwd())
        if target.is_dir():
            target = target / filename

        self._download_url(url, target)
        return target 
開發者ID:Open-EO,項目名稱:openeo-python-client,代碼行數:23,代碼來源:job.py

示例4: download_results

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def download_results(self, target: Union[str, Path] = None) -> Dict[Path, dict]:
        """
        Download job results into given folder (current working dir by default).

        The names of the files are taken directly from the backend.

        :param target: String/path, folder where to put the result files.
        :return: file_list: Dict containing the downloaded file path as value and asset metadata
        """
        target = Path(target or Path.cwd())
        if target.exists() and not target.is_dir():
            raise OpenEoClientException("The target argument must be a folder. Got {t!r}".format(t=str(target)))

        assets = {target / f: m for (f, m) in self._download_get_assets().items()}
        if len(assets) == 0:
            raise OpenEoClientException("Expected at least one result file to download, but got 0.")

        for path, metadata in assets.items():
            self._download_url(metadata["href"], path)

        return assets

    # TODO: All below methods are deprecated (at least not specified in the coreAPI) 
開發者ID:Open-EO,項目名稱:openeo-python-client,代碼行數:25,代碼來源:job.py

示例5: test_display

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def test_display(self):
        test_file = Path(_TEST_DATA).joinpath("morph_test.csv")
        test_data = pd.read_csv(test_file, index_col=0)
        output = test_morph.display(data=test_data, chart_name="SigninsChart")
        assert isinstance(output, IPython.lib.display.IFrame)
        assert os.path.isdir(Path.cwd().joinpath("morphchart_package")) is True
        assert (
            os.path.isfile(
                Path.cwd().joinpath(*["morphchart_package", "description.json"])
            )
            is True
        )
        assert (
            os.path.isfile(
                Path.cwd().joinpath(*["morphchart_package", "query_data.csv"])
            )
            is True
        )
        with pytest.raises(MsticpyException):
            assert test_morph.display(data=test_data, chart_name="test")
            assert test_morph.display(data="test_data", chart_name="SigninsChart") 
開發者ID:microsoft,項目名稱:msticpy,代碼行數:23,代碼來源:test_morph_charts.py

示例6: run

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def run(RunnerObj):
    '''
    Function to run GRN-VBEM algorithm
    '''
    inputPath = "data" + str(RunnerObj.inputDir).split(str(Path.cwd()))[1] + \
                    "/JUMP3/ExpressionData.csv"
    
    # make output dirs if they do not exist:
    outDir = "outputs/"+str(RunnerObj.inputDir).split("inputs/")[1]+"/JUMP3/"
    os.makedirs(outDir, exist_ok = True)
    
    outPath = "data/" +  str(outDir) + 'outFile.txt'
    cmdToRun = ' '.join(['docker run --rm -v', str(Path.cwd())+':/JUMP3/data/ jump3:base /bin/sh -c \"time -v -o', "data/" + str(outDir) + 'time.txt', './runJump3',
                         inputPath, outPath, '\"'])
    print(cmdToRun)
    os.system(cmdToRun) 
開發者ID:Murali-group,項目名稱:Beeline,代碼行數:18,代碼來源:jump3Runner.py

示例7: run

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def run(RunnerObj):
    '''
    Function to run PIDC algorithm
    '''
    inputPath = "data" + str(RunnerObj.inputDir).split(str(Path.cwd()))[1] + \
                    "/PIDC/ExpressionData.csv"
    
    # make output dirs if they do not exist:
    outDir = "outputs/"+str(RunnerObj.inputDir).split("inputs/")[1]+"/PIDC/"
    os.makedirs(outDir, exist_ok = True)
    
    outPath = 'data/'+ str(outDir) + 'outFile.txt'
    cmdToRun = ' '.join(['docker run --rm -v', str(Path.cwd())+':/data pidc:base /bin/sh -c \"time -v -o', "data/" + str(outDir) + 'time.txt', 'julia runPIDC.jl',
                         inputPath, outPath, '\"'])
    print(cmdToRun)
    os.system(cmdToRun) 
開發者ID:Murali-group,項目名稱:Beeline,代碼行數:18,代碼來源:pidcRunner.py

示例8: run

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def run(RunnerObj):
    '''
    Function to run GENIE3 algorithm

    :param RunnerObj: An instance of the :class:`BLRun`
    '''
    inputPath = "data" + str(RunnerObj.inputDir).split(str(Path.cwd()))[1] + \
                    "/GENIE3/ExpressionData.csv"
    # make output dirs if they do not exist:
    outDir = "outputs/"+str(RunnerObj.inputDir).split("inputs/")[1]+"/GENIE3/"
    os.makedirs(outDir, exist_ok = True)
    
    outPath = "data/" +  str(outDir) + 'outFile.txt'
    cmdToRun = ' '.join(['docker run --rm -v', str(Path.cwd())+':/data/ --expose=41269', 
                         'arboreto:base /bin/sh -c \"time -v -o', "data/" + str(outDir) + 'time.txt', 'python runArboreto.py --algo=GENIE3',
                         '--inFile='+inputPath, '--outFile='+outPath, '\"'])

    print(cmdToRun)
    os.system(cmdToRun) 
開發者ID:Murali-group,項目名稱:Beeline,代碼行數:21,代碼來源:genie3Runner.py

示例9: run

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def run(RunnerObj):
    '''
    Function to run SCNS algorithm
    '''

    inputPath = "data" + str(RunnerObj.inputDir).split(str(Path.cwd()))[1] + "/SCNS/"
                    
    
    # make output dirs if they do not exist:
    outDir = "outputs/"+str(RunnerObj.inputDir).split("inputs/")[1]+"/SCNS/"
    os.makedirs(outDir, exist_ok = True)
    
    outPath = "data/" +  str(outDir)
    cmdToRun = ' '.join(['docker run --rm -v', str(Path.cwd())+':/SCNS-Toolkit/SynthesisEngine/data/', 
                         'scns:base /bin/sh -c \"time -v -o', "data/" + str(outDir) + 'time.txt',
                         'mono SynthesisEngine.exe', inputPath+'ExpressionData.csv',
                          inputPath+'Edges.csv',  inputPath+'Parameters.csv',
                          inputPath+'initial.txt',  inputPath+'target.txt',
                          outPath, '\"'])

    print(cmdToRun)
    os.system(cmdToRun) 
開發者ID:Murali-group,項目名稱:Beeline,代碼行數:24,代碼來源:scnsRunner.py

示例10: run

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def run(RunnerObj):
    '''
    Function to run GRN-VBEM algorithm
    '''
    
    inputPath = "data" + str(RunnerObj.inputDir).split(str(Path.cwd()))[1]
    # make output dirs if they do not exist:
    outDir = "outputs/"+str(RunnerObj.inputDir).split("inputs/")[1]+"/GRNVBEM/"
    os.makedirs(outDir, exist_ok = True)
    
    PTData = pd.read_csv(RunnerObj.inputDir.joinpath(RunnerObj.cellData),
                             header = 0, index_col = 0)

    colNames = PTData.columns
    for idx in range(len(colNames)):
        exprName = "/GRNVBEM/ExpressionData"+str(idx)+".csv"
        outPath = 'data/' +  str(outDir) + 'outFile'+str(idx)+'.txt'

        cmdToRun = ' '.join(['docker run --rm -v', 
                             str(Path.cwd())+':/VBEM/data/ grnvbem:base /bin/sh -c \"time -v -o', 
                             "data/" + str(outDir) + 'time'+str(idx)+'.txt', 
                             './GRNVBEM', inputPath+exprName, outPath, '\"'])
        print(cmdToRun)
        os.system(cmdToRun) 
開發者ID:Murali-group,項目名稱:Beeline,代碼行數:26,代碼來源:grnvbemRunner.py

示例11: run

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def run(RunnerObj):
    '''
    Function to run PPCOR algorithm
    '''
    inputPath = "data" + str(RunnerObj.inputDir).split(str(Path.cwd()))[1] + \
                    "/PPCOR/ExpressionData.csv"
    
    # make output dirs if they do not exist:
    outDir = "outputs/"+str(RunnerObj.inputDir).split("inputs/")[1]+"/PPCOR/"
    os.makedirs(outDir, exist_ok = True)
    
    outPath = "data/" +  str(outDir) + 'outFile.txt'
    cmdToRun = ' '.join(['docker run --rm -v', str(Path.cwd())+':/data/ ppcor:base /bin/sh -c \"time -v -o', "data/" + str(outDir) + 'time.txt', 'Rscript runPPCOR.R',
                         inputPath, outPath, '\"'])
    print(cmdToRun)
    os.system(cmdToRun) 
開發者ID:Murali-group,項目名稱:Beeline,代碼行數:18,代碼來源:ppcorRunner.py

示例12: run

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def run(RunnerObj):
    '''
    Function to run SINCERITIES algorithm

    :param RunnerObj: A BLRun object
    '''
    inputPath = "data" + str(RunnerObj.inputDir).split(str(Path.cwd()))[1] + \
                        "/SINCERITIES/"
    # make output dirs if they do not exist:
    outDir = "outputs/"+str(RunnerObj.inputDir).split("inputs/")[1]+"/SINCERITIES/"
    os.makedirs(outDir, exist_ok = True)
    
    PTData = pd.read_csv(RunnerObj.inputDir.joinpath(RunnerObj.cellData),
                             header = 0, index_col = 0)

    colNames = PTData.columns
    for idx in range(len(colNames)):
        inFile = "ExpressionData"+str(idx)+".csv"
        outPath = 'data/' + str(outDir) + 'outFile'+str(idx)+'.txt'
        cmdToRun = ' '.join(['docker run --rm -v', 
                             str(Path.cwd())+':/SINCERITIES/data/ sincerities:base /bin/sh -c \"time -v -o', 
                             "data/" + str(outDir) + 'time'+str(idx)+'.txt', 'Rscript MAIN.R',
                             inputPath+inFile, outPath, '\"'])
        print(cmdToRun)
        os.system(cmdToRun) 
開發者ID:Murali-group,項目名稱:Beeline,代碼行數:27,代碼來源:sinceritiesRunner.py

示例13: __init__

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def __init__(self, instance_id, shard_list, shard_count, loop, main, cluster_count):
        self.id = instance_id
        self.shard_list = shard_list
        self.shard_count = shard_count
        self.loop = loop
        self.main = main
        self.cluster_count = cluster_count
        self.started_at = None
        self.command = (
            f"{sys.executable} \"{Path.cwd() / 'main.py'}\" \"{shard_list}\" {shard_count} {self.id} {cluster_count}"
        )
        self._process = None
        self.status = "initialized"
        self.started_at = 0.0
        self.task = self.loop.create_task(self.start())
        self.task.add_done_callback(self.main.dead_process_handler) 
開發者ID:CHamburr,項目名稱:modmail,代碼行數:18,代碼來源:launcher.py

示例14: template_to_base_path

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def template_to_base_path(template, google_songs):
	"""Get base output path for a list of songs for download."""

	path = Path(template)

	if (
		(
			path == Path.cwd()
			or path == Path()
		)
		or path == Path('%suggested%')
	):
		base_path = Path.cwd()
	else:
		song_paths = [
			gm_utils.template_to_filepath(template, song)
			for song in google_songs
		]
		if song_paths:
			base_path = Path(os.path.commonpath(song_paths))
		else:
			base_path = Path.cwd()

	return base_path.resolve() 
開發者ID:thebigmunch,項目名稱:google-music-scripts,代碼行數:26,代碼來源:utils.py

示例15: read_config

# 需要導入模塊: from pathlib import Path [as 別名]
# 或者: from pathlib.Path import cwd [as 別名]
def read_config():
    config = {}

    config_hierarchy = [
        Path(Path(__file__).parent, "s3recon.yml"),  # default
        Path(Path.home(), "s3recon.yaml"),
        Path(Path.home(), "s3recon.yml"),
        Path(Path.cwd(), "s3recon.yaml"),
        Path(Path.cwd(), "s3recon.yml"),
        Path(environ.get("S3RECON_CONFIG") or ""),
    ]

    for c in config_hierarchy:
        try:
            c = load(open(c, "r")) or {}
            merge(config, c)
        except (IOError, TypeError):
            pass

    return config 
開發者ID:clarketm,項目名稱:s3recon,代碼行數:22,代碼來源:s3recon.py


注:本文中的pathlib.Path.cwd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。