Closed juftin closed 9 months ago
Looking at this closer I think I've got the issue figured out, there were leading slashes being passed down to the GithubFilesystem that it didn't like. The following code looks to have resolved the issue without the need to customize the GitHubPath
further:
import upath
from upath import UPath, registry
from upath.core import _FSSpecAccessor
class _GitHubAccessor(_FSSpecAccessor):
"""
FSSpec Accessor for GitHub
"""
def _format_path(self, path: UPath) -> str:
"""
Remove the leading slash from the path
"""
return path._path.strip("/")
class GitHubPath(UPath):
"""
GitHubPath supporting the fsspec.GitHubFileSystem
"""
_default_accessor = _GitHubAccessor
With that being said, are you interested in a GitHub implementation for upath
and are there any issues you see with the example in this comment? I'm happy to contribute if so. Thanks again for the fantastic library
Hi @juftin
Thanks for reporting the issue! We're keeping up with the changes in pathlib, and will probably reach a stable interface with python 3.13 that can then be back-ported. In the meantime we're trying the best to not break external UPath subclasses, but can't fully guarantee.
That being said, the best way to ensure your custom implementation will keep on working is to add it to universal_pathlib 😃 So yes, it would be great if you could make a PR.
I wrote some instructions here on how to add new implementations: https://github.com/fsspec/universal_pathlib/issues/117#issuecomment-1641532209
In addition to your suggested changes above, you would need to add a test that derives from the BaseTests class and does the setup. I would probably try to use the universal_pathlib repo for the tests.
Let me know if you need any further advice. If you get stuck, feel free to open a draft PR for discussion.
Cheers, Andreas
Closed via 8314a65746c4d62c9263d7d98007a8b54f971dc5
I've got a couple projects, browsr and textual-universal-directorytree, that leverage
universal-pathlib
for a TUI file browser. I started working on updating dependencies yesterday and noticed an incompatibility with the new version ofuniversal-pathlib
: my custom implementation ofUPath
forfsspec
's GithubFileSystem stopped working after the release of0.1.0
. In particular, the methodis_dir()
is what broke on instances of theGitHubPath
:The following code, I'm calling it
example.py
, will correctly know that upath is a directory prior to0.1.0
but will get this wrong after:0.0.23 Output:
0.1.3 Output:
I know that GitHub isn't a supported
upath
implementation yet so I understand if you're unable to support this issue, I'd also like to get it added if that's something you're interested in. I'm happy to share code or submit a PR where I can - right now I'm just stuck on trying to figure out exactly what changed.