Open jwodder opened 2 years ago
answering question to https://github.com/con/fscacher/issues/44#issuecomment-996833473 (which is now closed) here
@yarikoptic So what should #58 do about resolving path attributes when decorating methods?
I am thinking about something along the lines of abstracting away "fingerprinters" so we could generalize to not only path
and not only the first arg of the function, but also to attributes etc. Inspection of signature to figure out which arguments we need to deal with is to be only once so it should not have notable performance hit IMHO.
Fingerprinter
which will be subclassed for File and Directory and where to _get_file_fingerprint
and _get_dir_fingerprint
would fold into along with the modified_in_window
to be called at the end of them to return None if "too early"PathFingerprinter
adapter will switch between file and dir fingerprinter depending on what the value (path) is (directory or not)memoize_path
into memoize_params
(or any other name you like) which would also take an option (so more of functions nesting, uff) e.g. params: dict[str, Fingerprinter]
to specify which fingerprinter to use for the args needing special handling. And add ability to specify access to class instance attributes
params={
"path": PathFingerprinter,
"self.path": PathFingerprinter, # here due to `self.` take corresponding attribute of the bound instance
}
edit 1: or make it more explicit by separate two options: args
and params
of the same kind.
self.
attributes) which went through "transformation" will be ignore
d in the calls to joblib like we did for the path
. Their Fingerprinter should provide desired value as part of the returned fingerprint (e.g. resolved path as you @jwodder did in #45 IIRC)@yarikoptic
PathFingerprinter
? If we want to support fingerprinting of multiple path arguments, wouldn't it be simpler to take a list or lists of argument & attribute names?@yarikoptic
no, we will ignore original path as we do now
How? The instance needs to be passed to the instance method, and if we tell joblib to ignore "self", then all non-path attributes will be ignored by joblib as well.
Ah, good point. Let me think about it.
Aha, I think it is manageable although fragile: we can also add argument to list attributes to be added to the fingerprint (if needed). Sure we wouldn't capture full state but I expect it to be applied cautiously ;-)
Prompted by https://github.com/dandi/dandi-cli/issues/852#issuecomment-996210566