Skip to content

Commit

Permalink
Merge 9785-py3-apidocs: Use Python 3 for building API and narrative d…
Browse files Browse the repository at this point in the history
…ocumentation

Author: hawkowl
Reviewer: rodrigc
Fixes: ticket:9785
  • Loading branch information
hawkowl authored Mar 28, 2020
1 parent 62ca995 commit 3b0854d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ jobs:
documentation:
working_directory: ~/documentation
docker:
- image: circleci/python:2.7
- image: circleci/python:3.6
environment:
PYTHON: python2
PYTHON: python3
steps:
# Get the source.
- checkout
Expand Down
Empty file.
47 changes: 13 additions & 34 deletions src/twisted/python/_pydoctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,12 @@
This documentation does not link to pydoctor API as there is no public API yet.
"""

import urllib2
import ast

from compiler import ast
from pydoctor import model, zopeinterface
from pydoctor import model, zopeinterface, astbuilder
from pydoctor.sphinx import SphinxInventory


class HeadRequest(urllib2.Request, object):
"""
A request for the HEAD HTTP method.
"""

def get_method(self):
"""
Use the HEAD HTTP method.
"""
return 'HEAD'



class TwistedSphinxInventory(SphinxInventory):
"""
Expand Down Expand Up @@ -94,22 +81,15 @@ def getDeprecated(self, decorators):
decorator.
"""
for a in decorators:
if isinstance(a, ast.CallFunc):
decorator = a.asList()

# Getattr is used when the decorator is @foo.bar, not @bar
if isinstance(decorator[0], ast.Getattr):
getAttr = decorator[0].asList()
name = getAttr[0].name
fn = self.expandName(name) + "." + getAttr[1]
else:
fn = self.expandName(decorator[0].name)
if isinstance(a, ast.Call):
fn = self.expandName(''.join(astbuilder.node2dottedname(a.func)))

if fn == "twisted.python.deprecate.deprecated":
try:
self._deprecated_info = deprecatedToUsefulText(
self.name, decorator)
self, self.name, a)
except AttributeError:
raise
# It's a reference or something that we can't figure out
# from the AST.
pass
Expand Down Expand Up @@ -147,23 +127,22 @@ def versionToUsefulObject(version):
Change an AST C{Version()} to a real one.
"""
from incremental import Version

return Version(*[x.value for x in version.asList()[1:] if x])
return Version(version.args[0].s, *[x.n for x in version.args[1:] if x])



def deprecatedToUsefulText(name, deprecated):
def deprecatedToUsefulText(visitor, name, deprecated):
"""
Change a C{@deprecated} to a display string.
"""
from twisted.python.deprecate import _getDeprecationWarningString

version = versionToUsefulObject(deprecated[1])
if deprecated[2]:
if isinstance(deprecated[2], ast.Keyword):
replacement = deprecated[2].asList()[1].value
version = versionToUsefulObject(deprecated.args[0])
if len(deprecated.args) > 1 and deprecated.args[1]:
if isinstance(deprecated.args[1], ast.Name):
replacement = visitor.resolveName(deprecated.args[1].id)
else:
replacement = deprecated[2].value
replacement = deprecated.args[1].s
else:
replacement = None

Expand Down
20 changes: 10 additions & 10 deletions src/twisted/python/_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,16 @@ def templatefile(filename):

from pydoctor.driver import main

args = [u"--project-name", projectName,
u"--project-url", projectURL,
u"--system-class", u"twisted.python._pydoctor.TwistedSystem",
u"--project-base-dir", packagePath.parent().path,
u"--html-viewsource-base", sourceURL,
u"--add-package", packagePath.path,
u"--html-output", outputPath.path,
u"--html-write-function-pages", u"--quiet", u"--make-html",
] + intersphinxes
args = [arg.encode("utf-8") for arg in args]
args = [
"--project-name", projectName,
"--project-url", projectURL,
"--system-class", "twisted.python._pydoctor.TwistedSystem",
"--project-base-dir", packagePath.parent().path,
"--html-viewsource-base", sourceURL,
"--add-package", packagePath.path,
"--html-output", outputPath.path,
"--html-write-function-pages", "--quiet", "--make-html",
] + intersphinxes
main(args)

monkeyPatch.restore()
Expand Down
1 change: 0 additions & 1 deletion src/twisted/python/_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ def _checkCPython(sys=sys, platform=platform):
"twisted.plugins.twisted_mail",
"twisted.plugins.twisted_news",
"twisted.protocols.shoutcast",
"twisted.python._pydoctor",
"twisted.python.finalize",
"twisted.python.hook",
"twisted.python.test.cmodulepullpipe",
Expand Down
3 changes: 1 addition & 2 deletions src/twisted/python/test/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

from ..url import URL

unicode = type(u'')

from twisted.python.compat import unicode
from twisted.trial.unittest import SynchronousTestCase


Expand Down
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ commands =
wheels: ls -l {toxinidir}/wheelhouse

[testenv:apidocs]
# Epydoc and pydoctor currently on work on Python 2
basepython=python2.7
deps=pydoctor
deps=https://github.com/twisted/pydoctor/archive/3f9c64829dfa040b334c9ae27c332c7078356e79.zip

[testenv:manifest-checker]
skip_install = true
Expand Down

0 comments on commit 3b0854d

Please sign in to comment.