-
Notifications
You must be signed in to change notification settings - Fork 7k
[core] Add .rayignore #58500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Add .rayignore #58500
Changes from 1 commit
0299a04
25a305c
f3dea2a
06bd459
1b18ff7
a6079f4
1830110
8b1e060
68e2511
4d525ab
8d6a2d3
2e9189a
101443b
71aab0d
9a8f5a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -505,7 +505,7 @@ The ``runtime_env`` is a Python dictionary or a Python class :class:`ray.runtime | |
|
|
||
| Note: Setting a local directory per-task or per-actor is currently unsupported; it can only be set per-job (i.e., in ``ray.init()``). | ||
|
|
||
| Note: If the local directory contains a ``.gitignore`` file, the files and paths specified there are not uploaded to the cluster. You can disable this by setting the environment variable `RAY_RUNTIME_ENV_IGNORE_GITIGNORE=1` on the machine doing the uploading. | ||
| Note: By default, if the local directory contains a ``.gitignore`` and/or ``.rayignore`` file, the files and paths specified in both will not be uploaded to the cluster. To disable the ``.gitignore`` from being considered, set ``RAY_RUNTIME_ENV_IGNORE_GITIGNORE=1`` on the machine doing the uploading. | ||
|
|
||
| Note: If the local directory contains symbolic links, Ray follows the links and the files they point to are uploaded to the cluster. | ||
|
|
||
|
|
@@ -532,7 +532,8 @@ The ``runtime_env`` is a Python dictionary or a Python class :class:`ray.runtime | |
|
|
||
| Note: Setting options (1), (3) and (4) per-task or per-actor is currently unsupported, it can only be set per-job (i.e., in ``ray.init()``). | ||
|
|
||
| Note: For option (1), if the local directory contains a ``.gitignore`` file, the files and paths specified there are not uploaded to the cluster. You can disable this by setting the environment variable `RAY_RUNTIME_ENV_IGNORE_GITIGNORE=1` on the machine doing the uploading. | ||
| Note: For option (1), by default, if the local directory contains a ``.gitignore`` and/or ``.rayignore`` file, the files and paths specified in both will not be uploaded to the cluster. To disable the ``.gitignore`` from being considered, set ``RAY_RUNTIME_ENV_IGNORE_GITIGNORE=1`` on the machine doing the uploading. | ||
|
|
||
|
||
|
|
||
| - ``py_executable`` (str): Specifies the executable used for running the Ray workers. It can include arguments as well. The executable can be | ||
| located in the `working_dir`. This runtime environment is useful to run workers in a custom debugger or profiler as well as to run workers | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,10 +92,9 @@ def _dir_travel( | |
|
|
||
| Respects excludes, which will be called to check if this path is skipped. | ||
| """ | ||
| e = _get_gitignore(path) | ||
|
|
||
| if e is not None: | ||
| excludes.append(e) | ||
| new_excludes = get_excludes_from_ignore_files(path, logger=logger) | ||
| excludes.extend(new_excludes) | ||
|
|
||
| skip = any(e(path) for e in excludes) | ||
| if not skip: | ||
|
|
@@ -108,7 +107,7 @@ def _dir_travel( | |
| for sub_path in path.iterdir(): | ||
| _dir_travel(sub_path, excludes, handler, logger=logger) | ||
|
|
||
| if e is not None: | ||
| for _ in range(len(new_excludes)): | ||
| excludes.pop() | ||
|
|
||
|
|
||
|
|
@@ -280,24 +279,22 @@ def match(p: Path): | |
| return match | ||
|
|
||
|
|
||
| def _get_gitignore(path: Path) -> Optional[Callable]: | ||
| def _get_ignore_file(path: Path, ignore_file: str) -> Optional[Callable]: | ||
| """Returns a function that returns True if the path should be excluded. | ||
|
|
||
| Returns None if there is no .gitignore file in the path, or if the | ||
| RAY_RUNTIME_ENV_IGNORE_GITIGNORE environment variable is set to 1. | ||
| Returns None if there is no .gitignore file in the path. | ||
|
|
||
| Args: | ||
| path: The path to the directory to check for a .gitignore file. | ||
| path: The path to the directory to check for a .rayignore file. | ||
iamjustinhsu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ignore_file: The name of the ignore file. Combined with path will | ||
| give the absolute path to the ignore_file. | ||
|
|
||
| Returns: | ||
| A function that returns True if the path should be excluded. | ||
| """ | ||
| ignore_gitignore = os.environ.get(RAY_RUNTIME_ENV_IGNORE_GITIGNORE, "0") == "1" | ||
| if ignore_gitignore: | ||
| return None | ||
|
|
||
| path = path.absolute() | ||
| ignore_file = path / ".gitignore" | ||
| ignore_file = path / ignore_file | ||
| if ignore_file.is_file(): | ||
| with ignore_file.open("r") as f: | ||
| pathspec = PathSpec.from_lines("gitwildmatch", f.readlines()) | ||
|
|
@@ -311,6 +308,37 @@ def match(p: Path): | |
| return None | ||
|
|
||
|
|
||
| def get_excludes_from_ignore_files( | ||
| path: Path, logger: Optional[logging.Logger] = default_logger | ||
| ) -> List[Callable]: | ||
| """Get exclusion functions from .gitignore and .rayignore files in the current path. | ||
|
|
||
| Environment Variables: | ||
| RAY_RUNTIME_ENV_IGNORE_GITIGNORE: If set to "1", .gitignore files | ||
| won't be parsed. Default is "0" (parse .gitignore). | ||
|
|
||
| Returns: | ||
| List[Callable]: List of exclusion functions. Each function takes a Path | ||
| and returns True if the path should be excluded based on the ignore | ||
| patterns in the respective ignore file. | ||
| """ | ||
| ignore_gitignore = os.environ.get(RAY_RUNTIME_ENV_IGNORE_GITIGNORE, "0") == "1" | ||
|
||
|
|
||
| to_ignore: List[Optional[Callable]] = [] | ||
| if not ignore_gitignore: | ||
| # Default behavior: use both .gitignore and .rayignore | ||
| # .gitignore is parsed, and .rayignore inherits from it | ||
| g = _get_ignore_file(path, ignore_file=".gitignore") | ||
| to_ignore.append(g) | ||
| logger.info( | ||
| "Ignoring files found in .rayignore (if exists) and .gitginore (if exists)" | ||
| ) | ||
iamjustinhsu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
iamjustinhsu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| r = _get_ignore_file(path, ignore_file=".rayignore") | ||
| to_ignore.append(r) | ||
| return [ignore for ignore in to_ignore if ignore is not None] | ||
iamjustinhsu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def pin_runtime_env_uri(uri: str, *, expiration_s: Optional[int] = None) -> None: | ||
| """Pin a reference to a runtime_env URI in the GCS on a timeout. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: In accordance with technical writing style guide:
Not sure if "Ray" is the right subject in "Ray doesn't upload". Might need to check me on that.