Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 08f5440

Browse files
authored
feat: Create command line interface for a migrate command (#1109)
Closes #1108. ### Summary of Changes Created a migrate cli command, that takes two api files, an annotation file, and an output path as input ### Testing Instructions Run Terminal with `parse-package migrate -a1 apiv1.json -a2 apiv2.json -a annotations.json -o out` Co-authored-by: Aclrian <[email protected]>
1 parent bea3076 commit 08f5440

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

package-parser/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ A tool to analyze client and API code written in Python.
2727
parse-package usages -p sklearn -s "Kaggle Kernels" -o out
2828
```
2929
3. Generate annotations for the API:
30-
```shell
31-
parse-package annotations -a data/api/sklearn__api.json -u data/usages/sklearn__usage_counts.json -o out/annotations.json
32-
```
30+
```shell
31+
parse-package annotations -a data/api/sklearn__api.json -u data/usages/sklearn__usage_counts.json -o out/annotations.json
32+
```
33+
4. Migrate annotations for a new version of the API:
34+
```shell
35+
parse-package migrate -a1 data/api/sklearn__api.json -a2 data/api/sklearn__apiv2.json -a data/annotations/annotations.json -o out
36+
```

package-parser/package_parser/cli/_cli.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
from package_parser.cli._run_all import _run_all_command
99
from package_parser.cli._run_annotations import _run_annotations
1010
from package_parser.cli._run_api import _run_api_command
11+
from package_parser.cli._run_migrate import _run_migrate_command
1112
from package_parser.cli._run_usages import _run_usages_command
1213

1314
_API_COMMAND = "api"
1415
_USAGES_COMMAND = "usages"
1516
_ANNOTATIONS_COMMAND = "annotations"
1617
_ALL_COMMAND = "all"
18+
_MIGRATE_COMMAND = "migrate"
1719

1820

1921
def cli() -> None:
@@ -38,6 +40,8 @@ def cli() -> None:
3840
args.processes,
3941
args.batchsize,
4042
)
43+
elif args.command == _MIGRATE_COMMAND:
44+
_run_migrate_command(args.apiv1, args.annotations, args.apiv2, args.out)
4145

4246

4347
def _get_args() -> argparse.Namespace:
@@ -52,6 +56,7 @@ def _get_args() -> argparse.Namespace:
5256
_add_usages_subparser(subparsers)
5357
_add_annotations_subparser(subparsers)
5458
_add_all_subparser(subparsers)
59+
_add_migrate_subparser(subparsers)
5560

5661
return parser.parse_args()
5762

@@ -184,3 +189,34 @@ def _add_all_subparser(subparsers: _SubParsersAction) -> None:
184189
required=False,
185190
default=100,
186191
)
192+
193+
194+
def _add_migrate_subparser(subparsers) -> None:
195+
generate_parser = subparsers.add_parser(
196+
_MIGRATE_COMMAND,
197+
help="Migrate Annotations for the new version based on the previous version.",
198+
)
199+
generate_parser.add_argument(
200+
"-a1",
201+
"--apiv1",
202+
help="File created with the 'api' command from the previous version.",
203+
type=Path,
204+
required=True,
205+
)
206+
generate_parser.add_argument(
207+
"-a2",
208+
"--apiv2",
209+
help="File created by the 'api' command from the new version.",
210+
type=Path,
211+
required=True,
212+
)
213+
generate_parser.add_argument(
214+
"-a",
215+
"--annotations",
216+
help="File that includes all annotations of the previous version.",
217+
type=Path,
218+
required=True,
219+
)
220+
generate_parser.add_argument(
221+
"-o", "--out", help="Output directory.", type=Path, required=True
222+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import json
2+
from pathlib import Path
3+
4+
from package_parser.processing.api.model import API
5+
6+
7+
def _run_migrate_command(
8+
apiv1_file_path: Path,
9+
annotations_file_path: Path,
10+
apiv2_file_path: Path,
11+
out_dir_path: Path,
12+
) -> None:
13+
pass
14+
15+
16+
def _read_api_file(api_file_path: Path) -> API:
17+
with open(api_file_path) as api_file:
18+
api_json = json.load(api_file)
19+
20+
return API.from_json(api_json)

0 commit comments

Comments
 (0)