Skip to content

Commit

Permalink
Add GitHubPath
Browse files Browse the repository at this point in the history
  • Loading branch information
juftin authored Oct 12, 2023
1 parent 7e3836d commit d5e7a15
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
25 changes: 25 additions & 0 deletions upath/implementations/github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
GitHub implementation of UPath
"""

import upath.core


class _GitHubAccessor(upath.core._FSSpecAccessor):
"""
FSSpecAccessor for GitHub
"""

def _format_path(self, path: upath.core.UPath) -> str:
"""
Remove the leading slash from the path
"""
return path._path.lstrip("/")


class GitHubPath(upath.core.UPath):
"""
GitHubPath supporting the fsspec.GitHubFileSystem
"""

_default_accessor = _GitHubAccessor
1 change: 1 addition & 0 deletions upath/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class _Registry(MutableMapping[str, "type[upath.core.UPath]"]):
"s3a": "upath.implementations.cloud.S3Path",
"webdav+http": "upath.implementations.webdav.WebdavPath",
"webdav+https": "upath.implementations.webdav.WebdavPath",
"github": "upath.implementations.github.GitHubPath",
}

def __init__(self) -> None:
Expand Down
26 changes: 26 additions & 0 deletions upath/tests/implementations/test_github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from upath import UPath
from upath.implementations.github import GitHubPath
from upath.tests.cases import BaseTests


class TestUPathGitHubPath(BaseTests):
"""
Unit-tests for the GitHubPath implementation of UPath.
"""

@pytest.fixture(autouse=True)
def path(self, local_testdir, hdfs):
"""
Fixture for the UPath instance to be tested.
"""
host, user, port = hdfs
path = "github://fsspec:universal_pathlib@main"
self.path = UPath(path)

def test_is_GitHubPath(self):
"""
Test that the path is a GitHubPath instance.
"""
assert isinstance(self.path, GitHubPath)
1 change: 1 addition & 0 deletions upath/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"s3a",
"webdav+http",
"webdav+https",
"github",
}


Expand Down

0 comments on commit d5e7a15

Please sign in to comment.