Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
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
10 changes: 7 additions & 3 deletions package-parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ A tool to analyze client and API code written in Python.
parse-package usages -p sklearn -s "Kaggle Kernels" -o out
```
3. Generate annotations for the API:
```shell
parse-package annotations -a data/api/sklearn__api.json -u data/usages/sklearn__usage_counts.json -o out/annotations.json
```
```shell
parse-package annotations -a data/api/sklearn__api.json -u data/usages/sklearn__usage_counts.json -o out/annotations.json
```
4. Migrate annotations for a new version of the API:
```shell
parse-package migrate -a1 data/api/sklearn__api.json -a2 data/api/sklearn__apiv2.json -a data/annotations/annotations.json -o out
```
36 changes: 36 additions & 0 deletions package-parser/package_parser/cli/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
from package_parser.cli._run_all import _run_all_command
from package_parser.cli._run_annotations import _run_annotations
from package_parser.cli._run_api import _run_api_command
from package_parser.cli._run_migrate import _run_migrate_command
from package_parser.cli._run_usages import _run_usages_command

_API_COMMAND = "api"
_USAGES_COMMAND = "usages"
_ANNOTATIONS_COMMAND = "annotations"
_ALL_COMMAND = "all"
_MIGRATE_COMMAND = "migrate"


def cli() -> None:
Expand All @@ -38,6 +40,8 @@ def cli() -> None:
args.processes,
args.batchsize,
)
elif args.command == _MIGRATE_COMMAND:
_run_migrate_command(args.apiv1, args.annotations, args.apiv2, args.out)


def _get_args() -> argparse.Namespace:
Expand All @@ -52,6 +56,7 @@ def _get_args() -> argparse.Namespace:
_add_usages_subparser(subparsers)
_add_annotations_subparser(subparsers)
_add_all_subparser(subparsers)
_add_migrate_subparser(subparsers)

return parser.parse_args()

Expand Down Expand Up @@ -184,3 +189,34 @@ def _add_all_subparser(subparsers: _SubParsersAction) -> None:
required=False,
default=100,
)


def _add_migrate_subparser(subparsers) -> None:
generate_parser = subparsers.add_parser(
_MIGRATE_COMMAND,
help="Migrate Annotations for the new version based on the previous version.",
)
generate_parser.add_argument(
"-a1",
"--apiv1",
help="File created with the 'api' command from the previous version.",
type=Path,
required=True,
)
generate_parser.add_argument(
"-a2",
"--apiv2",
help="File created by the 'api' command from the new version.",
type=Path,
required=True,
)
generate_parser.add_argument(
"-a",
"--annotations",
help="File that includes all annotations of the previous version.",
type=Path,
required=True,
)
generate_parser.add_argument(
"-o", "--out", help="Output directory.", type=Path, required=True
)
20 changes: 20 additions & 0 deletions package-parser/package_parser/cli/_run_migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import json
from pathlib import Path

from package_parser.processing.api.model import API


def _run_migrate_command(
apiv1_file_path: Path,
annotations_file_path: Path,
apiv2_file_path: Path,
out_dir_path: Path,
) -> None:
pass


def _read_api_file(api_file_path: Path) -> API:
with open(api_file_path) as api_file:
api_json = json.load(api_file)

return API.from_json(api_json)