-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
Support renaming #202
Support renaming #202
Conversation
c5452f4
to
fc7a379
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #202 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 397 397
Branches 82 82
=========================================
Hits 397 397 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise looks like a good start.
@@ -37,7 +40,7 @@ enum WatcherEnum { | |||
|
|||
#[pyclass] | |||
struct RustNotify { | |||
changes: Arc<Mutex<HashSet<(u8, String)>>>, | |||
changes: Arc<Mutex<HashSet<(u8, String, String)>>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes: Arc<Mutex<HashSet<(u8, String, String)>>>, | |
changes: Arc<Mutex<HashSet<(u8, Option<String>, String)>>>, |
maybe? Then you can use None
for the src
for added
, moved
and deleted
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I tried that before, and run into issues that I didn't really understand.
const CHANGE_ADDED: u8 = 1; | ||
const CHANGE_MODIFIED: u8 = 2; | ||
const CHANGE_DELETED: u8 = 3; | ||
const CHANGE_MOVED: u8 = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably use an enum for these.
Either an enum with values, or:
enum Change {
Added(String),
Modified(String),
Deleted(String),
Moved(String, String),
}
Then implement ToPyObject
on Change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I will do that later. This is the first time I write Rust, so it's all new for me 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, then I'm impressed.
Let me know if you have more questions, or if you want some help with this.
Lots of examples of ToPyObject
in pydantic-core.
Also github copolit is very useful when you're new to rust (or indeed not new to it), it makes some very helpful suggestions.
} | ||
EventKind::Modify(ModifyKind::Name(RenameMode::Both)) => { | ||
let mut changes = changes_clone.lock().unwrap(); | ||
changes.remove(&(CHANGE_DELETED, path.clone(), EMPTY_STRING)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this actually happen? If so, I guess we should remove added
here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It happens when a file is moved out of the directory. In this case we want to see it as deleted, which is handled in the RenameMode::From
event. But if the file is moved in the same directory, we want to see it as moved, so we need to remove the CHANGE_DELETED
. I didn't find a better way to do it.
When a file is moved in the directory from outside, we want to see it as added, this works fine already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense.
It's getting difficult to handle the macOS case, where renaming a file doesn't provide the src/dst paths. I'm starting to think that the other option you mentioned would be better:
|
Yes, I'll open another PR where we post-process events in Python, but we keep track in Rust of "rename from X" and "rename to Y" events, and I'll get rid of the "rename from X to Y" event. I think it will make it easier to handle these special cases like the one on macOS. |
Are you really sure macos events don't include src and dst? Where did you find that? I know events aren't very good in macos (compared to linux), but I'm surprised by that. I'll check on my mac when I get home. Sorry you didn't have more luck with this. |
One option could be to collect See |
From these comments, and the tests confirm that.
No worries, maybe this is how my journey to Rust begins 😄
Yes, that's what I meant in my comment. |
Thinking about it, it is impossible to only use |
Well that's true, there can be hundreds of files changed in a single set (e.g. when you change branch in git), and we have no file hash to de-duplicate with. The only options are:
I think we cal also get date modified and maybe even size on a file from the OS without reading the file - if we had them, we could do a much better job of matching files. WDYT? |
Yes, that's what is done in jupyter_server_fileid, but I thought we wouldn't have to do that if we used Notify. In the end, it seems that move events only work on Linux? |
It sounds like we have to go the whole hot:
I think to avoid this being a breaking change, and to avoid extra processing when this isn't required, we should put this logic behind a flag/argument parameter. Do you agree with that? I haven't reviewed this PR recently, do you want me to review it or should we work on this separeately? Also, are you willing to have a crack at this, or do you want me to work on it? Would be great if you could, but I understand it's quite a complex feature to start your rust career. I'm happy to work on it, but won't be for a few weeks at least. |
This seems like a good plan.
I reverted my last attempts and got back to the start, where I just assumed that
I'm not sure, it seems that it will take me a lot of time, and you will probably do a much better work. |
okay, makes sense. I'll try and work on it when I get time. Thanks so much for investigating this, it's made my work much easier. I'll leave this open to remind me about it. |
closing this as I haven't needed it so haven't work on it, happy to review a new PR if someone wants to work on it. |
Closes #201.