-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Add RelocPath
type for userdefined relocatable paths
#56053
base: master
Are you sure you want to change the base?
Conversation
What's the idiomatic usage pattern for this look like? |
The example where module MyPkg
const data = RelocPath(joinpath(@__DIR__, "myfile.data"))
function read_data()
path = String(data)
# load from path ...
end
end |
Is this how we get a Path type finally. I'd love that |
It would be nice to get this into Julia 1.12. |
Should we have a way of constructing a |
Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
FWIW there is already https://juliahub.com/ui/Packages/General/FilePathsBase and https://juliahub.com/ui/Packages/General/FilePaths which provide such types.
I am not sure. |
@vchuravy @gbaraldi and @topolarity Would you be able to review this PR? As far as I can tell, this PR is an improvement compared to #55146, but I'm not particularly familiar with the relevant part of the codebase. |
@staticfloat IIRC, you also worked on the depot-relocatibility code; it would be great if you could review this PR. |
The |
struct RelocPath | ||
subpath::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.
Thoughts about using OncePerProcess
to make it so we only compute the result once:
struct RelocPath | |
subpath::String | |
struct RelocPath | |
getpath::OncePerProcess{String} | |
end | |
RelocPath(path::AbstractString) = let | |
depot, _ = replace_depot_path_impl(path) | |
if isnothing(depot) | |
error("Failed to locate $(path) in any of DEPOT_PATH.") | |
end | |
subpath = String(replace(path, depot => ""; count=1)) | |
return RelocPath(OncePerProcess{String}() do | |
for d in DEPOT_PATH | |
if isdirpath(d) | |
d = dirname(d) | |
end | |
local path = string(d, subpath) | |
if ispath(path) | |
return path | |
end | |
end | |
error("Failed to relocate @depot$(subpath) in any of DEPOT_PATH.") | |
end) | |
end | |
String(r::RelocPath) = r.getpath() # dynamically dispatches since getpath isn 't concrete :/ |
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 don't love this. What if someone has modified Base.DEPOT_PATH
during their Julia session?
function show(io::IO, r::RelocPath) | ||
print(io, string("RelocPath(\"@depot", r.subpath, "\")")) | ||
end |
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.
This is pretty inaccurate, since it doesn't support @depot
function show(io::IO, r::RelocPath) | |
print(io, string("RelocPath(\"@depot", r.subpath, "\")")) | |
end |
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.
How about we allow RelocPath to accept paths that are literally @depot/foo/bar
?
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.
Also, as far as the original show
method goes, I think that the meaning of @depot/
is reasonably easy to understand here.
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.
This is pretty inaccurate, since it doesn't support @depot
But it does behave like a @depot
. (it behaves more like include_dependency
than include
to be precise)
What is inaccurate is that show
assumes that nobody tinkered with DEPOT_PATH
since construction.
Should we just call this |
No strong feelings from my side. |
I also don't feel strongly between We could also do |
RelocPath(path)
works by splittingpath
asdepot/subpath
based onDEPOT_PATH
during construction.When using
RelocPath
one explicitly opts into relocation, so it throws whenpath
cannot be split.A relocated path can be queried with
String(r::RelocPath)
, which also throws on failure.Fixes #54430
Alternative to #55146