Skip to content

Commit db69cdc

Browse files
committed
split os.path from os
1 parent 123b18b commit db69cdc

File tree

10 files changed

+324
-275
lines changed

10 files changed

+324
-275
lines changed

ssh_utilities/abstract/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from ._builtins import BuiltinsABC
44
from ._connection import ConnectionABC
5-
from ._os import OsABC, OsPathABC, DirEntryABC
5+
from ._os import OsABC, DirEntryABC
6+
from ._os_path import OsPathABC
67
from ._pathlib import PathlibABC
78
from ._shutil import ShutilABC
89
from ._subprocess import SubprocessABC

ssh_utilities/abstract/_os.py

Lines changed: 3 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Template module for all os classes."""
1+
"""Template module for all os classes and methods."""
22

33
import logging
44
from abc import ABC, abstractmethod
@@ -8,7 +8,7 @@
88
from ..typeshed import _ONERROR, _SPATH
99
from . import _ATTRIBUTES
1010

11-
__all__ = ["OsPathABC", "OsABC", "DirEntryABC"]
11+
__all__ = ["OsABC", "DirEntryABC"]
1212

1313
logging.getLogger(__name__)
1414

@@ -117,162 +117,6 @@ def stat(self, *, follow_symlinks: bool = True) -> "_ATTRIBUTES":
117117
raise NotImplementedError
118118

119119

120-
class OsPathABC(ABC):
121-
"""`os.path` module drop-in replacement base."""
122-
123-
__name__: str
124-
__abstractmethods__: FrozenSet[str]
125-
126-
@abstractmethod
127-
def isfile(self, path: "_SPATH") -> bool:
128-
"""Check if path points to a file.
129-
130-
Parameters
131-
----------
132-
path: :const:`ssh_utilities.typeshed._SPATH`
133-
path to check
134-
135-
Returns
136-
-------
137-
bool
138-
check result
139-
140-
Raises
141-
------
142-
IOError
143-
if file could not be accessed
144-
"""
145-
raise NotImplementedError
146-
147-
@abstractmethod
148-
def isdir(self, path: "_SPATH") -> bool:
149-
"""Check if path points to directory.
150-
151-
Parameters
152-
----------
153-
path: :const:`ssh_utilities.typeshed._SPATH`
154-
path to check
155-
156-
Returns
157-
-------
158-
bool
159-
check result
160-
161-
Raises
162-
------
163-
IOError
164-
if dir could not be accessed
165-
"""
166-
raise NotImplementedError
167-
168-
@abstractmethod
169-
def exists(self, path: "_SPATH") -> bool:
170-
"""Check if path exists in filesystem.
171-
172-
Parameters
173-
----------
174-
path: :const:`ssh_utilities.typeshed._SPATH`
175-
path to check
176-
177-
Returns
178-
-------
179-
bool
180-
check result
181-
"""
182-
raise NotImplementedError
183-
184-
@abstractmethod
185-
def islink(self, path: "_SPATH") -> bool:
186-
"""Check if path points to symbolic link.
187-
188-
Parameters
189-
----------
190-
path: :const:`ssh_utilities.typeshed._SPATH`
191-
path to check
192-
193-
Returns
194-
-------
195-
bool
196-
check result
197-
198-
Raises
199-
------
200-
IOError
201-
if dir could not be accessed
202-
"""
203-
raise NotImplementedError
204-
205-
@abstractmethod
206-
def realpath(self, path: "_SPATH") -> str:
207-
"""Return the canonical path of the specified filename.
208-
209-
Eliminates any symbolic links encountered in the path.
210-
211-
Parameters
212-
----------
213-
path : :const:`ssh_utilities.typeshed._SPATH`
214-
path to resolve
215-
216-
Returns
217-
-------
218-
str
219-
string representation of the resolved path
220-
"""
221-
raise NotImplementedError
222-
223-
@abstractmethod
224-
def getsize(self, path: "_SPATH") -> int:
225-
"""Return the size of path in bytes.
226-
227-
Parameters
228-
----------
229-
path : :const:`ssh_utilities.typeshed._SPATH`
230-
path to file/directory
231-
232-
Returns
233-
-------
234-
int
235-
size in bytes
236-
237-
Raises
238-
------
239-
OsError
240-
if the file does not exist or is inaccessible
241-
"""
242-
raise NotImplementedError
243-
244-
@abstractmethod
245-
def join(self, path: "_SPATH", *paths: "_SPATH") -> str:
246-
"""Join one or more path components intelligently.
247-
248-
The return value is the concatenation of path and any members of
249-
*paths with exactly one directory separator following each non-empty
250-
part except the last, meaning that the result will only end
251-
in a separator if the last part is empty. If a component is
252-
an absolute path, all previous components are thrown away and
253-
joining continues from the absolute path component. On Windows,
254-
the drive letter is not reset when an absolute path component
255-
(e.g., 'foo') is encountered. If a component contains a drive letter,
256-
all previous components are thrown away and the drive letter is reset.
257-
Note that since there is a current directory for each drive,
258-
os.path.join("c:", "foo") represents a path relative to the current
259-
directory on drive C: (c:foo), not c:/foo.
260-
261-
Parameters
262-
----------
263-
path : :const:`ssh_utilities.typeshed._SPATH`
264-
the starting path part
265-
*paths : :const:`ssh_utilities.typeshed._SPATH`
266-
path parts to join to the first one
267-
268-
Returns
269-
-------
270-
str
271-
joined path parts
272-
"""
273-
raise NotImplementedError
274-
275-
276120
class OsABC(ABC, Generic[_Os1, _Os2, _Os3, _Os4, _Os5, _Os6]):
277121
"""`os` module drop-in replacement base."""
278122

@@ -454,7 +298,7 @@ def replace(self, src: "_SPATH", dst: "_SPATH", *,
454298
------
455299
OsError
456300
If dst is a directory, the operation will fail with an OSError,
457-
301+
458302
Warnings
459303
--------
460304
If dst exists and is a file, it will be replaced silently

ssh_utilities/abstract/_os_path.py

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
"""Template module for all os.path classes and methods."""
2+
3+
import logging
4+
from abc import ABC, abstractmethod
5+
from typing import TYPE_CHECKING, FrozenSet
6+
7+
if TYPE_CHECKING:
8+
from ..typeshed import _SPATH
9+
10+
__all__ = ["OsPathABC"]
11+
12+
logging.getLogger(__name__)
13+
14+
15+
class OsPathABC(ABC):
16+
"""`os.path` module drop-in replacement base."""
17+
18+
__name__: str
19+
__abstractmethods__: FrozenSet[str]
20+
21+
@abstractmethod
22+
def isfile(self, path: "_SPATH") -> bool:
23+
"""Check if path points to a file.
24+
25+
Parameters
26+
----------
27+
path: :const:`ssh_utilities.typeshed._SPATH`
28+
path to check
29+
30+
Returns
31+
-------
32+
bool
33+
check result
34+
35+
Raises
36+
------
37+
IOError
38+
if file could not be accessed
39+
"""
40+
raise NotImplementedError
41+
42+
@abstractmethod
43+
def isdir(self, path: "_SPATH") -> bool:
44+
"""Check if path points to directory.
45+
46+
Parameters
47+
----------
48+
path: :const:`ssh_utilities.typeshed._SPATH`
49+
path to check
50+
51+
Returns
52+
-------
53+
bool
54+
check result
55+
56+
Raises
57+
------
58+
IOError
59+
if dir could not be accessed
60+
"""
61+
raise NotImplementedError
62+
63+
@abstractmethod
64+
def exists(self, path: "_SPATH") -> bool:
65+
"""Check if path exists in filesystem.
66+
67+
Parameters
68+
----------
69+
path: :const:`ssh_utilities.typeshed._SPATH`
70+
path to check
71+
72+
Returns
73+
-------
74+
bool
75+
check result
76+
"""
77+
raise NotImplementedError
78+
79+
@abstractmethod
80+
def islink(self, path: "_SPATH") -> bool:
81+
"""Check if path points to symbolic link.
82+
83+
Parameters
84+
----------
85+
path: :const:`ssh_utilities.typeshed._SPATH`
86+
path to check
87+
88+
Returns
89+
-------
90+
bool
91+
check result
92+
93+
Raises
94+
------
95+
IOError
96+
if dir could not be accessed
97+
"""
98+
raise NotImplementedError
99+
100+
@abstractmethod
101+
def realpath(self, path: "_SPATH") -> str:
102+
"""Return the canonical path of the specified filename.
103+
104+
Eliminates any symbolic links encountered in the path.
105+
106+
Parameters
107+
----------
108+
path : :const:`ssh_utilities.typeshed._SPATH`
109+
path to resolve
110+
111+
Returns
112+
-------
113+
str
114+
string representation of the resolved path
115+
"""
116+
raise NotImplementedError
117+
118+
@abstractmethod
119+
def getsize(self, path: "_SPATH") -> int:
120+
"""Return the size of path in bytes.
121+
122+
Parameters
123+
----------
124+
path : :const:`ssh_utilities.typeshed._SPATH`
125+
path to file/directory
126+
127+
Returns
128+
-------
129+
int
130+
size in bytes
131+
132+
Raises
133+
------
134+
OsError
135+
if the file does not exist or is inaccessible
136+
"""
137+
raise NotImplementedError
138+
139+
@abstractmethod
140+
def join(self, path: "_SPATH", *paths: "_SPATH") -> str:
141+
"""Join one or more path components intelligently.
142+
143+
The return value is the concatenation of path and any members of
144+
*paths with exactly one directory separator following each non-empty
145+
part except the last, meaning that the result will only end
146+
in a separator if the last part is empty. If a component is
147+
an absolute path, all previous components are thrown away and
148+
joining continues from the absolute path component. On Windows,
149+
the drive letter is not reset when an absolute path component
150+
(e.g., 'foo') is encountered. If a component contains a drive letter,
151+
all previous components are thrown away and the drive letter is reset.
152+
Note that since there is a current directory for each drive,
153+
os.path.join("c:", "foo") represents a path relative to the current
154+
directory on drive C: (c:foo), not c:/foo.
155+
156+
Parameters
157+
----------
158+
path : :const:`ssh_utilities.typeshed._SPATH`
159+
the starting path part
160+
*paths : :const:`ssh_utilities.typeshed._SPATH`
161+
path parts to join to the first one
162+
163+
Returns
164+
-------
165+
str
166+
joined path parts
167+
"""
168+
raise NotImplementedError

ssh_utilities/local/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
# ! preserve this order otherwise import fail
44
from ._os import Os
5+
from ._os_path import OsPath
56
from ._builtins import Builtins
67
from ._pathlib import Pathlib
78
from ._shutil import Shutil
89
from ._subprocess import Subprocess
910
from .local import LocalConnection
1011

1112
__all__ = ["LocalConnection", "Builtins", "Os", "Pathlib", "Shutil",
12-
"Subprocess"]
13+
"Subprocess", "OsPath"]

0 commit comments

Comments
 (0)