def get_project(name: str, directory: str = '') -> None: """Clone a project from a GitHub name or git url. Put it in dir if this argument is given. A GitHub name without / will be considered as a leanprover-community project. If the name ends with ':foo' then foo will be interpreted as a branch name, and that branch will be checked out.""" # check whether we can ssh into GitHub try: assert PARAMIKO_OK client = paramiko.client.SSHClient() client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy()) client.connect('github.com', username='******') client.close() ssh = True except (AssertionError, AuthenticationException, SSHException): ssh = False name, url, branch = parse_project_name(name, ssh) if branch: name = name + '_' + branch directory = directory or name if directory and Path(directory).exists(): raise FileExistsError('Directory ' + directory + ' already exists') try: LeanProject.from_git_url(url, directory, branch, cache_url, force_download) except GitCommandError as err: handle_exception(err, 'Git command failed')
def get_project(name: str, new_branch: bool, directory: str = '') -> None: """Clone a project from a GitHub name or git url. Put it in dir if this argument is given. A GitHub name without / will be considered as a leanprover-community project. If the name ends with ':foo' then foo will be interpreted as a branch name, and that branch will be checked out. This will fail if the branch does not exist. If you want to create a new branch, pass the `-b` option.""" original_name = name name, url, branch, is_url = parse_project_name(original_name) if branch: name = name + '_' + branch directory = directory or name if directory and Path(directory).exists(): raise FileExistsError('Directory ' + directory + ' already exists') try: LeanProject.from_git_url(url, directory, branch, new_branch, cache_url, force_download) except GitCommandError as err: # if full url is provided, do not retry with HTTPS if not is_url: log.info('Error cloning via SSH, trying HTTPS...') try: name, url, branch, is_url = parse_project_name(original_name, ssh=False) LeanProject.from_git_url(url, directory, branch, new_branch, cache_url, force_download) except GitCommandError as e: handle_exception(e, e.stderr) else: handle_exception(err, err.stderr)
def upgrade_mathlib() -> None: """Upgrade mathlib (as a dependency or as the main project).""" try: proj().upgrade_mathlib() except LeanDownloadError as err: handle_exception(err, 'Failed to fetch mathlib oleans') except InvalidLeanProject: project = LeanProject.user_wide(cache_url, force_download) project.upgrade_mathlib()
def get_mathlib(rev: str) -> None: """Get mathlib""" log.info('Cloning mathlib') repo = Repo.clone_from( 'https://github.com/leanprover-community/mathlib.git', str(DIST_ALL / 'mathlib')) repo.git.checkout(rev) mathlib = LeanProject.from_path(DIST_ALL / 'mathlib') mathlib.get_cache() for dest in DISTS: shutil.copytree(DIST_ALL / 'mathlib', dest / 'mathlib') touch_olean(dest / 'mathlib')
def decls(ctx): proj = LeanProject.from_path(ROOT) proj.pickle_decls(ROOT / 'decls.pickle')
def new(path: str = '.') -> None: """Create a new Lean project and prepare mathlib. If no directory name is given, the current directory is used. """ LeanProject.new(Path(path), cache_url, force_download)
def proj() -> LeanProject: return LeanProject.from_path(Path('.'), cache_url, force_download, lean_upgrade)
def global_upgrade() -> None: """Upgrade user-wide mathlib""" proj = LeanProject.user_wide(cache_url, force_download) proj.upgrade_mathlib()
def global_install() -> None: """Install mathlib user-wide.""" proj = LeanProject.user_wide(cache_url, force_download) proj.add_mathlib()