本文整理汇总了Python中pathlib.Path.home方法的典型用法代码示例。如果您正苦于以下问题:Python Path.home方法的具体用法?Python Path.home怎么用?Python Path.home使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pathlib.Path
的用法示例。
在下文中一共展示了Path.home方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: for_flight_booking
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def for_flight_booking(
cls,
training_data_dir: str = os.path.abspath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), "../training_data")
),
task_name: str = "flight_booking",
):
"""Return the flight booking args."""
args = cls()
args.training_data_dir = training_data_dir
args.task_name = task_name
home_dir = str(Path.home())
args.model_dir = os.path.abspath(os.path.join(home_dir, "models/bert"))
args.bert_model = "bert-base-uncased"
args.do_lower_case = True
print(
f"Bert Model training_data_dir is set to {args.training_data_dir}",
file=sys.stderr,
)
print(f"Bert Model model_dir is set to {args.model_dir}", file=sys.stderr)
return args
示例2: addNoiseAndGray
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def addNoiseAndGray(surf):
# https://stackoverflow.com/questions/34673424/how-to-get-numpy-array-of-rgb-colors-from-pygame-surface
imgdata = pygame.surfarray.array3d(surf)
imgdata = imgdata.swapaxes(0, 1)
# print('imgdata shape %s' % imgdata.shape) # shall be IMG_HEIGHT * IMG_WIDTH
imgdata2 = noise_generator('s&p', imgdata)
img2 = Image.fromarray(np.uint8(imgdata2))
# img2.save('/home/zhichyu/Downloads/2sp.jpg')
grayscale2 = ImageOps.grayscale(img2)
# grayscale2.save('/home/zhichyu/Downloads/2bw2.jpg')
# return grayscale2
array = np.asarray(np.uint8(grayscale2))
# print('array.shape %s' % array.shape)
selem = disk(random.randint(0, 1))
eroded = erosion(array, selem)
return eroded
示例3: cached_path
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def cached_path(file_path, cached_dir=None):
if not cached_dir:
cached_dir = str(Path(Path.home() / '.tatk') / "cache")
return allennlp_cached_path(file_path, cached_dir)
# DATA_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))), 'data/mdbt')
# VALIDATION_URL = os.path.join(DATA_PATH, "data/validate.json")
# WORD_VECTORS_URL = os.path.join(DATA_PATH, "word-vectors/paragram_300_sl999.txt")
# TRAINING_URL = os.path.join(DATA_PATH, "data/train.json")
# ONTOLOGY_URL = os.path.join(DATA_PATH, "data/ontology.json")
# TESTING_URL = os.path.join(DATA_PATH, "data/test.json")
# MODEL_URL = os.path.join(DATA_PATH, "models/model-1")
# GRAPH_URL = os.path.join(DATA_PATH, "graphs/graph-1")
# RESULTS_URL = os.path.join(DATA_PATH, "results/log-1.txt")
# KB_URL = os.path.join(DATA_PATH, "data/") # TODO: yaoqin
# TRAIN_MODEL_URL = os.path.join(DATA_PATH, "train_models/model-1")
# TRAIN_GRAPH_URL = os.path.join(DATA_PATH, "train_graph/graph-1")
示例4: __init__
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def __init__(self, base_path, home_path=Path.home(), apps=None, input_enabled=True):
self.base_path = base_path
self.home_path = home_path
self.dot_briefcase_path = home_path / ".briefcase"
self.global_config = None
self.apps = {} if apps is None else apps
# Some details about the host machine
self.host_arch = platform.machine()
self.host_os = platform.system()
# External service APIs.
# These are abstracted to enable testing without patching.
self.cookiecutter = cookiecutter
self.requests = requests
self.input = Console(enabled=input_enabled)
self.os = os
self.sys = sys
self.shutil = shutil
self.subprocess = Subprocess(self)
# The internal Briefcase integrations API.
self.integrations = integrations
示例5: get_data_dir
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def get_data_dir(app: str = 'dephell') -> Path:
# unix
if 'XDG_DATA_HOME' in os.environ:
path = Path(os.environ['XDG_DATA_HOME'])
if path.exists():
return path / app
# unix default
path = Path.home() / '.local' / 'share'
if path.exists():
return path / app
# mac os x
path = Path.home() / 'Library' / 'Application Support'
if path.exists():
return path / app
return Path(appdirs.user_data_dir(app))
示例6: get_cache_dir
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def get_cache_dir(app: str = 'dephell') -> Path:
# unix
if 'XDG_CACHE_HOME' in os.environ:
path = Path(os.environ['XDG_CACHE_HOME'])
if path.exists():
return path / app
# unix default
path = Path.home() / '.cache'
if path.exists():
return path / app
# mac os x
path = Path.home() / 'Library' / 'Caches'
if path.exists():
return path / app
return get_data_dir(app=app) / 'cache'
示例7: bin_dir
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def bin_dir(self) -> Path:
"""Global directory from PATH to simlink dephell's binary
"""
path = Path.home() / '.local' / 'bin'
if path.exists():
return path
paths = [Path(path) for path in environ.get('PATH', '').split(pathsep)]
for path in paths:
if path.exists() and '.local' in path.parts:
return path
for path in paths:
if path.exists():
return path
raise LookupError('cannot find place to install binary', paths)
# actions
示例8: assert_state_file_valid
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def assert_state_file_valid(target_name, tap_name, log_path=None):
"""Assert helper function to check if state file exists for
a certain tap for a certain target"""
state_file = Path(f'{Path.home()}/.pipelinewise/{target_name}/{tap_name}/state.json').resolve()
assert os.path.isfile(state_file)
# Check if state file content equals to last emitted state in log
if log_path:
success_log_path = f'{log_path}.success'
state_in_log = None
with open(success_log_path, 'r') as log_f:
state_log_pattern = re.search(r'\nINFO STATE emitted from target: (.+\n)', '\n'.join(log_f.readlines()))
if state_log_pattern:
state_in_log = state_log_pattern.groups()[-1]
# If the emitted state message exists in the log then compare it to the actual state file
if state_in_log:
with open(state_file, 'r') as state_f:
assert state_in_log == ''.join(state_f.readlines())
示例9: output_dir
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def output_dir(self) -> Path:
"""Main experiment output directory.
In this directory, the training checkpoints, logs, and tensorboard files will be
stored for this (sub-)experiment.
"""
# When running as part of an `MultiStageExperiment` the outputs of this `stage` of the experiment will be
# stored in a sub directory of the `MultiStageExperiment` which is named after the current stage index.
if hasattr(self, "parent_output_dir"):
return Path(self.parent_output_dir) / f"stage_{self.stage}"
return (
Path.home()
/ "zookeeper-logs"
/ self.dataset.__class__.__name__
/ self.__class__.__name__
/ datetime.now().strftime("%Y%m%d_%H%M")
)
示例10: parent_output_dir
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def parent_output_dir(self) -> str:
"""Top level experiment directory shared by all sub-experiments.
This directory will have the following structure:
```
parent_output_dir/models/ # dir shared among all experiments in the sequence to store trained models
parent_output_dir/stage_0/ # dir with artifacts (checkpoints, logs, tensorboards, ...) of stage 0
...
parent_output_dir/stage_n/ # dir with artifacts (checkpoints, logs, tensorboards, ...) of stage n
```
"""
return str(
Path.home()
/ "zookeeper-logs"
/ "knowledge_distillation"
/ self.__class__.__name__
/ datetime.now().strftime("%Y%m%d_%H%M")
)
示例11: read_player_cfg
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def read_player_cfg(cls, auto_keys=None):
if sys.platform == "darwin":
conf_path = Path.home() / ".config" / "mpv" / "mpv.conf"
else:
conf_path = (
Path(appdirs.user_config_dir("mpv", roaming=True, appauthor=False))
/ "mpv.conf"
)
mpv_conf = ConfigParser(
allow_no_value=True, strict=False, inline_comment_prefixes="#"
)
mpv_conf.optionxform = lambda option: option
mpv_conf.read_string("[root]\n" + conf_path.read_text())
return {
"ipc_path": lambda: mpv_conf.get("root", "input-ipc-server")
}
示例12: _get_dolphin_home_path
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def _get_dolphin_home_path(self):
"""Return the path to dolphin's home directory"""
if self.dolphin_executable_path:
return self.dolphin_executable_path + "/User/"
home_path = str(Path.home())
legacy_config_path = home_path + "/.dolphin-emu/"
#Are we using a legacy Linux home path directory?
if os.path.isdir(legacy_config_path):
return legacy_config_path
#Are we on OSX?
osx_path = home_path + "/Library/Application Support/Dolphin/"
if os.path.isdir(osx_path):
return osx_path
#Are we on a new Linux distro?
linux_path = home_path + "/.local/share/dolphin-emu/"
if os.path.isdir(linux_path):
return linux_path
print("ERROR: Are you sure Dolphin is installed? Make sure it is, and then run again.")
return ""
示例13: main
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def main():
"""Prevent running two instances of autobisectjs concurrently - we don't want to confuse hg."""
options = parseOpts()
repo_dir = None
if options.build_options:
repo_dir = options.build_options.repo_dir
with LockDir(sm_compile_helpers.get_lock_dir_path(Path.home(), options.nameOfTreeherderBranch, tbox_id="Tbox")
if options.useTreeherderBinaries else sm_compile_helpers.get_lock_dir_path(Path.home(), repo_dir)):
if options.useTreeherderBinaries:
print("TBD: We need to switch to the autobisect repository.", flush=True)
sys.exit(0)
else: # Bisect using local builds
findBlamedCset(options, repo_dir, compile_shell.makeTestRev(options))
# Last thing we do while we have a lock.
# Note that this only clears old *local* cached directories, not remote ones.
rm_old_local_cached_dirs(sm_compile_helpers.ensure_cache_dir(Path.home()))
示例14: ensure_mq_enabled
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def ensure_mq_enabled():
"""Ensure that mq is enabled in the ~/.hgrc file.
Raises:
NoOptionError: Raises if an mq entry is not found in [extensions]
"""
user_hgrc = Path.home() / ".hgrc"
assert user_hgrc.is_file()
user_hgrc_cfg = configparser.ConfigParser()
user_hgrc_cfg.read(str(user_hgrc))
try:
user_hgrc_cfg.get("extensions", "mq")
except configparser.NoOptionError:
print('Please first enable mq in ~/.hgrc by having "mq =" in [extensions].')
raise
示例15: check
# 需要导入模块: from pathlib import Path [as 别名]
# 或者: from pathlib.Path import home [as 别名]
def check() -> None:
"""Check mathlib oleans are more recent than their sources"""
project = proj()
core_ok, mathlib_ok = project.check_timestamps()
toolchain = project.toolchain
toolchain_path = Path.home()/'.elan'/'toolchains'/toolchain
if not core_ok:
print('Some core oleans files in toolchain {} seem older than '
'their source.'.format(toolchain))
touch = input('Do you want to set their modification time to now (y/n) ? ')
if touch.lower() in ['y', 'yes']:
touch_oleans(toolchain_path)
if not mathlib_ok:
print('Some mathlib oleans files seem older than their source.')
touch = input('Do you want to set their modification time to now (y/n) ? ')
if touch.lower() in ['y', 'yes']:
touch_oleans(project.mathlib_folder/'src')
if core_ok and mathlib_ok:
log.info('Everything looks fine.')