Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
feat: parse docstrings in the epydoc format (#82)
Browse files Browse the repository at this point in the history
Closes #16.
Closes #17.

### Summary of Changes

* Parse docstrings in the `epydoc` format
* Add a flag to the CLI to choose the docstring format (supports the
settings `plaintext`, `numpy` and `epydoc` at the moment)
* Refactor the parser for `Numpydoc` to use the `docstring_parser`
  • Loading branch information
lars-reimann authored Apr 3, 2023
1 parent 2c41af2 commit 1fdab33
Show file tree
Hide file tree
Showing 43 changed files with 628 additions and 457 deletions.
1 change: 0 additions & 1 deletion .github/linters/.ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ select = [
"INT",
"ARG",
"PTH",
"ERA",
"PGH",
"PL",
"TRY",
Expand Down
215 changes: 9 additions & 206 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ python = "^3.10,<3.12"
astroid = "^2.14.2"
black = "^23.1.0"
levenshtein = "^0.20.9"
numpydoc = "^1.5"
scipy = "^1.10.1"
spacy = "^3.5.1"
docstring-parser = "^0.15"

[tool.poetry.group.dev.dependencies]
pytest = "^7.2.1"
Expand Down
20 changes: 19 additions & 1 deletion src/library_analyzer/cli/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from library_analyzer.cli._run_api import _run_api_command
from library_analyzer.cli._run_migrate import _run_migrate_command
from library_analyzer.cli._run_usages import _run_usages_command
from library_analyzer.processing.api.docstring_parsing import DocstringStyle

_API_COMMAND = "api"
_USAGES_COMMAND = "usages"
Expand All @@ -24,7 +25,7 @@ def cli() -> None:
logging.basicConfig(level=logging.INFO)

if args.command == _API_COMMAND:
_run_api_command(args.package, args.src, args.out)
_run_api_command(args.package, args.src, args.out, args.docstyle)
elif args.command == _USAGES_COMMAND:
_run_usages_command(args.package, args.client, args.out, args.processes, args.batchsize)
elif args.command == _ANNOTATIONS_COMMAND:
Expand All @@ -35,6 +36,7 @@ def cli() -> None:
args.src,
args.client,
args.out,
args.docstyle,
args.processes,
args.batchsize,
)
Expand Down Expand Up @@ -76,6 +78,14 @@ def _add_api_subparser(subparsers: _SubParsersAction) -> None:
default=None,
)
api_parser.add_argument("-o", "--out", help="Output directory.", type=Path, required=True)
api_parser.add_argument(
"--docstyle",
help="The docstring style.",
type=DocstringStyle.from_string,
choices=list(DocstringStyle),
required=False,
default=DocstringStyle.PLAINTEXT.name,
)


def _add_usages_subparser(subparsers: _SubParsersAction) -> None:
Expand Down Expand Up @@ -159,6 +169,14 @@ def _add_all_subparser(subparsers: _SubParsersAction) -> None:
required=True,
)
all_parser.add_argument("-o", "--out", help="Output directory.", type=Path, required=True)
all_parser.add_argument(
"--docstyle",
help="The docstring style.",
type=DocstringStyle.from_string,
choices=list(DocstringStyle),
required=False,
default=DocstringStyle.PLAINTEXT.name,
)
all_parser.add_argument(
"--processes",
help="How many processes should be spawned during processing.",
Expand Down
4 changes: 3 additions & 1 deletion src/library_analyzer/cli/_run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
from library_analyzer.cli._run_api import _run_api_command
from library_analyzer.cli._run_usages import _run_usages_command
from library_analyzer.cli._shared_constants import _API_KEY, _USAGES_KEY
from library_analyzer.processing.api.docstring_parsing import DocstringStyle


def _run_all_command(
package: str,
src_dir_path: Path,
client_dir_path: Path,
out_dir_path: Path,
docstring_style: DocstringStyle,
n_processes: int,
batch_size: int,
) -> None:
out_file_annotations = out_dir_path.joinpath("annotations.json")
results = _run_in_parallel(
partial(_run_api_command, package, src_dir_path, out_dir_path),
partial(_run_api_command, package, src_dir_path, out_dir_path, docstring_style),
partial(
_run_usages_command,
package,
Expand Down
4 changes: 3 additions & 1 deletion src/library_analyzer/cli/_run_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

from library_analyzer.processing.api import get_api
from library_analyzer.processing.api.docstring_parsing import DocstringStyle
from library_analyzer.processing.dependencies import get_dependencies

from ._read_and_write_file import _write_api_dependency_file, _write_api_file
Expand All @@ -11,9 +12,10 @@ def _run_api_command(
package: str,
src_dir_path: Path,
out_dir_path: Path,
docstring_style: DocstringStyle,
result_dict: dict | None = None,
) -> None:
api = get_api(package, src_dir_path)
api = get_api(package, src_dir_path, docstring_style)
api_dependencies = get_dependencies(api)

api_file_path = _write_api_file(api, out_dir_path)
Expand Down
Loading

0 comments on commit 1fdab33

Please sign in to comment.