Comments (6)
I also think that this should be addresses on the fsspec
side.
The upath side seems to work consistently. So, you could replace
path = UPath("file:///opt/foo/bar")
fs.ls(path)
with
path = UPath("file:///opt/foo/bar")
path.iterdir()
from universal_pathlib.
My understanding is that this is correct (as of Feb 2017), as RFC8089 has made the entire authority component of a file URI, including the double slashes, optional.
A file URL takes the form:
file://<host>/<path>
When the are 3 slashes after the file:
schema, this means that the host has been omitted from the URI. If the host is blank, the double slash preceding it is not required, so universal_pathlib
doesn't include it when formatting the path.
If you include an authority component (i.e. a server name) in your file URI, you will see that all three slashes get printed - the two before the server name, and the one at the start of the path:
>>> print(UPath("file://localhost/usr"))
file://localhost/usr
from universal_pathlib.
@joouha Ah ok this makes sense thank you!
The reason I hit the issue was that I have some code using fsspec to handle various file operations. That code gets file URLs from elsewhere, and I'd like to be able to pass them UPath's instead because that seems convenient. But if I have
path = UPath("file:///opt/foo/bar")
fs.ls(path)
Fails because the cutting of the slashes means fs
treats it as a relative path (with "file:" being part of the path) and looks for ./file:/opt/foo/bar
Whereas if I use the string directly with the triple slashes:
fs.ls("file:///opt/foo/bar")
Then this gets treated as an absolute path and is handled correctly by fs
.
The first snippet with UPath
works whenever the path is s3/gcp/anything else, and it feels like that's how it's meant to be used. So maybe the issue is in a discrepancy in how fsspec handles these single slash paths?
from universal_pathlib.
Yep how the strip protocol works in fsspec's Local implementation treats a single slash and triple slash differently:
https://github.com/fsspec/filesystem_spec/blob/master/fsspec/implementations/local.py#L213-L217
Happy to close this issue out if you think I should open an issue in filesystem_spec
?
from universal_pathlib.
Personally I think this ought to be fixed in fsspec
- but I'm not a maintainer here
from universal_pathlib.
Gotcha makes sense, I'll put a PR in on the fsspec
side, thanks!
from universal_pathlib.
Related Issues (20)
- Adhere to semver and add a changelog
- UPath broken in Python 3.11
- The noxfile has to be changed to support newer nox versions
- UPath with_name, with_stem, with_suffix is broken
- Glob on s3 bucket should be coherent with other implementations? HOT 5
- mkdir does not respect exist_ok when parents is set to True
- Accessing the underlying filesystem HOT 8
- URI paths are incorrectly parsed as posix paths HOT 3
- Updating admins/maintainers HOT 3
- Use `urllib.parse.urljoin` when joining paths HOT 5
- Support for data URI scheme? HOT 5
- Should `UPath.__new__` return `pathlib.Path` instances for local paths HOT 16
- Should the `UPath` public class API be identical to the public `pathlib.Path` class API HOT 2
- URI query component is ignored when opening a file HOT 5
- Inconsistency with Path HOT 3
- `joinpath` does not update url
- Refactor tests HOT 3
- Updating package dev tools HOT 4
- Add ability to register custom UPath implementations HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from universal_pathlib.