Skip to content

Commit e34a70a

Browse files
authored
Make paramiko an optional dependency (#3584)
Removed paramiko from requirements.txt and added it as an optional module in setup.py. Added OptionalModuleMissing errors for the ssh channel files for when usage is attempted without the required paramiko module being installed. Changed Behaviour: If users have code that depends on the ssh channels, they may need to opt in to that module. Prepares for #3515
1 parent ffb3644 commit e34a70a

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

parsl/channels/oauth_ssh/oauth_ssh.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import logging
22
import socket
33

4-
import paramiko
5-
64
from parsl.channels.ssh.ssh import DeprecatedSSHChannel
75
from parsl.errors import OptionalModuleMissing
86

7+
try:
8+
import paramiko
9+
_ssh_enabled = True
10+
except (ImportError, NameError, FileNotFoundError):
11+
_ssh_enabled = False
12+
913
try:
1014
from oauth_ssh.oauth_ssh_token import find_access_token
1115
from oauth_ssh.ssh_service import SSHService
@@ -38,6 +42,10 @@ def __init__(self, hostname, username=None, script_dir=None, envs=None, port=22)
3842
3943
Raises:
4044
'''
45+
if not _ssh_enabled:
46+
raise OptionalModuleMissing(['ssh'],
47+
"OauthSSHChannel requires the ssh module and config.")
48+
4149
if not _oauth_ssh_enabled:
4250
raise OptionalModuleMissing(['oauth_ssh'],
4351
"OauthSSHChannel requires oauth_ssh module and config.")

parsl/channels/ssh/ssh.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import logging
33
import os
44

5-
import paramiko
6-
75
from parsl.channels.base import Channel
86
from parsl.channels.errors import (
97
AuthException,
@@ -13,15 +11,24 @@
1311
FileCopyException,
1412
SSHException,
1513
)
14+
from parsl.errors import OptionalModuleMissing
1615
from parsl.utils import RepresentationMixin
1716

17+
try:
18+
import paramiko
19+
_ssh_enabled = True
20+
except (ImportError, NameError, FileNotFoundError):
21+
_ssh_enabled = False
22+
23+
1824
logger = logging.getLogger(__name__)
1925

2026

21-
class NoAuthSSHClient(paramiko.SSHClient):
22-
def _auth(self, username, *args):
23-
self._transport.auth_none(username)
24-
return
27+
if _ssh_enabled:
28+
class NoAuthSSHClient(paramiko.SSHClient):
29+
def _auth(self, username, *args):
30+
self._transport.auth_none(username)
31+
return
2532

2633

2734
class DeprecatedSSHChannel(Channel, RepresentationMixin):
@@ -53,6 +60,9 @@ def __init__(self, hostname, username=None, password=None, script_dir=None, envs
5360
5461
Raises:
5562
'''
63+
if not _ssh_enabled:
64+
raise OptionalModuleMissing(['ssh'],
65+
"SSHChannel requires the ssh module and config.")
5666

5767
self.hostname = hostname
5868
self.username = username

parsl/channels/ssh_il/ssh_il.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import getpass
22
import logging
33

4-
import paramiko
5-
64
from parsl.channels.ssh.ssh import DeprecatedSSHChannel
5+
from parsl.errors import OptionalModuleMissing
6+
7+
try:
8+
import paramiko
9+
_ssh_enabled = True
10+
except (ImportError, NameError, FileNotFoundError):
11+
_ssh_enabled = False
12+
713

814
logger = logging.getLogger(__name__)
915

@@ -30,6 +36,10 @@ def __init__(self, hostname, username=None, password=None, script_dir=None, envs
3036
3137
Raises:
3238
'''
39+
if not _ssh_enabled:
40+
raise OptionalModuleMissing(['ssh'],
41+
"SSHInteractiveLoginChannel requires the ssh module and config.")
42+
3343
self.hostname = hostname
3444
self.username = username
3545
self.password = password

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ globus-sdk
1212
dill
1313
tblib
1414
requests
15-
paramiko
1615
psutil>=5.5.1
1716
setproctitle
1817
filelock>=3.13,<4

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'flux': ['pyyaml', 'cffi', 'jsonschema'],
3636
'proxystore': ['proxystore'],
3737
'radical-pilot': ['radical.pilot==1.60', 'radical.utils==1.60'],
38+
'ssh': ['paramiko'],
3839
# Disabling psi-j since github direct links are not allowed by pypi
3940
# 'psij': ['psi-j-parsl@git+https://github.com/ExaWorks/psi-j-parsl']
4041
}

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
flake8==6.1.0
22
ipyparallel
33
pandas
4+
paramiko
45
pytest>=7.4.0,<8
56
pytest-cov
67
pytest-random-order

0 commit comments

Comments
 (0)