(package, force=False, skip_list=None, allow_list=None, local_path=None)
| 25 | |
| 26 | |
| 27 | def do_link(package, force=False, skip_list=None, allow_list=None, local_path=None): |
| 28 | if skip_list and package in skip_list: |
| 29 | print(f"Skip creating symbolic link for {package}") |
| 30 | return |
| 31 | if allow_list is not None and package not in allow_list: |
| 32 | print(f"Skip creating symbolic link for {package} (not in allow list)") |
| 33 | return |
| 34 | package_home = os.path.abspath(os.path.join(ray.__file__, f"../{package}")) |
| 35 | # Infer local_path automatically. |
| 36 | if local_path is None: |
| 37 | local_path = f"../{package}" |
| 38 | local_home = os.path.abspath(os.path.join(__file__, local_path)) |
| 39 | # If installed package dir does not exist, continue either way. We'll |
| 40 | # remove it/create a link from there anyways. |
| 41 | if not os.path.isdir(package_home) and not os.path.isfile(package_home): |
| 42 | print(f"{package_home} does not exist. Continuing to link.") |
| 43 | # Make sure the path we are linking to does exist. |
| 44 | assert os.path.exists(local_home), local_home |
| 45 | # Confirm with user. |
| 46 | if not force and not click.confirm( |
| 47 | f"This will replace:\n {package_home}\nwith " f"a symlink to:\n {local_home}", |
| 48 | default=True, |
| 49 | ): |
| 50 | return |
| 51 | |
| 52 | # Windows: Create directory junction. |
| 53 | if os.name == "nt": |
| 54 | try: |
| 55 | shutil.rmtree(package_home) |
| 56 | except FileNotFoundError: |
| 57 | pass |
| 58 | except OSError: |
| 59 | os.remove(package_home) |
| 60 | |
| 61 | # create symlink for directory or file |
| 62 | if os.path.isdir(local_home): |
| 63 | subprocess.check_call( |
| 64 | ["mklink", "/J", package_home, local_home], shell=True |
| 65 | ) |
| 66 | elif os.path.isfile(local_home): |
| 67 | subprocess.check_call( |
| 68 | ["mklink", "/H", package_home, local_home], shell=True |
| 69 | ) |
| 70 | else: |
| 71 | print(f"{local_home} is neither directory nor file. Link failed.") |
| 72 | |
| 73 | # Posix: Use `ln -s` to create softlink. |
| 74 | else: |
| 75 | if os.path.exists(package_home) and os.path.realpath( |
| 76 | package_home |
| 77 | ) == os.path.realpath(local_home): |
| 78 | print(f"{package} is already linked to source. Skipping.") |
| 79 | return |
| 80 | sudo = [] |
| 81 | if not os.access(os.path.dirname(package_home), os.W_OK): |
| 82 | print("You don't have write permission " f"to {package_home}, using sudo:") |
| 83 | sudo = ["sudo"] |
| 84 | print(f"Creating symbolic link from \n {local_home} to \n {package_home}") |
no test coverage detected
searching dependent graphs…