Skip to content

Conversation

@chris-smith-zocdoc
Copy link
Contributor

@chris-smith-zocdoc chris-smith-zocdoc commented Oct 25, 2025

We've run into a few cases where setting the working directory on an InteractiveProcess would be useful, in particular for rules are tests (ie TestRequest). In order to support debugging we convert the setup process to InteractiveProcess but since that drops the working directory you're unable to utilize it currently.

As a workaround we currently write a bash script into the sandbox like

cd ${DIR} && exec {COMMAND}

This will help clean that up

This is also a pre-requisite to supporting setting the working dir in the Run goal (small thread here https://pantsbuild.slack.com/archives/C01CQHVDMMW/p1707448457657149) I'll handle that in a separate pr though

append_only_caches=process.append_only_caches,
immutable_input_digests=process.immutable_input_digests,
keep_sandboxes=keep_sandboxes,
working_directory=process.working_directory,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a subtle breaking change for plugin authors if they're currently setting working_directory but its getting ignored. I guess I could mention that in the release notes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of the existing rules, ones look like they might be affected

test_shell_command_interactively via

working_directory=working_directory,

twine_upload via

working_directory=request.working_directory,

I'll see if there are failing tests when CI comes back in a few minutes, but I either can update these to drop the workingdir or leave them as is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to treat this as a bugfix and mention it in the release notes.

if !run_in_workspace {
command.current_dir(tempdir.path());

let cwd = match (&process.working_directory, run_in_workspace) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe parse this with RelativePath to ensure that working directory is inside the build root?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plugin code is trusted, so more of a safety issue than a security issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually already happens. Because interactive_process shares a lot of code with execute_process, the call to ExecuteProcess::lift ends up creating the RelativePath here

The error it produces is Exception: Absolute paths are not allowed: "/foo"

@benjyw
Copy link
Contributor

benjyw commented Oct 31, 2025

@chris-smith-zocdoc thanks for this! It'll need an entry in the docs/notes/2.31.x.md release notes to pass CI.

@chris-smith-zocdoc
Copy link
Contributor Author

I can add a note there @benjyw , but did you or @tdyas have an opinion on how I should handle the existing rules? #22802 (comment)

Its unclear to me if that is going to break existing usages or not

@benjyw
Copy link
Contributor

benjyw commented Nov 8, 2025

I can add a note there @benjyw , but did you or @tdyas have an opinion on how I should handle the existing rules? #22802 (comment)

Its unclear to me if that is going to break existing usages or not

(I commented there)

@benjyw
Copy link
Contributor

benjyw commented Nov 8, 2025

LMK when this is ready for another look

@chris-smith-zocdoc
Copy link
Contributor Author

Sorry for the delay here @benjyw I updated the note about the two existing usages I called out. Let me know if thats what you intended or not.

CI seems to be failing for unrelated reasons. Rust compilation timed out in one and a race condition in another (slack thread)

Copy link
Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I don't think you need to address my release notes comment above. I might tweak it next time I edit them, but it's not worth a CI round in this PR.


Pants no longer supports loading `pkg_resources`-style namespace packages for plugins. Instead, just use ["native namespace packages"](https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#native-namespace-packages) as per [PEP 420](https://peps.python.org/pep-0420/).

Allow `InteractiveProcess` to set the working directory relative to the sandbox or workspace. Existing usages of `InteractiveProcess.from_process` will now respect the working directory if its set on the Process, which may be a breaking change depending on the use case. Two existing rules `twine_upload` for python package uploads and `test_shell_command_interactively` for shell command testing with the `--debug` flag will now honor the working directory if set on the Process.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should emphasize that this is a bugfix, so while it might change existing behavior, it's not exactly a "breaking change" in the bad way. It's more like "you will now get what you asked for, and if you were previously implicitly relying on not getting it, you'll have to revisit".

@benjyw benjyw merged commit 3da4be2 into pantsbuild:main Dec 8, 2025
25 checks passed
@benjyw
Copy link
Contributor

benjyw commented Dec 8, 2025

Thanks @chris-smith-zocdoc ! If you happen to have a future PR in which you could also modify the notes per my comment, great. Otherwise don't worry about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants