Skip to main content
Version: 2.2 (deprecated)

relocated_files


Loose files with path manipulation applied.

Allows you to relocate the files at runtime to something more convenient than their actual paths in your project.

For example, you can relocate src/resources/project1/data.json to instead be resources/data.json. Your other target types can then add this target to their dependencies field, rather than using the original files target.

To remove a prefix:

# Results in `data.json`.
relocated_files(
file_targets=["src/resources/project1:target"],
src="src/resources/project1",
dest="",
)

To add a prefix:

# Results in `images/logo.svg`.
relocated_files(
file_targets=["//:logo"],
src="",
dest="images",
)

To replace a prefix:

# Results in `new_prefix/project1/data.json`.
relocated_files(
file_targets=["src/resources/project1:target"],
src="src/resources",
dest="new_prefix",
)

Backend: ``


dest

str
required

The new prefix that you want to add to the beginning of the path, such as data.

You can set this field to "" to avoid adding any new values to the path; the value in the src field will then be stripped, rather than replaced.

files_targets

Iterable[str]
required

Addresses to the original files() targets that you want to relocate, such as ['//:json_files'].

Every target will be relocated using the same mapping. This means that every target must include the value from the src field in their original path.

src

str
required

The original prefix that you want to replace, such as src/resources.

You can set this field to ` to preserve the original path; the value in the dest` field will then be added to the beginning of this original path.

description

str | None
default: None

A human-readable description of the target.

Use ./pants list --documented :: to see all targets with descriptions.

tags

Iterable[str] | None
default: None

Arbitrary strings to describe a target.

For example, you may tag some test targets with 'integration_test' so that you could run ./pants --tags='integration_test' test :: to only run on targets with that tag.