Skip to content

Commit

Permalink
Add GitHubPath (#155)
Browse files Browse the repository at this point in the history
Co-authored-by: juftin <juftin@juftin.com>
Co-authored-by: ap-- <andreas@poehlmann.io>
  • Loading branch information
3 people committed Feb 8, 2024
1 parent 5c240c1 commit 8314a65
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
23 changes: 23 additions & 0 deletions upath/implementations/github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
GitHub file system implementation
"""

import upath.core


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

@property
def path(self) -> str:
pth = super().path
if pth == ".":
return ""
return pth

def iterdir(self):
if self.is_file():
raise NotADirectoryError(str(self))
yield from super().iterdir()
1 change: 1 addition & 0 deletions upath/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class _Registry(MutableMapping[str, "type[upath.UPath]"]):
"webdav": "upath.implementations.webdav.WebdavPath",
"webdav+http": "upath.implementations.webdav.WebdavPath",
"webdav+https": "upath.implementations.webdav.WebdavPath",
"github": "upath.implementations.github.GitHubPath",
}

if TYPE_CHECKING:
Expand Down
71 changes: 71 additions & 0 deletions upath/tests/implementations/test_github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import os
import platform
import sys

import pytest

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

pytestmark = pytest.mark.skipif(
os.environ.get("CI")
and (sys.version_info not in {(3, 8), (3, 12)} and platform.system() != "Linux"),
reason="Skipping GitHubPath tests to prevent rate limiting on GitHub API.",
)


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

@pytest.fixture(autouse=True)
def path(self):
"""
Fixture for the UPath instance to be tested.
"""
path = "github://ap--:universal_pathlib@test_data/data"
self.path = UPath(path)

def test_is_GitHubPath(self):
"""
Test that the path is a GitHubPath instance.
"""
assert isinstance(self.path, GitHubPath)

@pytest.mark.skip(reason="GitHub filesystem is read-only")
def test_mkdir(self):
pass

@pytest.mark.skip(reason="GitHub filesystem is read-only")
def test_mkdir_exists_ok_false(self):
pass

@pytest.mark.skip(reason="GitHub filesystem is read-only")
def test_mkdir_parents_true_exists_ok_false(self):
pass

@pytest.mark.skip(reason="GitHub filesystem is read-only")
def test_rename(self):
pass

@pytest.mark.skip(reason="GitHub filesystem is read-only")
def test_rename2(self):
pass

@pytest.mark.skip(reason="GitHub filesystem is read-only")
def test_touch_unlink(self):
pass

@pytest.mark.skip(reason="GitHub filesystem is read-only")
def test_write_bytes(self):
pass

@pytest.mark.skip(reason="GitHub filesystem is read-only")
def test_write_text(self):
pass

@pytest.mark.skip(reason="GitHub filesystem is read-only")
def test_fsspec_compat(self):
pass
1 change: 1 addition & 0 deletions upath/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"webdav",
"webdav+http",
"webdav+https",
"github",
}


Expand Down

0 comments on commit 8314a65

Please sign in to comment.