Skip to content

Commit

Permalink
MAINT: adds copydoc decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
llllllllll committed Aug 7, 2015
1 parent 64b019a commit 090b4c7
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 28 deletions.
8 changes: 3 additions & 5 deletions odo/backends/aws.py
Expand Up @@ -19,7 +19,7 @@
from .text import TextFile

from ..compatibility import urlparse
from ..utils import tmpfile, ext, sample, filter_kwargs
from ..utils import tmpfile, ext, sample, filter_kwargs, copydoc


@memoize
Expand Down Expand Up @@ -87,14 +87,12 @@ def __init__(self, uri, s3=None, aws_access_key_id=None,
**filter_kwargs(self.subtype.__init__, kwargs))


@memoize
@copydoc(_S3)
def S3(cls):
return type('S3(%s)' % cls.__name__, (_S3, cls), {'subtype': cls})


S3.__doc__ = _S3.__doc__
S3 = memoize(S3)


@sample.register((S3(CSV), S3(JSONLines)))
@contextmanager
def sample_s3_line_delimited(data, length=8192):
Expand Down
8 changes: 3 additions & 5 deletions odo/backends/ssh.py
Expand Up @@ -8,7 +8,7 @@
import uuid

from ..directory import Directory
from ..utils import keywords, tmpfile, sample, ignoring
from ..utils import keywords, tmpfile, sample, ignoring, copydoc
from ..resource import resource
from ..append import append
from ..convert import convert
Expand Down Expand Up @@ -78,13 +78,11 @@ def lines(self):
return conn.file(self.path, 'r')


@memoize
@copydoc(_SSH)
def SSH(cls):
return type('SSH(%s)' % cls.__name__, (_SSH, cls), {'subtype': cls})

SSH.__doc__ = _SSH.__doc__

SSH = memoize(SSH)


types_by_extension = {'csv': CSV, 'json': JSONLines}

Expand Down
7 changes: 3 additions & 4 deletions odo/backends/url.py
Expand Up @@ -28,7 +28,7 @@
from .text import TextFile

from ..compatibility import urlparse
from ..utils import tmpfile, ext, sample
from ..utils import tmpfile, ext, sample, copydoc


class _URL(object):
Expand Down Expand Up @@ -70,12 +70,11 @@ def __init__(self, url, chunk_size=1024, decode_unicode=False, *args,
self.filename = os.path.basename(urlparse(url).path)


@memoize
@copydoc(_URL)
def URL(cls):
return type('URL(%s)' % cls.__name__, (_URL, cls), {'subtype': cls})

URL.__doc__ = _URL.__doc__
URL = memoize(URL)


@sample.register((URL(CSV), URL(JSONLines)))
@contextmanager
Expand Down
8 changes: 3 additions & 5 deletions odo/chunks.py
Expand Up @@ -2,7 +2,7 @@

from toolz import memoize, first
from datashape import discover, var
from .utils import cls_name
from .utils import cls_name, copydoc


class Chunks(object):
Expand Down Expand Up @@ -36,14 +36,12 @@ def __iter__(self):
return iter(self.data)


@memoize
@copydoc(Chunks)
def chunks(cls):
""" Parametrized Chunks Class """
return type('chunks(%s)' % cls_name(cls), (Chunks,), {'container': cls})

chunks.__doc__ = Chunks.__doc__

chunks = memoize(chunks)


@discover.register(Chunks)
def discover_chunks(c, **kwargs):
Expand Down
7 changes: 3 additions & 4 deletions odo/directory.py
Expand Up @@ -3,6 +3,7 @@
from glob import glob
from .chunks import Chunks
from .resource import resource
from .utils import copydoc
from toolz import memoize, first
from datashape import discover, var
import os
Expand Down Expand Up @@ -33,14 +34,12 @@ def __iter__(self):
for fn in sorted(os.listdir(self.path)))


@memoize
@copydoc(_Directory)
def Directory(cls):
""" Parametrized DirectoryClass """
return type('Directory(%s)' % cls.__name__, (_Directory,), {'container': cls})

Directory.__doc__ = Directory.__doc__

Directory = memoize(Directory)


re_path_sep = os.path.sep
if re_path_sep == '\\':
Expand Down
3 changes: 2 additions & 1 deletion odo/regex.py
Expand Up @@ -2,6 +2,7 @@

import re


def normalize(r):
"""
Expand All @@ -13,6 +14,7 @@ def normalize(r):
"""
return '^' + r.lstrip('^').rstrip('$') + '$'


class RegexDispatcher(object):
"""
Regular Expression Dispatcher
Expand Down Expand Up @@ -45,7 +47,6 @@ def __init__(self, name):
self.funcs = dict()
self.priorities = dict()


def add(self, regex, func, priority=10):
self.funcs[normalize(regex)] = func
self.priorities[func] = priority
Expand Down
8 changes: 4 additions & 4 deletions odo/temp.py
@@ -1,6 +1,8 @@
from __future__ import absolute_import, division, print_function
from toolz import memoize
from .drop import drop
from .utils import copydoc


class _Temp(object):
""" Temporary version of persistent storage
Expand All @@ -16,10 +18,8 @@ def __del__(self):
drop(self)


@memoize
@copydoc(_Temp)
def Temp(cls):
""" Parametrized Chunks Class """
return type('Temp(%s)' % cls.__name__, (_Temp, cls), {'persistent_type': cls})

Temp.__doc__ = _Temp.__doc__

Temp = memoize(Temp)
20 changes: 20 additions & 0 deletions odo/utils.py
Expand Up @@ -367,3 +367,23 @@ def filter_kwargs(f, kwargs):
6
"""
return keyfilter(keywords(f).__contains__, kwargs)


@curry
def copydoc(from_, to):
"""Copies the docstring from one function to another.
Paramaters
----------
from_ : any
The object to copy the docstring from.
to : any
The object to copy the docstring to.
Returns
-------
to : any
``to`` with the docstring from ``from_``
"""
to.__doc__ = from_.__doc__
return to

0 comments on commit 090b4c7

Please sign in to comment.