Skip to content

[WIP] Move fs.sshfs to it's own sshfs namespace #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ nosetests.xml
coverage.xml
*,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
Expand Down
8 changes: 4 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ classifiers =
zip_safe = true
include_package_data = true
python_requires = >= 2.7, != 3.0.*, != 3.1.*, != 3.2.*, != 3.3.*
packages = fs.sshfs, fs.opener
packages = sshfs
test_suite = tests
setup_requires = setuptools
install_requires =
Expand All @@ -55,8 +55,8 @@ test =

[options.entry_points]
fs.opener =
ssh = fs.opener.sshfs:SSHOpener
sftp = fs.opener.sshfs:SSHOpener
ssh = sshfs.opener:SSHOpener
sftp = sshfs.opener:SSHOpener

[coverage:report]
show_missing = true
Expand All @@ -73,7 +73,7 @@ exclude_lines =
verbosity = 2
with-coverage = true
cover-xml = true
cover-package = fs.sshfs, fs.opener.sshfs
cover-package = sshfs._sshfs, sshfs.opener
with-doctest = true
doctest-extension = .rst
rednose = true
Expand Down
4 changes: 3 additions & 1 deletion fs/sshfs/__init__.py → sshfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from .sshfs import SSHFS
from . import opener
from ._sshfs import SSHFS


__license__ = "LGPL-2.1+"
__copyright__ = "Copyright (c) 2017 Martin Larralde"
Expand Down
2 changes: 1 addition & 1 deletion fs/sshfs/file.py → sshfs/_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import io

from ..iotools import RawWrapper
from fs.iotools import RawWrapper


class SSHFile(RawWrapper):
Expand Down
22 changes: 11 additions & 11 deletions fs/sshfs/sshfs.py → sshfs/_sshfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
import six
import paramiko

from .. import errors
from ..base import FS
from ..info import Info
from ..enums import ResourceType
from ..iotools import RawWrapper
from ..path import basename
from ..permissions import Permissions
from ..osfs import OSFS
from ..mode import Mode

from .file import SSHFile
from fs import errors
from fs.base import FS
from fs.info import Info
from fs.enums import ResourceType
from fs.iotools import RawWrapper
from fs.path import basename
from fs.permissions import Permissions
from fs.osfs import OSFS
from fs.mode import Mode

from ._file import SSHFile
from .error_tools import convert_sshfs_errors


Expand Down
2 changes: 1 addition & 1 deletion fs/sshfs/error_tools.py → sshfs/error_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import six

from .. import errors
from fs import errors


class _ConvertSSHFSErrors(object):
Expand Down
24 changes: 4 additions & 20 deletions fs/opener/sshfs.py → sshfs/opener.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,17 @@

import six

from .base import Opener
from ..subfs import ClosingSubFS
from ..errors import FSError, CreateFailed

__license__ = "LGPL-2.1+"
__copyright__ = "Copyright (c) 2017 Martin Larralde"
__author__ = "Martin Larralde <[email protected]>"
__version__ = 'dev'


# Dynamically get the version of the main module
try:
_name = __name__.replace('.opener', '')
import pkg_resources
__version__ = pkg_resources.get_distribution(_name).version
except Exception: # pragma: no cover
pkg_resources = None
finally:
del pkg_resources
from fs.opener.base import Opener
from fs.subfs import ClosingSubFS
from fs.errors import FSError, CreateFailed


class SSHOpener(Opener):
protocols = ['ssh']

@staticmethod
def open_fs(fs_url, parse_result, writeable, create, cwd):
from ..sshfs import SSHFS
from ._sshfs import SSHFS
ssh_host, _, dir_path = parse_result.resource.partition('/')
ssh_host, _, ssh_port = ssh_host.partition(':')
ssh_port = int(ssh_port) if ssh_port.isdigit() else 22
Expand Down
9 changes: 1 addition & 8 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@
import pkg_resources


# Add the local code directory to the `fs` module path
fs.__path__.insert(0, os.path.realpath(
os.path.join(__file__, '..', '..', 'fs')))
fs.opener.__path__.insert(0, os.path.realpath(
os.path.join(__file__, '..', '..', 'fs', 'opener')))


# Add additional openers to the entry points
pkg_resources.get_entry_map('fs', 'fs.opener')['ssh'] = \
pkg_resources.EntryPoint.parse(
'ssh = fs.opener.sshfs:SSHOpener',
'ssh = sshfs.opener:SSHOpener',
dist=pkg_resources.get_distribution('fs')
)
2 changes: 1 addition & 1 deletion tests/test_opener.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import fs.errors
import fs.path
from fs.sshfs import SSHFS
from sshfs import SSHFS

from . import utils

Expand Down
2 changes: 1 addition & 1 deletion tests/test_sshfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import fs.path
import fs.test
import fs.errors
from fs.sshfs import SSHFS
from fs.subfs import ClosingSubFS
from fs.permissions import Permissions
from sshfs import SSHFS

from . import utils

Expand Down
4 changes: 2 additions & 2 deletions tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class TestFSURL(unittest.TestCase):
port = 2224

def test_timeout(self):
with utils.mock.patch('fs.sshfs.SSHFS', utils.mock.MagicMock()) as magic:
with utils.mock.patch('sshfs.SSHFS', utils.mock.MagicMock()) as magic:
fs.open_fs('ssh://user:pass@localhost:2224/?timeout=1')
self.assertEqual(magic.call_args[-1]['timeout'], 1)
fs.open_fs('ssh://user:pass@localhost:2224/?compress=1&timeout=5')
self.assertEqual(magic.call_args[-1]['timeout'], 5)

def test_compress(self):
with utils.mock.patch('fs.sshfs.SSHFS', utils.mock.MagicMock()) as magic:
with utils.mock.patch('sshfs.SSHFS', utils.mock.MagicMock()) as magic:
fs.open_fs('ssh://user:pass@localhost:2224/?compress=true')
self.assertEqual(magic.call_args[-1]['compress'], True)
fs.open_fs('ssh://user:pass@localhost:2224/?timeout=5&compress=1')
Expand Down