Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
Misc code style tweaks (spaces, pep8)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioChen authored and mk-fg committed Mar 9, 2013
1 parent ad57e78 commit a2bbccd
Show file tree
Hide file tree
Showing 9 changed files with 935 additions and 900 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@
/README.txt
*.pyc
*.pyo
.idea
14 changes: 7 additions & 7 deletions doc/api.rst
@@ -1,12 +1,12 @@
.. automodule:: skydrive.api_v5
:exclude-members: SkyDriveHTTPClient, SkyDriveAuth,
SkyDriveAPIWrapper, SkyDriveAPI, PersistentSkyDriveAPI
:exclude-members: SkyDriveHTTPClient, SkyDriveAuth,
SkyDriveAPIWrapper, SkyDriveAPI, PersistentSkyDriveAPI

.. autoclass:: SkyDriveHTTPClient
.. autoclass:: SkyDriveAuth
.. autoclass:: SkyDriveAPIWrapper
.. autoclass:: SkyDriveAPI
.. autoclass:: SkyDriveHTTPClient
.. autoclass:: SkyDriveAuth
.. autoclass:: SkyDriveAPIWrapper
.. autoclass:: SkyDriveAPI

.. autoclass:: PersistentSkyDriveAPI
:exclude-members: rx:^from_conf|conf_(path_default|update_keys)$
:exclude-members: rx:^from_conf|conf_(path_default|update_keys)$
:inherited-members:
1 change: 0 additions & 1 deletion doc/conf.py
Expand Up @@ -9,7 +9,6 @@
sys.path.insert(0, abspath('..')) # for module itself
sys.path.append(abspath('.')) # for extenstions


needs_sphinx = '1.1'
extensions = ['sphinx.ext.autodoc', 'sphinx_local_hooks']

Expand Down
104 changes: 57 additions & 47 deletions doc/sphinx_local_hooks.py
Expand Up @@ -5,71 +5,81 @@
from collections import Iterable
import os, sys, types, re


from sphinx.ext.autodoc import Documenter

_autodoc_add_line = Documenter.add_line


@ft.wraps(_autodoc_add_line)
def autodoc_add_line(self, line, *argz, **kwz):
tee = self.env.app.config.autodoc_dump_rst
if tee:
tee_line = self.indent + line
if isinstance(tee, file): tee.write(tee_line + '\n')
elif tee is True: print(tee_line)
else:
raise ValueError( 'Unrecognized'
' value for "autodoc_dump_rst" option: {!r}'.format(tee) )
return _autodoc_add_line(self, line, *argz, **kwz)
tee = self.env.app.config.autodoc_dump_rst
if tee:
tee_line = self.indent + line
if isinstance(tee, file):
tee.write(tee_line + '\n')
elif tee is True:
print(tee_line)
else:
raise ValueError('Unrecognized'
' value for "autodoc_dump_rst" option: {!r}'.format(tee))
return _autodoc_add_line(self, line, *argz, **kwz)


Documenter.add_line = autodoc_add_line


def process_docstring(app, what, name, obj, options, lines):
if not lines: return
if not lines: return

i, ld = 0, dict(enumerate(lines)) # to allow arbitrary peeks
i_max = max(ld)
i, ld = 0, dict(enumerate(lines)) # to allow arbitrary peeks
i_max = max(ld)

def process_line(i):
line, i_next = ld[i], i + 1
while i_next not in ld and i_next <= i_max: i_next += 1
line_next = ld.get(i_next)
def process_line(i):
line, i_next = ld[i], i + 1
while i_next not in ld and i_next <= i_max: i_next += 1
line_next = ld.get(i_next)

if line_next and line_next[0] in u' \t': # tabbed continuation of the sentence
ld[i] = u'{} {}'.format(line, line_next.strip())
del ld[i_next]
process_line(i)
elif line.endswith(u'.') or (line_next and line_next[0].isupper()): ld[i+0.5] = u''
if line_next and line_next[0] in u' \t': # tabbed continuation of the sentence
ld[i] = u'{} {}'.format(line, line_next.strip())
del ld[i_next]
process_line(i)
elif line.endswith(u'.') or (line_next and line_next[0].isupper()):
ld[i + 0.5] = u''

for i in xrange(i_max + 1):
if i not in ld: continue # was removed
process_line(i)
for i in xrange(i_max + 1):
if i not in ld: continue # was removed
process_line(i)

# Overwrite the list items inplace, extending the list if necessary
for i, (k, line) in enumerate(sorted(ld.viewitems())):
try: lines[i] = line
except IndexError: lines.append(line)
# Overwrite the list items inplace, extending the list if necessary
for i, (k, line) in enumerate(sorted(ld.viewitems())):
try:
lines[i] = line
except IndexError:
lines.append(line)


def skip_override(app, what, name, obj, skip, options):
if options.get('exclude-members'):
include_only = set( re.compile(k[3:])
for k in options['exclude-members'] if k.startswith('rx:') )
if include_only:
for pat in include_only:
if pat.search(name): break
else: return True
if what == 'exception':
return False if name == '__init__'\
and isinstance(obj, types.UnboundMethodType) else True
elif what == 'class':
if name in ['__init__', '__call__']\
and isinstance(obj, types.UnboundMethodType): return False
elif getattr(obj, 'im_class', None) is type: return False
return skip
if options.get('exclude-members'):
include_only = set(re.compile(k[3:])
for k in options['exclude-members'] if k.startswith('rx:'))
if include_only:
for pat in include_only:
if pat.search(name): break
else:
return True
if what == 'exception':
return False if name == '__init__' \
and isinstance(obj, types.UnboundMethodType) else True
elif what == 'class':
if name in ['__init__', '__call__'] \
and isinstance(obj, types.UnboundMethodType):
return False
elif getattr(obj, 'im_class', None) is type:
return False
return skip


def setup(app):
app.connect('autodoc-process-docstring', process_docstring)
app.connect('autodoc-skip-member', skip_override)
app.add_config_value('autodoc_dump_rst', None, True)
app.connect('autodoc-process-docstring', process_docstring)
app.connect('autodoc-skip-member', skip_override)
app.add_config_value('autodoc_dump_rst', None, True)
133 changes: 68 additions & 65 deletions doc/sphinx_text_to_md.py
Expand Up @@ -10,71 +10,74 @@ class FormatError(Exception): pass


def main():
import argparse
parser = argparse.ArgumentParser(
description='Convert sphinx-produced autodoc.apidoc text to markdown.')
parser.add_argument('src', nargs='?', help='Source file (default: use stdin).')
optz = parser.parse_args()

src = open(optz.src) if optz.src else sys.stdin
dst = sys.stdout

py_name = r'[\w_\d]+'
out = ft.partial(print, file=dst)

st_attrdoc = 0
st_cont, lse_nl = False, None

for line in src:
ls = line.strip()
if not ls: # blank line
out(line, end='')
continue

line_indent = re.search(r'^( +)', line)
if not line_indent: line_indent = 0
else:
line_indent = len(line_indent.group(1))
if line_indent % 3: raise FormatError('Weird indent size: {}'.format(line_indent))
line_indent = line_indent / 3

lp = line.split()
lse = re.sub(r'(<\S+) at 0x[\da-f]+(>)', r'\1\2', ls)
lse = re.sub(r'([_*<>])', r'\\\1', lse)
for url in re.findall(r'\b\w+://\S+', lse):
lse = lse.replace(url, url.replace(r'\_', '_'))
lse = re.sub(r'\bu([\'"])', r'\1', lse)
st_cont, lse_nl = bool(lse_nl), '' if re.search(r'\b\w+://\S+-$', lse) else '\n'

st_attrdoc_reset = True
if not line_indent:
if len(lp) > 2 and lp[0] == lp[1]:
if lp[0] in ('exception', 'class'): # class, exception
out('\n'*1, end='')
out('* **{}**'.format(' '.join(lse.split()[1:])))

else:
raise FormatError('Unhandled: {!r}'.format(line))

elif line_indent == 1:
if re.search(r'^(\w+ )?{}\('.format(py_name), ls): # function
out('\n'*1, end='')
out('{}* {}'.format(' '*4, lse))
st_attrdoc, st_attrdoc_reset = 8, False
elif re.search(r'^{}\s+=\s+'.format(py_name), ls): # attribute
out('{}* {}'.format(' '*4, lse))
st_attrdoc, st_attrdoc_reset = 8, False
elif lp[0] == 'Bases:': # class bases
out('{}{}'.format(' '*4, lse))
st_attrdoc, st_attrdoc_reset = 4, False
else: out('{}{}'.format(' '*(4 * st_cont), ls), end=lse_nl) # class docstring

else: # description line
if ls[0] in '-*': line = '\\' + line.lstrip()
out('{}{}'.format(' '*(st_attrdoc * st_cont), line.strip()), end=lse_nl)
st_attrdoc_reset = False

if st_attrdoc and st_attrdoc_reset: st_attrdoc = 0
import argparse

parser = argparse.ArgumentParser(
description='Convert sphinx-produced autodoc.apidoc text to markdown.')
parser.add_argument('src', nargs='?', help='Source file (default: use stdin).')
optz = parser.parse_args()

src = open(optz.src) if optz.src else sys.stdin
dst = sys.stdout

py_name = r'[\w_\d]+'
out = ft.partial(print, file=dst)

st_attrdoc = 0
st_cont, lse_nl = False, None

for line in src:
ls = line.strip()
if not ls: # blank line
out(line, end='')
continue

line_indent = re.search(r'^( +)', line)
if not line_indent:
line_indent = 0
else:
line_indent = len(line_indent.group(1))
if line_indent % 3: raise FormatError('Weird indent size: {}'.format(line_indent))
line_indent = line_indent / 3

lp = line.split()
lse = re.sub(r'(<\S+) at 0x[\da-f]+(>)', r'\1\2', ls)
lse = re.sub(r'([_*<>])', r'\\\1', lse)
for url in re.findall(r'\b\w+://\S+', lse):
lse = lse.replace(url, url.replace(r'\_', '_'))
lse = re.sub(r'\bu([\'"])', r'\1', lse)
st_cont, lse_nl = bool(lse_nl), '' if re.search(r'\b\w+://\S+-$', lse) else '\n'

st_attrdoc_reset = True
if not line_indent:
if len(lp) > 2 and lp[0] == lp[1]:
if lp[0] in ('exception', 'class'): # class, exception
out('\n' * 1, end='')
out('* **{}**'.format(' '.join(lse.split()[1:])))

else:
raise FormatError('Unhandled: {!r}'.format(line))

elif line_indent == 1:
if re.search(r'^(\w+ )?{}\('.format(py_name), ls): # function
out('\n' * 1, end='')
out('{}* {}'.format(' ' * 4, lse))
st_attrdoc, st_attrdoc_reset = 8, False
elif re.search(r'^{}\s+=\s+'.format(py_name), ls): # attribute
out('{}* {}'.format(' ' * 4, lse))
st_attrdoc, st_attrdoc_reset = 8, False
elif lp[0] == 'Bases:': # class bases
out('{}{}'.format(' ' * 4, lse))
st_attrdoc, st_attrdoc_reset = 4, False
else:
out('{}{}'.format(' ' * (4 * st_cont), ls), end=lse_nl) # class docstring

else: # description line
if ls[0] in '-*': line = '\\' + line.lstrip()
out('{}{}'.format(' ' * (st_attrdoc * st_cont), line.strip()), end=lse_nl)
st_attrdoc_reset = False

if st_attrdoc and st_attrdoc_reset: st_attrdoc = 0


if __name__ == '__main__': main()
90 changes: 46 additions & 44 deletions setup.py
Expand Up @@ -6,50 +6,52 @@
pkg_root = os.path.dirname(__file__)

# Error-handling here is to allow package to be built w/o README included
try: readme = open(os.path.join(pkg_root, 'README.txt')).read()
except IOError: readme = ''
try:
readme = open(os.path.join(pkg_root, 'README.txt')).read()
except IOError:
readme = ''

setup(

name = 'python-skydrive',
version = '13.01.2',
author = 'Mike Kazantsev',
author_email = 'mk.fraggod@gmail.com',
license = 'WTFPL',
keywords = 'skydrive api oauth2 rest microsoft cloud live liveconnect',
url = 'http://github.com/mk-fg/python-skydrive',

description = 'Python and command-line interface'
' for Microsoft LiveConnect SkyDrive REST API v5.0',
long_description = readme,

classifiers = [
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Intended Audience :: Information Technology',
'License :: OSI Approved',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 2 :: Only',
'Topic :: Internet',
'Topic :: Software Development',
'Topic :: System :: Archiving',
'Topic :: System :: Filesystems',
'Topic :: Utilities' ],

# install_requires = [],
extras_require = dict(
standalone=['requests'],
cli=['PyYAML', 'requests'],
conf=['PyYAML', 'requests'] ),

packages = find_packages(),
include_package_data = True,
package_data = {'': ['README.txt']},
exclude_package_data = {'': ['README.*']},

entry_points = dict(console_scripts=[
'skydrive-cli = skydrive.cli_tool:main' ]) )
name='python-skydrive',
version='13.03.3',
author='Mike Kazantsev',
author_email='mk.fraggod@gmail.com',
license='WTFPL',
keywords='skydrive api oauth2 rest microsoft cloud live liveconnect',
url='http://github.com/mk-fg/python-skydrive',

description='Python and command-line interface'
' for Microsoft LiveConnect SkyDrive REST API v5.0',
long_description=readme,

classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Intended Audience :: Information Technology',
'License :: OSI Approved',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 2 :: Only',
'Topic :: Internet',
'Topic :: Software Development',
'Topic :: System :: Archiving',
'Topic :: System :: Filesystems',
'Topic :: Utilities'],

# install_requires = [],
extras_require=dict(
standalone=['requests'],
cli=['PyYAML', 'requests'],
conf=['PyYAML', 'requests']),

packages=find_packages(),
include_package_data=True,
package_data={'': ['README.txt']},
exclude_package_data={'': ['README.*']},

entry_points=dict(console_scripts=[
'skydrive-cli = skydrive.cli_tool:main']))

0 comments on commit a2bbccd

Please sign in to comment.