Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9']
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v2
with:
path: |
~/.cache/pip
~/.cache/pre-commit
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
- name: dependencies
run: |
pip install --upgrade pip wheel
pip install .[test,typehints]
- name: tests
run: pytest --color=yes
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 20.8b1 # https://github.com/psf/black/tags
hooks:
- id: black
language_version: python3
- repo: https://github.com/pycqa/isort
rev: 5.7.0
hooks:
- id: isort
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

from sphinx.application import Sphinx


# Allow importing scanpydoc itself
HERE = Path(__file__).parent
sys.path.insert(0, str(HERE.parent))
import scanpydoc # noqa


# Clean build env
for file in HERE.glob("scanpydoc.*.rst"):
file.unlink()
Expand Down
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,32 @@ requires = [
]

[tool.flit.metadata.requires-extra]
dev = [
'pre-commit',
]
test = [
'pytest',
'pytest-cov',
'pytest-black',
'typing_extensions>=3.10; python_version<"3.8"',
]
doc = [
'sphinx-autodoc-typehints>=1.12',
'sphinx-rtd-theme',
]
typehints = ['sphinx-autodoc-typehints>=1.12']
theme = ['sphinx-rtd-theme']

[tool.flit.entrypoints.'sphinx.html_themes']
scanpydoc = 'scanpydoc.theme'

[tool.black]
target-version = ['py37']

[tool.isort]
profile = 'black'
lines_after_imports = 2
multi_line_output = 3

[tool.tox]
legacy_tox_ini = """
[tox]
Expand Down
2 changes: 1 addition & 1 deletion scanpydoc/autosummary_generate_imported.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import logging
from pathlib import Path
from typing import Dict, Any
from typing import Any, Dict

from sphinx.application import Sphinx
from sphinx.ext import autosummary
Expand Down
4 changes: 2 additions & 2 deletions scanpydoc/definition_list_typed_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
(e.g. function parameters) as definition lists instead of simple paragraphs.
"""

from typing import Dict, List, Tuple, Any
from typing import Any, Dict, List, Tuple

from docutils import nodes
from sphinx import addnodes
from sphinx.application import Sphinx
from sphinx.domains.python import PyTypedField, PyObject
from sphinx.domains.python import PyObject, PyTypedField
from sphinx.environment import BuildEnvironment

from . import _setup_sig, metadata
Expand Down
5 changes: 2 additions & 3 deletions scanpydoc/elegant_typehints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ def x() -> Tuple[int, float]:
from pathlib import Path
from typing import Any, Dict


import sphinx_autodoc_typehints
from docutils.parsers.rst import roles
from sphinx.application import Sphinx
from sphinx.config import Config
from docutils.parsers.rst import roles
from sphinx.ext.autodoc import ClassDocumenter

from .. import _setup_sig, metadata
Expand Down Expand Up @@ -96,7 +95,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_css_file("typehints.css")
app.connect("config-inited", _init_vars)

from .formatting import format_annotation, _role_annot
from .formatting import _role_annot, format_annotation

sphinx_autodoc_typehints.format_annotation = format_annotation
for name in ["annotation-terse", "annotation-full"]:
Expand Down
2 changes: 1 addition & 1 deletion scanpydoc/elegant_typehints/autodoc_patch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import wraps
from typing import Mapping, Callable, Tuple
from typing import Callable, Mapping, Tuple

from docutils.statemachine import StringList
from sphinx.ext.autodoc import ClassDocumenter
Expand Down
2 changes: 1 addition & 1 deletion scanpydoc/elegant_typehints/example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Union, Optional
from typing import Dict, Optional, Union


def example_func(a: Optional[str], b: Union[str, int, None] = None) -> Dict[str, int]:
Expand Down
13 changes: 6 additions & 7 deletions scanpydoc/elegant_typehints/formatting.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import inspect
import collections.abc as cabc
import inspect
from functools import partial
from typing import Any, Union # Meta
from typing import Type, Sequence, Iterable # ABC
from typing import Dict, List, Tuple # Concrete
from typing import Any, Dict, Iterable, List, Sequence, Tuple, Type, Union


try: # 3.8 additions
from typing import Literal, get_args, get_origin
except ImportError:
from typing_extensions import Literal, get_args, get_origin

import sphinx_autodoc_typehints
from sphinx_autodoc_typehints import format_annotation as _format_orig
from docutils import nodes
from docutils.nodes import Node
from docutils.parsers.rst.roles import set_classes
from docutils.parsers.rst.states import Inliner, Struct
from docutils.utils import SystemMessage, unescape
from sphinx_autodoc_typehints import format_annotation as _format_orig

from scanpydoc import elegant_typehints

Expand Down Expand Up @@ -72,8 +71,8 @@ def _format_terse(
return f":py:class:`{tilde}typing.Mapping`"

# display dict as {k: v}
if origin is dict:
k, v = get_args(annotation)
if origin is dict and len(args) == 2:
k, v = args
return f"{{{fmt(k)}: {fmt(v)}}}"

# display Callable[[a1, a2], r] as (a1, a2) -> r
Expand Down
3 changes: 2 additions & 1 deletion scanpydoc/elegant_typehints/return_tuple.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import inspect
import re
from logging import getLogger
from typing import get_type_hints, Any, Union, Optional, Type, Tuple, List
from typing import Any, List, Optional, Tuple, Type, Union, get_type_hints


try: # 3.8 additions
from typing import get_args, get_origin
Expand Down
2 changes: 1 addition & 1 deletion scanpydoc/rtd_github_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import sys
from pathlib import Path, PurePosixPath
from types import ModuleType
from typing import Dict, Any, Tuple
from typing import Any, Dict, Tuple

from jinja2.defaults import DEFAULT_FILTERS
from sphinx.application import Sphinx
Expand Down
5 changes: 3 additions & 2 deletions tests/test_elegant_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import typing as t
from pathlib import Path


try: # 3.8 additions
from typing import Literal, get_args, get_origin
except ImportError:
Expand All @@ -14,9 +15,9 @@
from sphinx.application import Sphinx

from scanpydoc.elegant_typehints.formatting import (
format_annotation,
_format_terse,
_format_full,
_format_terse,
format_annotation,
)
from scanpydoc.elegant_typehints.return_tuple import process_docstring

Expand Down
3 changes: 2 additions & 1 deletion tests/test_rtd_github_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import pytest
from _pytest.monkeypatch import MonkeyPatch

from scanpydoc.rtd_github_links import github_url, _get_linenos, _get_obj_module
from scanpydoc.rtd_github_links import _get_linenos, _get_obj_module, github_url


HERE = Path(__file__).parent

Expand Down