---
sidebar:
  label: roboto.paths
  order: 18
title: roboto.paths
---
## Module Contents

### DOTFILE_PATTERN

```python
roboto.paths.DOTFILE_PATTERN = '.**'
```

`from roboto.paths import DOTFILE_PATTERN`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/paths.py#L21-L21)

Gitignore-style pattern that matches a path with any component starting with a dot, such as `.env`.

It also matches `.cache/run.bag` and `logs/.tmp/run.bag`. Triggers never run on files whose paths match it.

### excludespec_from_patterns()

```python
def roboto.paths.excludespec_from_patterns(
    exclude_patterns: Optional[collections.abc.Iterable[str]] = None,
) -> Optional[pathspec.PathSpec]
```

`from roboto.paths import excludespec_from_patterns`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/paths.py#L64-L79)

Build a `pathspec.GitIgnoreSpec` from Gitignore-style patterns.

[`upload_directory()`](/docs/reference/python-sdk/roboto/domain/files/file_system#roboto.domain.files.file_system.FileSystem.upload_directory) builds its include and exclude specs through it, so most code never calls it.

**Parameters**

- **exclude_patterns** (`Optional[collections.abc.Iterable[str]]`): Patterns to compile. `None` returns `None`.

**Returns**

- `Optional[pathspec.PathSpec]`: A spec that matches a path when the patterns select it, as a `.gitignore` file with these lines would, or `None` when `exclude_patterns` is `None`.

### is_dotfile_path()

```python
def roboto.paths.is_dotfile_path(path: str) -> bool
```

`from roboto.paths import is_dotfile_path`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/paths.py#L146-L154)

Return whether any component of `path` starts with a dot, as `DOTFILE_PATTERN` matches.

Roboto calls this when a trigger decides which files to run on. A file whose path it matches is skipped.

**Parameters**

- **path** (`str`): Path to test, relative to its dataset.

**Returns**

- `bool`

### join_within()

```python
def roboto.paths.join_within(
    directory: pathlib.Path,
    relative_path: str,
) -> pathlib.Path
```

`from roboto.paths import join_within`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/paths.py#L28-L48)

Return `directory / relative_path`, refusing a path that resolves outside `directory`.

[`download_files()`](/docs/reference/python-sdk/roboto/domain/files/file_system#roboto.domain.files.file_system.FileSystem.download_files) checks each file's destination through it, so most code never calls it. The check follows symbolic links.

**Parameters**

- **directory** (`pathlib.Path`): Directory the path must stay within.
- **relative_path** (`str`): Path to join to `directory`, such as a file's path within its dataset.

**Returns**

- `pathlib.Path`: `directory / relative_path` as joined, not resolved.

**Raises**

- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): `relative_path` resolves outside `directory`, as `../notes.txt` or an absolute path elsewhere does.

### path_matches()

```python
def roboto.paths.path_matches(
    path: str,
    include_patterns: Optional[collections.abc.Iterable[str]] = None,
    exclude_patterns: Optional[collections.abc.Iterable[str]] = None,
) -> bool
```

`from roboto.paths import path_matches`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/paths.py#L96-L116)

Return whether `path` matches an include pattern and no exclude pattern.

To match many paths against the same patterns, compile them once with `pathspec_from_patterns` and call `path_matches_specs`.

**Parameters**

- **path** (`str`): Path to test, relative to the root the patterns are written against.
- **include_patterns** (`Optional[collections.abc.Iterable[str]]`): Gitignore-style patterns `path` must match one of. `None` includes every path; an empty list includes none.
- **exclude_patterns** (`Optional[collections.abc.Iterable[str]]`): Gitignore-style patterns `path` must match none of. `None` excludes no path.

**Returns**

- `bool`

### path_matches_specs()

```python
def roboto.paths.path_matches_specs(
    path: str,
    include_spec: Optional[pathspec.PathSpec] = None,
    exclude_spec: Optional[pathspec.PathSpec] = None,
) -> bool
```

`from roboto.paths import path_matches_specs`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/paths.py#L119-L140)

Return whether `path` matches `include_spec` and does not match `exclude_spec`.

This is `path_matches` for patterns already compiled with `pathspec_from_patterns`, for callers that match many paths against the same patterns.

**Parameters**

- **path** (`str`): Path to test, relative to the root the patterns are written against.
- **include_spec** (`Optional[pathspec.PathSpec]`): Spec `path` must match. `None` includes every path.
- **exclude_spec** (`Optional[pathspec.PathSpec]`): Spec `path` must not match. `None` excludes no path.

**Returns**

- `bool`

### path_to_pattern()

```python
def roboto.paths.path_to_pattern(path: str) -> str
```

`from roboto.paths import path_to_pattern`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/paths.py#L51-L61)

Return `path` with `[` and `]` escaped, so a Gitignore-style pattern made from it matches them literally.

Other wildcard characters, such as `*` and `?`, are not escaped and still match as wildcards.

**Parameters**

- **path** (`str`): Path to escape.

**Returns**

- `str`

### pathspec_from_patterns()

```python
def roboto.paths.pathspec_from_patterns(
    patterns: collections.abc.Iterable[str],
) -> pathspec.PathSpec
```

`from roboto.paths import pathspec_from_patterns`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/paths.py#L82-L93)

Build a `pathspec.PathSpec` from Gitignore-style patterns, which matches a path any of them selects.

A pattern starting with `!` stops an earlier pattern from selecting a path, as in a `.gitignore` file. An empty `patterns` matches no path.

**Parameters**

- **patterns** (`collections.abc.Iterable[str]`): Patterns to compile.

**Returns**

- `pathspec.PathSpec`

### pattern_to_like_value()

```python
def roboto.paths.pattern_to_like_value(pattern: str) -> str
```

`from roboto.paths import pattern_to_like_value`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/paths.py#L157-L169)

Return a Gitignore-style pattern as a value for [`Like`](/docs/reference/python-sdk/roboto/query/conditions#roboto.query.conditions.Comparator.Like).

Each `**/*`, `**` and `*` becomes `%`, which matches any run of characters, `/` included, so `*` matches across directories here as `**` does. Nothing else is translated: `?` and `[...]` stay as written, a pattern with no wildcard matches only that exact path rather than a file of that name in any directory, and `_` and `%` in the pattern act as `LIKE` wildcards. `patterns_to_condition_group` converts each pattern through it, so most code never calls it.

**Parameters**

- **pattern** (`str`): Pattern to convert.

**Returns**

- `str`

### patterns_to_condition_group()

```python
def roboto.paths.patterns_to_condition_group(
    patterns: collections.abc.Iterable[str],
    path_field_name: str,
    comparator: roboto.query.Comparator,
    operator: roboto.query.ConditionOperator,
) -> roboto.query.ConditionGroup
```

`from roboto.paths import patterns_to_condition_group`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/paths.py#L172-L206)

Build a condition group that compares a path field against each of several Gitignore-style patterns.

Roboto calls this when a caller lists a dataset's files with include or exclude patterns. Roboto treats an empty pattern list as no filter and does not call this for it. Each pattern is converted by `pattern_to_like_value`, so it matches as that function describes.

**Parameters**

- **patterns** (`collections.abc.Iterable[str]`): Patterns to compare against. Must not be empty.
- **path_field_name** (`str`): Name of the field that holds the path, such as `"relative_path"`.
- **comparator** (`roboto.query.Comparator`): Comparator for each pattern's condition, such as [`Like`](/docs/reference/python-sdk/roboto/query/conditions#roboto.query.conditions.Comparator.Like) to include matching paths or [`NotLike`](/docs/reference/python-sdk/roboto/query/conditions#roboto.query.conditions.Comparator.NotLike) to exclude them.
- **operator** (`roboto.query.ConditionOperator`): Operator that joins the conditions: [`Or`](/docs/reference/python-sdk/roboto/query/conditions#roboto.query.conditions.ConditionOperator.Or) to match any pattern, or [`And`](/docs/reference/python-sdk/roboto/query/conditions#roboto.query.conditions.ConditionOperator.And) to match all of them.

**Raises**

- `pydantic.ValidationError`: `patterns` is empty, because a condition group needs at least one condition.

**Returns**

- `roboto.query.ConditionGroup`
