コード例 #1
0
def scope_name_to_path(
        filesystem: FS,
        scope_path: str,
        valid_types: Iterable[str] = ("classdef", "funcdef"),
) -> str:
    # Try get a valid filesystem path from a scope name (adds ".c" and scope type).
    for scope_type in valid_types:
        possible_path = f"{scope_path}.{scope_type}.c"
        if filesystem.exists(possible_path):
            return possible_path
    raise fs.errors.ResourceNotFound(possible_path)
コード例 #2
0
def package_json(cwd_fs: FS):
    """
    Try guess a version from ``package.json``.
    """
    log.debug('Looking for package.json')
    if cwd_fs.exists('package.json'):
        log.debug('Guessing version with package.json')
        try:
            with cwd_fs.open('package.json', 'r') as fd:
                return json.load(fd).get('version')
        except json.JSONDecodeError:
            pass
    return None
コード例 #3
0
def _checkin(src_fs: FS,
             src_path: str,
             dst_fs: FS,
             dst_path: str,
             move: bool = False):
    dst_dir = Path(dst_path).parent.as_posix()
    if not dst_fs.exists(dst_dir):
        dst_fs.makedirs(dst_dir)
    if src_fs.isfile(src_path):
        method = move_file if move else copy_file
    else:
        method = move_dir if move else copy_dir
    method(src_fs, src_path, dst_fs, dst_path)
    if move:
        src_fs.settext(rf'{src_path}.checkin',
                       json.dumps({repr(dst_fs): dst_path}))
    return dst_fs, dst_path