def patch(self, location, patch_content): # type: (PathLike, Text) -> bool """ Apply patch repository at `location` """ self.log.info("applying diff to %s" % location) # noinspection PyBroadException try: for match in filter( None, map(self.PATCH_ADDED_FILE_RE.match, patch_content.splitlines())): file_path = None # noinspection PyBroadException try: file_path = normalize_path(location, match.group("path")) create_file_if_not_exists(file_path) except Exception: if file_path: self.log.warning( "failed creating file for git diff (%s)" % file_path) except Exception: pass return_code, errors = self.call_with_stdin(patch_content, *self.patch_base, cwd=location) if return_code: self.log.error("Failed applying diff") lines = errors.splitlines() if any(l for l in lines if "no such file or directory" in l.lower()): self.log.warning( "NOTE: files were not found when applying diff, perhaps you forgot to push your changes?" ) return False else: self.log.info("successfully applied uncommitted changes") return True
from datetime import timedelta from distutils.util import strtobool from enum import IntEnum from os import getenv, environ from typing import Text, Optional, Union, Tuple, Any from furl import furl from pathlib2 import Path import six from clearml_agent.helper.base import normalize_path PROGRAM_NAME = "clearml-agent" FROM_FILE_PREFIX_CHARS = "@" CONFIG_DIR = normalize_path("~/.clearml") TOKEN_CACHE_FILE = normalize_path("~/.clearml.clearml_agent.tmp") CONFIG_FILE_CANDIDATES = ["~/clearml.conf"] def find_config_path(): for candidate in CONFIG_FILE_CANDIDATES: if Path(candidate).expanduser().exists(): return candidate return CONFIG_FILE_CANDIDATES[0] CONFIG_FILE = normalize_path(find_config_path())