Skip to content
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

Make os.pwd modifiable via the os.pwd0 dynamic variable #298

Merged
merged 5 commits into from
Sep 7, 2024
Merged

Conversation

lihaoyi
Copy link
Member

@lihaoyi lihaoyi commented Sep 7, 2024

Basically the same thing we did in #295 and #283, except rather than being os.SubProcess-specific this applies to all usage of os.pwd. And with similar limitations: this works for code paths that go through OS-Lib, but not for code that uses java.io or java.nio directly.

AFAIK this is the last of the "global" things we need to redirect in Mill tasks, after env variables and default subprocess streams. I'd like it to go into Mill 0.12.0 together with the other sandboxing-related changes

Added unit tests and updated the documentation

Pull Request: #298

@lihaoyi lihaoyi requested review from lefou and lolgab September 7, 2024 04:24
@@ -38,7 +39,9 @@ package object os {
/**
* The current working directory for this process.
*/
val pwd: Path = os.Path(java.nio.file.Paths.get(".").toAbsolutePath)
def pwd: Path = pwd0.value
val pwd0: DynamicVariable[Path] =
Copy link
Member

Choose a reason for hiding this comment

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

Can we find a better name? pwdContext or pwdDynamic?

Would be nice, if reading code gives a clue what's happening.

Example:

val y = os.pwd0.withValue(os.pwd / "hello") {
  os.pwd
}

vs.

val y = os.pwdContext.withValue(os.pwd / "hello") {
  os.pwd
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with dynamicPwd

@lefou lefou added this to the after 0.10.5 milestone Sep 7, 2024
@lihaoyi lihaoyi merged commit 5dc0aa5 into main Sep 7, 2024
18 checks passed
@lihaoyi lihaoyi deleted the change-pwd branch September 7, 2024 09:57
lihaoyi added a commit that referenced this pull request Sep 7, 2024
…nction` (#299)

Follow up to #298, which it
turns out was not flexible enough to do what we need in Mill. Mill uses
references to the `pwd` to create the `.dest` folder lazily, thus we
cannot just assign a value to the `os.pwd` but actually need to assign a
lambda that can be replaced to implement the lazy evaluation

I pulled the trigger too quickly on releasing 0.10.6 with
`os.dynamicPwd`, so this one has to be named differently. I chose
`os.dynamicPwdFunction` and will make sure to test it with an unstable
release before releasing a stable tag
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