Skip to content

Commit

Permalink
feat: Add initial code
Browse files Browse the repository at this point in the history
This version is already able to find modules and load partial data.
  • Loading branch information
pawamoy committed Sep 9, 2021
1 parent 7ea73ad commit 8cbdf7a
Show file tree
Hide file tree
Showing 20 changed files with 906 additions and 56 deletions.
7 changes: 7 additions & 0 deletions config/flake8.ini
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,12 @@ ignore =
WPS428
# redundant with C0415 (not top-level import)
WPS433
# wrong multiline usage (attributes docstrings)
WPS462
# implicit dict.get usage (generally false-positive)
WPS529

per-file-ignores =
src/griffe/dataclasses.py:WPS115
src/griffe/visitor.py:N802,D102
src/griffe/encoders.py:WPS232
File renamed without changes.
3 changes: 0 additions & 3 deletions docs/gen_ref_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@

mkdocs_gen_files.set_edit_path(full_doc_path, path)

# add pages manually:
# nav["package", "module"] = "path/to/file.md"

with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file:
nav_file.writelines(nav.build_literate_nav())
1 change: 0 additions & 1 deletion docs/reference/cli.md

This file was deleted.

31 changes: 1 addition & 30 deletions duties.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import re
import sys
from functools import wraps
from pathlib import Path
from shutil import which
from typing import List, Optional, Pattern
Expand Down Expand Up @@ -152,32 +151,7 @@ def check_dependencies(ctx):
)


def no_docs_py36(nofail=True):
"""
Decorate a duty that builds docs to warn that it's not possible on Python 3.6.
Arguments:
nofail: Whether to fail or not.
Returns:
The decorated function.
"""

def decorator(func):
@wraps(func)
def wrapper(ctx):
if sys.version_info <= (3, 7, 0):
ctx.run(["false"], title="Docs can't be built on Python 3.6", nofail=nofail, quiet=True)
else:
func(ctx)

return wrapper

return decorator


@duty
@no_docs_py36()
def check_docs(ctx):
"""
Check if the documentation builds correctly.
Expand All @@ -187,7 +161,7 @@ def check_docs(ctx):
"""
Path("htmlcov").mkdir(parents=True, exist_ok=True)
Path("htmlcov/index.html").touch(exist_ok=True)
ctx.run("mkdocs build -s", title="Building documentation", pty=PTY)
ctx.run("mkdocs build -s", title="Building documentation", pty=PTY, nofail=True, quiet=True)


@duty
Expand Down Expand Up @@ -223,7 +197,6 @@ def clean(ctx):


@duty
@no_docs_py36(nofail=False)
def docs(ctx):
"""
Build the documentation locally.
Expand All @@ -235,7 +208,6 @@ def docs(ctx):


@duty
@no_docs_py36(nofail=False)
def docs_serve(ctx, host="127.0.0.1", port=8000):
"""
Serve the documentation (localhost:8000).
Expand All @@ -249,7 +221,6 @@ def docs_serve(ctx, host="127.0.0.1", port=8000):


@duty
@no_docs_py36(nofail=False)
def docs_deploy(ctx):
"""
Deploy the documentation on GitHub pages.
Expand Down
6 changes: 5 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ theme:
name: Switch to light mode

extra_css:
- css/material.css
- css/custom.css
- css/mkdocstrings.css

markdown_extensions:
Expand All @@ -68,6 +68,10 @@ plugins:
nav_file: SUMMARY.md
- coverage
- mkdocstrings:
handlers:
python:
import:
- https://docs.python.org/3/objects.inv
watch:
- src/griffe

Expand Down
26 changes: 16 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ build-backend = "pdm.pep517.api"
[project]
name = "griffe"
version = {use_scm = true}
description = "Signatures for entire Python programs. Extract the structure, the frame, the skeleton of your project, to generate API documentation or find breaking changes in your API."
description = """
Signatures for entire Python programs.
Extract the structure, the frame, the skeleton of your project,
to generate API documentation or find breaking changes in your API.
"""
authors = [{name = "Timothée Mazzucotelli", email = "pawamoy@pm.me"}]
license = {file = "LICENSE"}
readme = "README.md"
requires-python = ">=3.6"
requires-python = ">=3.8"
keywords = []
dynamic = ["version", "classifiers"]
classifiers = [
Expand Down Expand Up @@ -38,21 +42,23 @@ package-dir = "src"
[tool.pdm.dev-dependencies]
duty = ["duty~=0.6"]
docs = [
"mkdocs~=1.1; python_version >= '3.7'",
"mkdocs-coverage~=0.2; python_version >= '3.7'",
"mkdocs-gen-files~=0.3; python_version >= '3.7'",
"mkdocs-literate-nav~=0.4; python_version >= '3.7'",
"mkdocs-material~=7.1; python_version >= '3.7'",
"mkdocstrings~=0.15; python_version >= '3.7'",
"toml~=0.10; python_version >= '3.7'",
"mkdocs~=1.1",
"mkdocs-coverage~=0.2",
"mkdocs-gen-files~=0.3",
"mkdocs-literate-nav~=0.4",
"mkdocs-material~=7.1",
"mkdocstrings~=0.15",
"-e ../mkdocstrings",
"-e ../pytkdocs",
"toml~=0.10",
]
format = [
"autoflake~=1.4",
"black~=20.8b1",
"isort~=5.8",
]
# TODO: remove this section when git-changelog is more powerful
maintain = [
# TODO: remove this section when git-changelog is more powerful
"git-changelog~=0.4",
]
quality = [
Expand Down
2 changes: 1 addition & 1 deletion scripts/multirun.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

PYTHON_VERSIONS="${PYTHON_VERSIONS-3.6 3.7 3.8 3.9}"
PYTHON_VERSIONS="${PYTHON_VERSIONS-3.8 3.9}"

if [ -n "${PYTHON_VERSIONS}" ]; then
for python_version in ${PYTHON_VERSIONS}; do
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

PYTHON_VERSIONS="${PYTHON_VERSIONS-3.6 3.7 3.8 3.9}"
PYTHON_VERSIONS="${PYTHON_VERSIONS-3.8 3.9}"

install_with_pipx() {
if ! command -v "$1" &>/dev/null; then
Expand Down
4 changes: 3 additions & 1 deletion src/griffe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""
griffe package.
Signatures for entire Python programs. Extract the structure, the frame, the skeleton of your project, to generate API documentation or find breaking changes in your API.
Signatures for entire Python programs.
Extract the structure, the frame, the skeleton of your project,
to generate API documentation or find breaking changes in your API.
"""

from typing import List
Expand Down
29 changes: 22 additions & 7 deletions src/griffe/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,29 @@

"""Module that contains the command line application."""

from __future__ import annotations

import argparse
from typing import List, Optional
import json

from griffe.encoders import Encoder
from griffe.extensions.base import Extensions
from griffe.loader import GriffeLoader


def get_parser() -> argparse.ArgumentParser:
"""
Return the CLI argument parser.
Return the program argument parser.
Returns:
An argparse parser.
The argument parser for the program.
"""
return argparse.ArgumentParser(prog="griffe")
parser = argparse.ArgumentParser(prog="griffe")
parser.add_argument("packages", metavar="PACKAGE", nargs="+", help="Packages to find and parse.")
return parser


def main(args: Optional[List[str]] = None) -> int:
def main(args: list[str] | None = None) -> int:
"""
Run the main program.
Expand All @@ -38,6 +46,13 @@ def main(args: Optional[List[str]] = None) -> int:
An exit code.
"""
parser = get_parser()
opts = parser.parse_args(args=args)
print(opts) # noqa: WPS421 (side-effect in main is fine)
opts: argparse.Namespace = parser.parse_args(args) # type: ignore

extensions = Extensions()
loader = GriffeLoader(extensions=extensions)
modules = []
for package in opts.packages:
modules.append(loader.load_module(package))
serialized = json.dumps(modules, cls=Encoder, indent=2, full=True)
print(serialized)
return 0
7 changes: 7 additions & 0 deletions src/griffe/collections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""This module stores collections of data, useful during parsing."""

from __future__ import annotations

lines_collection: dict[str, list[str]] = {}
"""A simple dictionary containing lines of modules.
It will probably be made more powerful later."""
Loading

0 comments on commit 8cbdf7a

Please sign in to comment.