Merge pull request #14 from rtfd/fix-linting

Fix linting on top of the `add-tests` branch
This commit is contained in:
Anthony 2015-10-19 13:37:07 -07:00
commit 64ba4c161c
10 changed files with 123 additions and 24 deletions

19
.travis.yml Normal file
View file

@ -0,0 +1,19 @@
language: python
python:
- 2.7
sudo: false
env:
- TOX_ENV=py27
- TOX_ENV=py34
- TOX_ENV=docs
- TOX_ENV=lint
install:
- pip install tox
script:
- tox -e $TOX_ENV
notifications:
slack:
rooms:
- readthedocs:y3hjODOi7EIz1JAbD1Zb41sz#random
on_success: change
on_failure: always

23
prospector.yml Normal file
View file

@ -0,0 +1,23 @@
strictness: low
test-warnings: false
doc-warnings: true
ignore-paths:
- docs
pep8:
full: true
options:
max-line-length: 100
pylint:
max-line-length: 100
disable:
- interface-not-implemented
mccabe:
run: false
pep257:
run: false

View file

@ -1,9 +1,7 @@
from contextlib import contextmanager
import itertools
from docutils import parsers, nodes, utils
from docutils.parsers.rst import roles, states
from docutils import parsers, nodes
from CommonMark import DocParser, HTMLRenderer
from warnings import warn
@ -38,6 +36,7 @@ class _SectionHandler(object):
class CommonMarkParser(parsers.Parser):
"""Parser of recommonmark."""
supported = ('md', 'markdown')

View file

@ -19,49 +19,42 @@ from recommonmark.parser import CommonMarkParser
def cm2html():
description = ('Generate html document from markdown sources. '
+ default_description)
description = ('Generate html document from markdown sources. ' + default_description)
publish_cmdline(writer_name='html',
parser=CommonMarkParser(),
description=description)
def cm2man():
description = ('Generate a manpage from markdown sources. '
+ default_description)
description = ('Generate a manpage from markdown sources. ' + default_description)
publish_cmdline(writer_name='manpage',
parser=CommonMarkParser(),
description=description)
def cm2xml():
description = ('Generate XML document from markdown sources. '
+ default_description)
description = ('Generate XML document from markdown sources. ' + default_description)
publish_cmdline(writer_name='xml',
parser=CommonMarkParser(),
description=description)
def cm2pseudoxml():
description = ('Generate pseudo-XML document from markdown sources. '
+ default_description)
description = ('Generate pseudo-XML document from markdown sources. ' + default_description)
publish_cmdline(writer_name='pseudoxml',
parser=CommonMarkParser(),
description=description)
def cm2latex():
description = ('Generate latex document from markdown sources. '
+ default_description)
description = ('Generate latex document from markdown sources. ' + default_description)
publish_cmdline(writer_name='latex',
parser=CommonMarkParser(),
description=description)
def cm2xetex():
description = ('Generate xetex document from markdown sources. '
+ default_description)
description = ('Generate xetex document from markdown sources. ' + default_description)
publish_cmdline(writer_name='latex',
parser=CommonMarkParser(),
description=description)

View file

@ -7,6 +7,7 @@ from docutils.parsers.rst.directives import directive
class DummyStateMachine(StateMachineWS):
"""A dummy state machine that mimicks the property of statemachine.
This state machine cannot be used for parsing, it is only used to generate
@ -14,6 +15,7 @@ class DummyStateMachine(StateMachineWS):
- Call `reset` to reset the state
- Then call `run_directive` or `run_role` to generate the node.
"""
def __init__(self):
self.memo = Struct(title_styles=[],
inliner=None)
@ -59,9 +61,9 @@ class DummyStateMachine(StateMachineWS):
self.input_lines = document['source']
def run_directive(self, name,
arguments=[],
options={},
content=[]):
arguments=None,
options=None,
content=None):
"""Generate directive node given arguments.
Parameters
@ -80,6 +82,12 @@ class DummyStateMachine(StateMachineWS):
node : docutil Node
Node generated by the arguments.
"""
if options is None:
options = {}
if content is None:
content = []
if arguments is None:
arguments = []
direc, msg = directive(name,
self.language,
self.document)
@ -95,8 +103,8 @@ class DummyStateMachine(StateMachineWS):
return direc.run()
def run_role(self, name,
options={},
content=[]):
options=None,
content=None):
"""Generate a role node.
options : dict
@ -109,11 +117,15 @@ class DummyStateMachine(StateMachineWS):
node : docutil Node
Node generated by the arguments.
"""
if options is None:
options = {}
if content is None:
content = []
role_fn, msg = role(name,
self.language,
self.node.line,
self.reporter)
vec, msg= role_fn(name,
vec, msg = role_fn(name,
rawtext=str(content),
text=str(content),
lineno=self.node.line,

View file

@ -5,7 +5,9 @@ from states import DummyStateMachine
from docutils import nodes, transforms
from docutils.statemachine import StringList
class AutoStructify(transforms.Transform):
"""Automatically try to transform blocks to sphinx directives.
This class is designed to handle AST generated by CommonMarkParser.
@ -21,7 +23,7 @@ class AutoStructify(transforms.Transform):
'enable_eval_rst': True,
'enable_math': True,
'url_resolver': lambda x: x,
}
}
def parse_ref(self, ref):
"""Analyze the ref block, and return the information needed.
@ -60,7 +62,7 @@ class AutoStructify(transforms.Transform):
relpath = os.path.relpath(abspath, self.root_dir)
suffix = abspath.rsplit('.', 1)
if len(suffix) == 2 and suffix[1] in AutoStructify.suffix_set and (
os.path.exists(abspath) and abspath.startswith(self.root_dir)):
os.path.exists(abspath) and abspath.startswith(self.root_dir)):
docpath = '/' + relpath.rsplit('.', 1)[0]
# rewrite suffix to html, this is suboptimal
uri = docpath + '.html'

4
requirements.txt Normal file
View file

@ -0,0 +1,4 @@
commonmark>= 0.5.4
docutils>=0.11
sphinx==1.3.1
pytest==2.7.2

0
tests/__init__.py Normal file
View file

21
tests/test_basic.py Normal file
View file

@ -0,0 +1,21 @@
import unittest
from docutils.core import publish_parts
from recommonmark.parser import CommonMarkParser
class TestStringMethods(unittest.TestCase):
def test_basic_parser(self):
source = '# Header'
ret = publish_parts(
source=source,
writer_name='html',
parser=CommonMarkParser()
)
self.assertTrue(ret['title'], 'Header')
if __name__ == '__main__':
unittest.main()

26
tox.ini Normal file
View file

@ -0,0 +1,26 @@
[tox]
envlist = py27,py34,lint,docs
[testenv]
setenv =
LANG=C
deps =
-r{toxinidir}/requirements.txt
commands =
py.test {posargs}
[testenv:docs]
deps = {[testenv]deps}
changedir = {toxinidir}/docs
commands =
sphinx-build -b html -d {envtmpdir}/doctrees . {envtmpdir}/html
[testenv:lint]
deps =
{[testenv]deps}
prospector
commands =
prospector \
--profile-path={toxinidir} \
--profile=prospector \
--die-on-tool-error