Skip to content
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

Document and follow aliases better #414

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
de67334
Add initial code for proper aliases handling.
Jun 26, 2021
e476cf8
Fix a reccursion error and reduce the scope of what is an module-leve…
Jun 26, 2021
5f5fca9
Still register the indirection for aliases defined in try/expect or i…
Jun 26, 2021
da6f4ce
Cleanup and documenting.
Jun 27, 2021
100e55b
Fix docstrings
Jun 27, 2021
275e815
Import Final from the typing_extensions module
Jun 27, 2021
f56d050
Add requirement typing_extensions; python_version < "3.8"
Jun 27, 2021
2c76275
Use ._alias_to attribute to store the aliases indirection instead of …
tristanlatr Jun 28, 2021
fccbd4f
Add Add Known aliases for modules and classes. Not fully functional...
tristanlatr Jun 28, 2021
e666795
Add some aliases in the RST demo
tristanlatr Jun 28, 2021
43c251b
Merge branch 'twisted-master' into alias - might be broken :/
Jan 2, 2022
3d67f95
broken :/
Jan 2, 2022
6a2af77
Merge meta files form 'twisted-master' into alias
tristanlatr May 23, 2022
606e54d
merge docs from 'twisted-master' into 'alias'
tristanlatr May 23, 2022
46c1e8e
Forgot a meta file.
tristanlatr May 23, 2022
59d46ee
merge source files 'twisted-master' into 'alias', currently fails 21 …
tristanlatr May 23, 2022
f0f38d7
wip debugging...
tristanlatr May 23, 2022
6f2e374
Add a test
tristanlatr May 23, 2022
f0b4255
Merge branch 'add-a-test-for-module-attributes-and-aliases' into alias
tristanlatr May 23, 2022
5bae337
Fix tests
tristanlatr May 23, 2022
ca1e470
passing ctx to ast.Name() is required for python 3.6
tristanlatr May 25, 2022
7cd0554
add test
tristanlatr Jun 11, 2022
174526e
Merge branch 'master' into alias
tristanlatr Jun 11, 2022
93f82d9
Re-export name in any case when processing imports parts of __all__
tristanlatr Jun 12, 2022
8cdc932
Merge branch 'alias' of github.com:tristanlatr/pydoctor into alias
tristanlatr Jun 12, 2022
fc66fa3
More tests
tristanlatr Jun 12, 2022
2db2386
Try fixing mypy
tristanlatr Jun 12, 2022
eab7a98
Move alias processing to post-process and refactors.
tristanlatr Jun 13, 2022
229405b
Move the name resolving logic into a new module: names.py
tristanlatr Jun 17, 2022
7e98ed6
Fix infinite recusion (I just forgot the indirections arg to be passe…
tristanlatr Jun 17, 2022
a0b6091
Add a tox environment that parses the cpython code to only generate t…
tristanlatr Jun 17, 2022
f82fb92
Fix expandName()
tristanlatr Jun 17, 2022
a907d14
Use protocol and more stricter checks
tristanlatr Jun 18, 2022
64a32f6
Wip import resolve import alises across modules
tristanlatr Jun 30, 2022
41cc53a
Merge branch 'twisted-master' into alias
tristanlatr Aug 18, 2022
312da1e
We now recursively resolve aliases.
tristanlatr Aug 18, 2022
fa528e4
Add docs
tristanlatr Aug 18, 2022
1fd1d17
Prevent recusrsion error
tristanlatr Aug 18, 2022
63d1894
Increase max recursions to 100.
tristanlatr Aug 18, 2022
627b82c
Small refactors
tristanlatr Aug 25, 2022
3d7e95f
Merge branch 'master' into tristanlatr/alias
tristanlatr Nov 11, 2022
e136938
Merge commit '5393bd867864aeef8e7e94f551589cbc35df96eb' into tristanl…
tristanlatr Nov 12, 2022
791da52
use report()
tristanlatr Nov 12, 2022
d262d87
With failing tests for now. Merge branch 'master' into tristanlatr/alias
tristanlatr Jan 24, 2024
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 .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ omit =
pydoctor/sphinx_ext/*
pydoctor/test/*
pydoctor/epydoc/sre_parse36.py
pydoctor/epydoc/sre_constants36.py
source =
pydoctor

Expand Down
117 changes: 117 additions & 0 deletions .github/workflows/pydoctor_primer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Run pydoctor_primer

on:
# Only run on PR, since we diff against master
pull_request:
paths-ignore:
- 'pydoctor/test/**'
- 'docs/**'
- '*.rst'
- '*.txt'
- '*.in'
- '*.md'
- '.*'
- 'setup.py'


jobs:
pydoctor_primer:
name: Run pydoctor_primer
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
path: pydoctor_to_test
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install pydoctor_primer
run: |
python -m pip install -U pip
pip install git+https://github.com/twisted/pydoctor_primer.git
- name: Run pydoctor_primer
shell: bash
run: |
cd pydoctor_to_test
echo "new commit"
git rev-list --format=%s --max-count=1 $GITHUB_SHA

MERGE_BASE=$(git merge-base $GITHUB_SHA origin/$GITHUB_BASE_REF)
git checkout -b base_commit $MERGE_BASE
echo "base commit"
git rev-list --format=%s --max-count=1 base_commit

echo ''
cd ..
# fail action if exit code isn't zero or one
(
pydoctor_primer \
--repo pydoctor_to_test \
--new $GITHUB_SHA --old base_commit \
--debug \
--output concise \
-j 8 \
| tee diff.txt
) || [ $? -eq 1 ]

- name: Post comment
id: post-comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const MAX_CHARACTERS = 30000
const MAX_CHARACTERS_PER_PROJECT = MAX_CHARACTERS / 3

const fs = require('fs')
let data = fs.readFileSync('diff.txt', { encoding: 'utf8' })

function truncateIfNeeded(original, maxLength) {
if (original.length <= maxLength) {
return original
}
let truncated = original.substring(0, maxLength)
// further, remove last line that might be truncated
truncated = truncated.substring(0, truncated.lastIndexOf('\n'))
let lines_truncated = original.split('\n').length - truncated.split('\n').length
return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...`
}

const projects = data.split('\n\n')
// don't let one project dominate
data = projects.map(project => truncateIfNeeded(project, MAX_CHARACTERS_PER_PROJECT)).join('\n\n')
// posting comment fails if too long, so truncate
data = truncateIfNeeded(data, MAX_CHARACTERS)

console.log("Diff from pydoctor_primer:")
console.log(data)

let body
if (data.trim()) {
body = 'Diff from [pydoctor_primer](https://github.com/tristanlatr/pydoctor_primer), showing the effect of this PR on open source code:\n```diff\n' + data + '```'
} else {
body = "According to [pydoctor_primer](https://github.com/tristanlatr/pydoctor_primer), this change doesn't affect pydoctor warnings on a corpus of open source code. ✅"
}
const ev = JSON.parse(
fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8')
)
const prNumber = ev.pull_request.number

await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
return prNumber

- name: Hide old comments
uses: kanga333/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
leave_visible: 1
issue_number: ${{ steps.post-comment.outputs.result }}
12 changes: 4 additions & 8 deletions .github/workflows/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@ jobs:

strategy:
matrix:
tox_target: [twisted-apidoc,
cpython-summary,
python-igraph-apidocs,
cpython-apidocs,
numpy-apidocs,
git-buildpackage-apidocs,]
tox_target: [twisted-apidoc, cpython-summary, python-igraph-apidocs, cpython-apidocs, numpy-apidocs, git-buildpackage-apidocs, pytype-apidocs]

steps:
- uses: actions/checkout@v2

- name: Set up Python
- name: Set up CPython
uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.11'

- name: Install tox
run: |
Expand All @@ -41,3 +36,4 @@ jobs:
- name: Generate API docs
run: |
tox -e ${{ matrix.tox_target }}

10 changes: 5 additions & 5 deletions .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:

strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, 3.10.0, pypy-3.6]
python-version: [pypy-3.7, 3.7, 3.8, 3.9, '3.10', 3.11, '3.12.0-rc.3']
os: [ubuntu-20.04]
include:
- os: windows-latest
python-version: 3.6
python-version: 3.7
- os: macos-latest
python-version: 3.6
python-version: 3.7

steps:
- uses: actions/checkout@v2
Expand All @@ -45,8 +45,8 @@ jobs:
run: |
tox -e test

- name: Run unit tests with latest Twisted version
if: matrix.python-version != '3.6' && matrix.python-version != 'pypy-3.6'
- name: Run unit tests with latest Twisted version (only for python 3.8 and later)
if: matrix.python-version != '3.7' && matrix.python-version != 'pypy-3.7'
run: |
tox -e test-latest-twisted

Expand Down
73 changes: 70 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pydoctor
.. image:: https://img.shields.io/pypi/pyversions/pydoctor.svg
:target: https://pypi.python.org/pypi/pydoctor

.. image:: https://travis-ci.org/twisted/pydoctor.svg?branch=tox-travis-2
:target: https://travis-ci.org/twisted/pydoctor
.. image:: https://github.com/twisted/pydoctor/actions/workflows/unit.yaml/badge.svg
:target: https://github.com/twisted/pydoctor/actions/workflows/unit.yaml

.. image:: https://codecov.io/gh/twisted/pydoctor/branch/master/graph/badge.svg
:target: https://codecov.io/gh/twisted/pydoctor
Expand Down Expand Up @@ -76,6 +76,73 @@ What's New?
in development
^^^^^^^^^^^^^^

This is the last major release to support Python 3.7.

* Drop support for Python 3.6
* Add support for Python 3.12
* `ExtRegistrar.register_post_processor()` now supports a `priority` argument that is an int.
Highest priority callables will be called first during post-processing.
* Fix too noisy ``--verbose`` mode (suppres some ambiguous annotations warnings).

pydoctor 23.9.1
^^^^^^^^^^^^^^^

* Fix regression in link not found warnings' line numbers.

pydoctor 23.9.0
^^^^^^^^^^^^^^^

This is the last major release to support Python 3.6.

* Do not show `**kwargs` when keywords are specifically documented with the `keyword` field
and no specific documentation is given for the `**kwargs` entry.
* Fix annotation resolution edge cases: names are resolved in the context of the module
scope when possible, when impossible, the theoretical runtime scopes are used. A warning can
be reported when an annotation name is ambiguous (can be resolved to different names
depending on the scope context) with option ``-v``.
* Ensure that explicit annotation are honored when there are multiple declarations of the same name.
* Use stricter verification before marking an attribute as constant:
- instance variables are never marked as constant
- a variable that has several definitions will not be marked as constant
- a variable declaration under any kind of control flow block will not be marked as constant
* Do not trigger warnings when pydoctor cannot make sense of a potential constant attribute
(pydoctor is not a static checker).
* Fix presentation of type aliases in string form.
* Improve the AST colorizer to output less parenthesis when it's not required.
* Fix colorization of dictionary unpacking.
* Improve the class hierarchy such that it links top level names with intersphinx when possible.
* Add highlighting when clicking on "View In Hierarchy" link from class page.
* Recognize variadic generics type variables (PEP 646).
* Fix support for introspection of cython3 generated modules.
* Instance variables are marked as such across subclasses.

pydoctor 23.4.1
^^^^^^^^^^^^^^^

* Pin ``urllib3`` version to keep compatibility with ``cachecontrol`` and python3.6.

pydoctor 23.4.0
^^^^^^^^^^^^^^^

* Add support for Python 3.11
* Add support for the ``@overload`` decorator.
* Show type annotations in function's signatures.
* If none of a function's parameters have documentation, do not render the parameter table.
* Themes have been adjusted to render annotations more concisely.
* Fix a rare crash in the type inference.
Invalid python code like a set of lists would raise a uncaught TypeError in the evaluation.
* Support when source path lies outside base directory (``--project-base-dir``).
Since pydoctor support generating docs for multiple packages,
it is not certain that all of the source is even viewable below a single URL.
We now allow to add arbitrary paths to the system,
but only the objects inside a module wich path is relative to
the base directory can have a source control link generated.
* Cache the default docutils settings on docutils>=0.19 to improve performance.
* Improve the search bar user experience by automatically appending wildcard to each query terms
when no terms already contain a wildcard.
* Link recognized constructors in class page.
* An invalid epytext docstring will be rederered as plaintext, just like invalid restructuredtext docstrings (finally).

pydoctor 22.9.1
^^^^^^^^^^^^^^^
* ``pydoctor --help`` works again.
Expand Down Expand Up @@ -109,7 +176,7 @@ pydoctor 22.7.0
* Improve the extensibility of pydoctor (`more infos on extensions <https://pydoctor.readthedocs.io/en/latest/customize.html#use-a-custom-system-class>`_)
* Fix line numbers in reStructuredText xref warnings.
* Add support for `twisted.python.deprecated` (this was originally part of Twisted's customizations).
* Add support for re-exporting it names imported from a wildcard import.
* Add support for re-exporting names imported from a wildcard import.

pydoctor 22.5.1
^^^^^^^^^^^^^^^
Expand Down
25 changes: 24 additions & 1 deletion docs/epytext_demo/demo_epytext_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from abc import ABC
import math
from typing import AnyStr, Dict, Generator, List, Union, Callable, Tuple, TYPE_CHECKING
from typing import overload, AnyStr, Dict, Generator, List, Union, Callable, Tuple, Sequence, Optional, Protocol, TYPE_CHECKING
from somelib import SomeInterface
import zope.interface
import zope.schema
Expand All @@ -32,6 +32,9 @@
This is also a constant, but annotated with typing.Final.
"""

Interface = Protocol
"""Aliases are also documented."""

@deprecated(Version("demo", "NEXT", 0, 0), replacement=math.prod)
def demo_product_deprecated(x, y) -> float: # type: ignore
return float(x * y)
Expand Down Expand Up @@ -81,6 +84,26 @@ def demo_cross_reference() -> None:
- L{Custom name <demo_typing_arguments>}
"""

@overload
def demo_overload(s: str) -> str:
...

@overload
def demo_overload(s: bytes) -> bytes:
...

def demo_overload(s: Union[str, bytes]) -> Union[str, bytes]:
"""
Overload signatures appear without the main signature and with C{@overload} decorator.

@param s: Some string or bytes param.
@return: Some string or bytes result.
"""
raise NotImplementedError

def demo_undocumented(s: str) -> str:
raise NotImplementedError


class _PrivateClass:
"""
Expand Down
34 changes: 33 additions & 1 deletion docs/restructuredtext_demo/demo_restructuredtext_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import math
import zope.interface
import zope.schema
from typing import Callable, Sequence, Optional, AnyStr, Generator, Union, List, Dict, TYPE_CHECKING
from typing import overload, Protocol, Callable, Sequence, Optional, AnyStr, Generator, Union, List, Dict, TYPE_CHECKING
from incremental import Version
from twisted.python.deprecate import deprecated, deprecatedProperty

Expand All @@ -30,6 +30,9 @@
This is also a constant, but annotated with typing.Final.
"""

Interface = Protocol
"""Aliases are also documented."""

@deprecated(Version("demo", "NEXT", 0, 0), replacement=math.prod)
def demo_product_deprecated(x, y) -> float: # type: ignore
return float(x * y)
Expand Down Expand Up @@ -89,6 +92,25 @@ def demo_cross_reference() -> None:
- `demo_typing_arguments`
"""

@overload
def demo_overload(s: str) -> str:
...

@overload
def demo_overload(s: bytes) -> bytes:
...

def demo_overload(s: Union[str, bytes]) -> Union[str, bytes]:
"""
Overload signatures appear without the main signature and with ``@overload`` decorator.

:param s: Some string or bytes param.
:return: Some string or bytes result.
"""
raise NotImplementedError

def demo_undocumented(s: str) -> str:
raise NotImplementedError


class _PrivateClass:
Expand Down Expand Up @@ -126,6 +148,7 @@ class DemoClass(ABC, _PrivateClass):
.. versionchanged:: 1.2
Add `read_and_write_delete` property.
"""
#FIXME: For some reason, the alias Demo do ont appear in the class page :/

def __init__(self, one: str, two: bytes) -> None:
"""
Expand Down Expand Up @@ -180,6 +203,12 @@ def read_and_write_delete(self) -> None:
"""
This is a docstring for deleter.
"""
pass

ro = read_only
rw = read_and_write
rwd = read_and_write_delete


class IContact(zope.interface.Interface):
"""
Expand All @@ -196,3 +225,6 @@ class IContact(zope.interface.Interface):

def send_email(text: str) -> None:
pass

_Demo = _PrivateClass
Demo = DemoClass
Loading