本文整理汇总了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
示例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
示例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
示例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)
示例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")
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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()
示例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