-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Feature-PWD-per-drive 2.0 #14546
base: main
Are you sure you want to change the base?
Feature-PWD-per-drive 2.0 #14546
Conversation
- Updated `need_expand` function to accept a string instead of a Path reference, simplifying the logic for checking relative paths with drive letters. - Enhanced `expand_pwd` method to handle leading quotes in paths, ensuring proper path expansion and returning dequoted paths when necessary. - Introduced a new helper function `remove_leading_quotes` to clean up input paths by removing matching leading and trailing quotes. - Added unit tests for the new functionality, ensuring robust handling of quoted paths and correct expansion behavior. This refactor improves the clarity and functionality of path handling in the DriveToPwdMap implementation.
…nv freely. Wait review and other file system commands pending.
do we have to have 5 mods in pwd_per_drive.rs (excluding tests)? it's kind of hard to read. |
Just split into several mods to improve understanding of the implementation before initiated PR, :(. OK, rollback to flatten the code without extra mods. |
…s most file system commands.
…State. 'ls' now PWD-per-drive ready.
…State. 'ls' now PWD-per-drive ready.
…o improve stability of CI test.
CI test for windows not very stable, currently these 3 failed: failures: Checked these tests, they're using stack variable, no global or shared, separately test all OK, do not understand what happened in CI test. Sometimes other network commands fail, sometimes one or more tests for PWD-per-drive failed at SUBST not succeed etc. Usually at least one test will fail, maybe the CI environment needs upgrade to larger memory? :). |
I've retried the windows test twice now and it still fails. I'm still not sure we'll move forward with this though. |
These network commands are not PWD-per-drive related, just recently some commands can't pass CI, seems somewhat randomly. |
The 1700+ lines of changes may seem very complex, but actually:
Since around 2024-12-15, I’ve primarily been writing tests, especially for the watch feature. Because Nushell doesn’t support background tasks, I tried numerous approaches, repeatedly encountering failures (and the output for nu!() macro is not friendly for debugging, have to manually proceeded line by line to isolate problems). Eventually, I solved the issue, wrapping up the PWD-related work. So, in my view, this version of the PWD implementation is not complicated at all. It uses the existing layered env variable mechanism of the stack/engine_state to store and retrieve PWD information, naturally coexisting in harmony with overlays and export-env modules. Now, the refactoring and testing of filesystem commands have been fully completed. The reason CI cannot pass smoothly does not appear to be related to the test code itself; it might be due to insufficient resources in the CI environment as sometime PWD commands all succeed but some network commands randomly fail in CI at the same time. Hope after resolving CI unstable problem, PWD related work can be online soon, :). |
It's concerning to me that the HTTP tests are specifically failing on Windows, since this PR specifically touches Windows. Those tests don't seem to be failing for any other recent commit CI runs, and they pass on this PR for Linux and macOS. We've disabled all of the tests which make actual outbound network connections, all of the HTTP remaining tests are mocked, so it's not an network issue. I know you didn't touch the HTTP code, but maybe some change in this PR changes the way the mock is set up, or some detail of how Nushell interacts with the mock, breaking those tests? It sounds like based on @fdncred's comment that these tests are failing locally, not just in CI (unless he meant that he re-ran the CI tests). Have you tried running the tests locally? You can run them locally by running this in your nushell folder: use toolkit.nu
toolkit check pr |
Already locally run 'cargo test --workspace', and run separately in IDE, all can pass. |
Recently I added test case for 'watch', the test case also runs on Ubuntu and macOS, at first, tests passed at my local macOS and Ubuntu, however, they all fail in CI. Finally I found watch in nushell is sensitive on different events at macOS and Ubuntu, and CI machine may be resource constraint, it often misses some events. Then I modify the test case to repeat create/delete after a while. After that, CI test for 'watch' on all platform passed. |
This time these 3 test cases failed in CI: |
I see, I might understand why there're randomly testcases that will fail in CI, that might be the test of 'watch' that interfere some other test cases happened to run on other threads at the same time. Let me find and update a solution to test again. |
…t interfere other test cases happened to run at the same time.
Fixed, previously the powershell script kills watch process (since that process will never exit itself), and it used name to kill process, which will also kill the nu.exe in test cases that runs at other threads that uses nu!() to execute commands. |
@PegasusPlusUS Is this PR ready for review then? If so I will try to take a look in the next couple of days |
All done for review, half of the time spent on 'watch', :). |
In GitHub review, there’s a touch.rs in nu-command/tests/command/filesystem, it marks the whole file 654 lines new, indeed it was moved from ../, only last test is new added, other part does not need spend time to review. |
I'd like to apologize for the lack of feedback over the last week. I definitely appreciate both your contribution, as well as your thorough explanation of the changes, and I'm still working through them myself. The team has been discussing this PR, and the general agreement is that it creates (at least some) additional maintenance burden for what might not be a common use-case. When future filesystem commands are contributed, it seems likely that it might miss this Windows nuance. It's especially likely that the contributor won't remember to add tests for this feature with the new command. It seems that even now, some commands may have been overlooked? For example, I could be wrong, but it appears that Side-note: I would recommend holding off on implementing this, though, until we reach a final decision. Even the Windows users among us haven't commonly utilized per-drive-PWD in PowerShell or CMD in the past. At the same time, we do want Windows users to have a "first class" experience on Nushell, and we're not opposed to adding new OS-specific features when it makes sense. At the request of the team, I've created a poll in the Discussions area here on GitHub in order to try to understand how commonly used this feature would be. |
Yes, I just patched commands in filesystem\ subdir, there might be other commands that should be patched to fully support PWD, maybe I'd better to search for the usage of nu_path::expand_path_with() to find all commands that should support PWD. I guess if adding a signature for nu_path::expand_path_with() as deprecated, that might help newly created commands directly support PWD, and chances of missing test case to verify supporting of PWD can also be reduced. OK, just wait guidance for additional action, :). If PWD-per-drive not used, I'll extract updates for test of 'watch' and some other improvements not directly related to PWD-per-drive to issue other small PRs. |
Will respect decision, but really can't agree with the conclusion of 'creates additional maintenance burden', if some new commands forget to support PWD-per-drive, (while the possibility is relatively low after nu_path::expand_path_with() marked as deprecated), why not try to improve the new commands, but rather let all commands discard support of PWD-per-drive? If supporting PWD-per-drive is optional not important, then it's okay for the new command not to support it. It wouldn't really count as increasing the maintenance difficulty, would it? |
Upgrade for PR #14411
This PR implements PWD-per-drive as described in discussion #14355
Description
The first version of the implementation was relatively complex and incompatible with overlays. The second version simplifies the implementation by removing the independent DriveToPwd map and avoiding modifications to Stack. Instead, the pwd information is stored in the Stack as an environment variable according to the requirements of the native Windows shell. When expanding relative paths, the Stack is queried for the corresponding environment variable. This approach allows seamless integration with the powerful layered overlay system of Nushell, maintaining perfect harmony between set-env, overlays, and PWD functionality, preserving the original Nushell behavior.
The summary of related file changes is as follows:
Moved from the nu_path module to the nu_protocol::engine module.
1.1 File system commands can use expand_path_with(), to replace previously (directly) used nu_path::expand_path_with. If the path is relative to a drive, it will expand and return the result; otherwise, it processes paths as before by calling nu_path::expand_path_with. File system commands can also directly call expand_pwd() for converting drive relative path.
1.2 When user changes current directory, current stack shall add "PWD" environment variable to store current directory. PWD-per-drive hooks in Stack::add_env_var() and EngineState::add_env_var(). If found the variable name is "PWD", hooking code will call set_pwd() to notify PWD-per-drive recording PWD for current drive. It does the job by requesting the stack or engine_state (via EnvMaintainer trait) to store the information in environment variables according to the native Windows shell conventions. An extend_automatic_env_vars() is designed to help keep dedicated environment variables from being modified manually.
1.3 Other fn()s are auxiliary path-handling functions needed for the above two parts. Unit tests are in test mod.
crates/nu_protocol/src/engine/stack.rs
Removed the first version's modifications to the Stack structure.
Added a single line in set_cwd() to call set_pwd() mentioned in 1.2.
src/run.rs
Reverted changes made in the first version.
crates/nu_protocol/src/engine/mod.rs
Added the module declaration and re-export for pwd_per_drive.
crates/nu_protocol/Cargo.toml
Added reference to omnipath.
crates/nu_path/src/lib.rs
Reverted changes made in the first version.
crates/nu-engine/src/eval_ir.rs
Continued updates from the first version, replacing three calls to nu_path::expand_path_with() with expand_path_with() mentioned in 1.1.
crates/nu-engine/src/eval.rs
Removed modifications to caller/callee Stack operations from the first version.
Replaced two calls to nu_path::expand_path_with() with expand_path_with() mentioned in 1.1.
crates/nu-engine/src/env.rs
Reverted changes made in the first version.
crates/nu-cmd-plugin/src/util.rs
Replaced two calls to nu_path::expand_path_with() with expand_path_with() mentioned in 1.1.
crates/nu-cli/src/repl.rs
Reverted the first version's changes and no longer modified the do_auto_cd implementation.
Replaced one call to nu_path::expand_path_with() with expand_path_with() mentioned in 1.1.
Updated the logic for path.is_dir() in parse_operation() to account for Windows relative paths.
crates/nu-command/src/filesystem/cd.rs
Revert the change made in the first version.
crates/nu-cli/src/completions/completion_common.rs
Continued updates from the first version, replacing one call to nu_path::expand_path_with() with
expand_path_with() mentioned in 1.1.
Apart from auto_cd/cd/ls/save/watch, other file systems support relative path for drive syntax, and need to be modified to support PWD-per-drive, they are under testing and will be upgraded near after this PR is accepted.
'glob' currently does not support windows path syntax, so this command also needs to be updated.
=================================================================
Make sure you've run and fixed any issues with these commands:
Pass -
cargo fmt --all -- --check
to check standard code formatting (cargo fmt --all
applies these changes)Pass -
cargo clippy --workspace -- -D warnings -D clippy::unwrap_used
to check that you're using the standard code stylePass -
cargo test --workspace
to check that all tests pass (on Windows make sure to enable developer mode)Pass -
cargo run -- -c "use toolkit.nu; toolkit test stdlib"
to run the tests for the standard libraryAfter Submitting
To DO
PWD-per-drive ready: auto_cd/cd/ls/save/watch
Other file system [du|mktemp|rm|open|touch|ucp|umkdir|umv|utouch] commands are pending for upgrade.