Skip to content

Commit

Permalink
fixed many warnings of rtd
Browse files Browse the repository at this point in the history
  • Loading branch information
khsrali committed Dec 11, 2024
1 parent 482eeca commit 5e29e5b
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 159 deletions.
1 change: 1 addition & 0 deletions src/aiida/transports/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'AsyncTransport',
'SshTransport',
'Transport',
'TransportPath',
'convert_to_bool',
'parse_sshconfig',
)
Expand Down
139 changes: 70 additions & 69 deletions src/aiida/transports/plugins/ssh_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@

import asyncssh
import click
from asyncssh import SFTPFileAlreadyExists, SFTPOpUnsupported
from asyncssh import SFTPFileAlreadyExists

from aiida.common.escaping import escape_for_bash
from aiida.common.exceptions import InvalidOperation

from ..transport import AsyncTransport, Transport, TransportInternalError, TransportPath, path_to_str
from aiida.transports.transport import AsyncTransport, Transport, TransportInternalError, TransportPath, path_to_str

__all__ = ('AsyncSshTransport',)

Expand Down Expand Up @@ -160,8 +159,8 @@ async def get_async(
:param preserve: preserve file attributes
Default = False
:type remotepath: TransportPath
:type localpath: TransportPath
:type remotepath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type localpath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type dereference: bool
:type overwrite: bool
:type ignore_nonexisting: bool
Expand Down Expand Up @@ -240,8 +239,8 @@ async def getfile_async(
:param preserve: preserve file attributes
Default = False
:type remotepath: TransportPath
:type localpath: TransportPath
:type remotepath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type localpath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type dereference: bool
:type overwrite: bool
:type preserve: bool
Expand Down Expand Up @@ -290,8 +289,8 @@ async def gettree_async(
:param preserve: preserve file attributes
Default = False
:type remotepath: TransportPath
:type localpath: TransportPath
:type remotepath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type localpath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type dereference: bool
:type overwrite: bool
:type preserve: bool
Expand Down Expand Up @@ -363,8 +362,8 @@ async def put_async(
:param preserve: preserve file attributes
Default = False
:type remotepath: TransportPath
:type localpath: TransportPath
:type remotepath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type localpath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type dereference: bool
:type overwrite: bool
:type ignore_nonexisting: bool
Expand Down Expand Up @@ -443,8 +442,8 @@ async def putfile_async(
:param preserve: preserve file attributes
Default = False
:type remotepath: TransportPath
:type localpath: TransportPath
:type remotepath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type localpath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type dereference: bool
:type overwrite: bool
:type preserve: bool
Expand Down Expand Up @@ -494,8 +493,8 @@ async def puttree_async(
:param preserve: preserve file attributes
Default = False
:type localpath: TransportPath
:type remotepath: TransportPath
:type localpath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type remotepath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type dereference: bool
:type overwrite: bool
:type preserve: bool
Expand Down Expand Up @@ -562,8 +561,8 @@ async def copy_async(
:param preserve: preserve file attributes
Default = False
:type remotesource: TransportPath
:type remotedestination: TransportPath
:type remotesource: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type remotedestination: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type dereference: bool
:type recursive: bool
:type preserve: bool
Expand All @@ -586,30 +585,31 @@ async def copy_async(
# For performance reasons, we should check if the remote copy is supported, if so use
# self._sftp.mcopy() & self._sftp.copy() otherwise send a `cp` command to the remote machine.
# See here: https://github.com/ronf/asyncssh/issues/724
try:
if self.has_magic(remotesource):
await self._sftp.mcopy(
remotesource,
remotedestination,
preserve=preserve,
recurse=recursive,
follow_symlinks=dereference,
remote_only=True,
)
else:
if not await self.path_exists_async(remotesource):
raise OSError(f'The remote path {remotesource} does not exist')
await self._sftp.copy(
remotesource,
remotedestination,
preserve=preserve,
recurse=recursive,
follow_symlinks=dereference,
remote_only=True,
)
except asyncssh.sftp.SFTPFailure as exc:
raise OSError(f'Error while copying {remotesource} to {remotedestination}: {exc}')
except SFTPOpUnsupported:
if self._sftp.supports_remote_copy:
try:
if self.has_magic(remotesource):
await self._sftp.mcopy(

Check warning on line 591 in src/aiida/transports/plugins/ssh_async.py

View check run for this annotation

Codecov / codecov/patch

src/aiida/transports/plugins/ssh_async.py#L589-L591

Added lines #L589 - L591 were not covered by tests
remotesource,
remotedestination,
preserve=preserve,
recurse=recursive,
follow_symlinks=dereference,
remote_only=True,
)
else:
if not await self.path_exists_async(remotesource):
raise OSError(f'The remote path {remotesource} does not exist')
await self._sftp.copy(

Check warning on line 602 in src/aiida/transports/plugins/ssh_async.py

View check run for this annotation

Codecov / codecov/patch

src/aiida/transports/plugins/ssh_async.py#L600-L602

Added lines #L600 - L602 were not covered by tests
remotesource,
remotedestination,
preserve=preserve,
recurse=recursive,
follow_symlinks=dereference,
remote_only=True,
)
except asyncssh.sftp.SFTPFailure as exc:
raise OSError(f'Error while copying {remotesource} to {remotedestination}: {exc}')

Check warning on line 611 in src/aiida/transports/plugins/ssh_async.py

View check run for this annotation

Codecov / codecov/patch

src/aiida/transports/plugins/ssh_async.py#L610-L611

Added lines #L610 - L611 were not covered by tests
else:
self.logger.warning('The remote copy is not supported, using the `cp` command to copy the file/folder')
# I copy pasted the whole logic below from SshTransport class:

Expand Down Expand Up @@ -681,8 +681,8 @@ async def copyfile_async(
:param preserve: preserve file attributes
Default = False
:type remotesource: TransportPath
:type remotedestination: TransportPath
:type remotesource: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type remotedestination: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type dereference: bool
:type preserve: bool
Expand All @@ -705,8 +705,8 @@ async def copytree_async(
:param preserve: preserve file attributes
Default = False
:type remotesource: TransportPath
:type remotedestination: TransportPath
:type remotesource: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type remotedestination: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type dereference: bool
:type preserve: bool
Expand Down Expand Up @@ -738,8 +738,8 @@ async def exec_command_wait_async(
:type command: str
:type stdin: str
:type encoding: str
:type workdir: Optional[TransportPath]
:type timeout: Optional[float]
:type workdir: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type timeout: float
:return: a tuple with the return code, the stdout and the stderr of the command
:rtype: tuple(int, str, str)
Expand Down Expand Up @@ -776,7 +776,7 @@ async def get_attribute_async(self, path: TransportPath):
:param path: path to file
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:return: object FixedFieldsAttributeDict
"""
Expand Down Expand Up @@ -809,7 +809,7 @@ async def isdir_async(self, path: TransportPath):
:param path: the absolute path to check
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:return: True if the path is a directory, False otherwise
"""
Expand All @@ -827,7 +827,7 @@ async def isfile_async(self, path: TransportPath):
:param path: the absolute path to check
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:return: True if the path is a file, False otherwise
"""
Expand All @@ -848,7 +848,7 @@ async def listdir_async(self, path: TransportPath, pattern=None):
:param pattern: if used, listdir returns a list of files matching
filters in Unix style. Unix only.
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:return: a list of strings
"""
Expand Down Expand Up @@ -876,7 +876,7 @@ async def listdir_withattributes_async(self, path: TransportPath, pattern: Optio
:param pattern: if used, listdir returns a list of files matching
filters in Unix style. Unix only.
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type pattern: str
:return: a list of dictionaries, one per entry.
The schema of the dictionary is
Expand Down Expand Up @@ -911,7 +911,7 @@ async def makedirs_async(self, path, ignore_existing=False):
:param bool ignore_existing: if set to true, it doesn't give any error
if the leaf directory does already exist
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:raises: OSError, if directory at path already exists
"""
Expand All @@ -934,7 +934,7 @@ async def mkdir_async(self, path: TransportPath, ignore_existing=False):
:param bool ignore_existing: if set to true, it doesn't give any error
if the leaf directory does already exist
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:raises: OSError, if directory at path already exists
"""
Expand Down Expand Up @@ -965,7 +965,7 @@ async def remove_async(self, path: TransportPath):
:param path: path to file to remove
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:raise OSError: if the path is a directory
"""
Expand All @@ -984,8 +984,8 @@ async def rename_async(self, oldpath: TransportPath, newpath: TransportPath):
:param oldpath: existing name of the file or folder
:param newpath: new name for the file or folder
:type oldpath: TransportPath
:type newpath: TransportPath
:type oldpath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type newpath: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:raises OSError: if oldpath/newpath is not found
:raises ValueError: if oldpath/newpath is not a valid string
Expand All @@ -1006,7 +1006,7 @@ async def rmdir_async(self, path: TransportPath):
:param str path: absolute path to the folder to remove
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
"""
path = path_to_str(path)
try:
Expand All @@ -1019,7 +1019,7 @@ async def rmtree_async(self, path: TransportPath):
:param str path: absolute path to the folder to remove
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:raises OSError: if the operation fails
"""
Expand All @@ -1034,7 +1034,7 @@ async def path_exists_async(self, path: TransportPath):
:param path: path to check
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
"""
path = path_to_str(path)
return await self._sftp.exists(path)
Expand Down Expand Up @@ -1065,8 +1065,8 @@ async def symlink_async(self, remotesource: TransportPath, remotedestination: Tr
:param remotesource: absolute path to remote source
:param remotedestination: absolute path to remote destination
:type remotesource: TransportPath
:type remotedestination: TransportPath
:type remotesource: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type remotedestination: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:raises ValueError: if remotedestination has patterns
"""
Expand Down Expand Up @@ -1095,7 +1095,7 @@ async def glob_async(self, pathname: TransportPath):
:param pathname: the pathname pattern to match.
It should only be absolute path.
:type pathname: TransportPath
:type pathname: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:return: a list of paths matching the pattern.
"""
Expand All @@ -1109,7 +1109,7 @@ async def chmod_async(self, path: TransportPath, mode: int, follow_symlinks: boo
:param mode: the new permissions
:param bool follow_symlinks: if True, follow symbolic links
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type mode: int
:type follow_symlinks: bool
Expand All @@ -1130,7 +1130,7 @@ async def chown_async(self, path: TransportPath, uid: int, gid: int):
:param uid: the new owner id
:param gid: the new group id
:type path: TransportPath
:type path: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type uid: int
:type gid: int
Expand Down Expand Up @@ -1159,9 +1159,10 @@ async def copy_from_remote_to_remote_async(
:param kwargs: keyword parameters passed to the call to transportdestination.put,
except for 'dereference' that is passed to self.get
:type transportdestination: Union['Transport', 'AsyncTransport']
:type remotesource: TransportPath
:type remotedestination: TransportPath
:type transportdestination: :class:`Transport <aiida.transports.transport.Transport>`,
or :class:`AsyncTransport <aiida.transports.transport.AsyncTransport>`
:type remotesource: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
:type remotedestination: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
.. note:: the keyword 'dereference' SHOULD be set to False for the
final put (onto the destination), while it can be set to the
Expand Down Expand Up @@ -1210,7 +1211,7 @@ def gotocomputer_command(self, remotedir: TransportPath):
:param remotedir: the remote directory to connect to
:type remotedir: TransportPath
:type remotedir: :class:`Path <pathlib.Path>`, :class:`PurePosixPath <pathlib.PurePosixPath>`, or `str`
"""
connect_string = self._gotocomputer_string(remotedir)
cmd = f'ssh -t {self.machine} {connect_string}'
Expand Down
Loading

0 comments on commit 5e29e5b

Please sign in to comment.