Skip to content

Commit

Permalink
perform tilde expansion on path_metadata_request
Browse files Browse the repository at this point in the history
Within the pants repo itself, the inputs to `path_metadata_request` are
commonly used on the components of the `PATH` variable.  These would
presumable be valid paths, but people have all sorts of crusty
oddities in their shell configs.

In particular if one does something reasonable looking like `export
PATH="~/.local/bin:$PATH"` (note the quotes) than the path component
will be a literal `~/.local/bin` and not expanded to the home
directory.  This is because tilde expansion happened *before*
<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06>
the quote removal.

Since bash and friends are cool fine with literal tildes in `PATH`,
everyone would reasonable expect pants to be too.
  • Loading branch information
cburroughs committed Jan 31, 2025
1 parent 390416b commit 327d988
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/notes/2.25.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ The version of Python used by Pants itself is now [3.11](https://docs.python.org

The oldest [glibc version](https://www.sourceware.org/glibc/wiki/Glibc%20Timeline) supported by the published Pants wheels is now 2.28. This should have no effect unless you are running on extremely old Linux distributions. See <https://github.com/pypa/manylinux> for background context on Python wheels and C libraries.

The `path_metadata_request` intrinsic rule now performs tilde expansion on paths. For example if one does `PATH="~/.bin:$PATH"` (note the quotes), leaving a literal `~` in one of the `PATH` entries, `path_metadata_request` will now expand that.

## Full Changelog

Expand Down
1 change: 1 addition & 0 deletions src/rust/engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/rust/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ rand = { workspace = true }
regex = { workspace = true }
reqwest = { version = "0.12", default-features = false, features = ["stream", "rustls-tls"] }
rule_graph = { path = "rule_graph" }
shellexpand = { workspace = true }
smallvec = { version = "1", features = ["union"] }
stdio = { path = "stdio" }
store = { path = "fs/store" }
Expand Down
1 change: 1 addition & 0 deletions src/rust/engine/src/intrinsics/digests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ fn path_metadata_request(single_path: Value) -> PyGeneratorResponseNativeCall {
let path = externs::getattr_as_optional_string(arg, "path")
.map_err(|e| format!("Failed to get `path` for field: {e}"))?;
let path = path.ok_or_else(|| "Path must not be `None`.".to_string())?;
let path = shellexpand::tilde(&path).to_string();

let namespace: PyPathNamespace = externs::getattr(arg, "namespace")
.map_err(|e| format!("Failed to get `namespace` for field: {e}"))?;
Expand Down

0 comments on commit 327d988

Please sign in to comment.