Skip to content

Commit 4a45406

Browse files
hayat01sh1daclaude
andcommitted
Migrate Python CLI entry point from main.py to Invoke
Replace main.py with a tasks.py that mirrors the Ruby Rakefile: a run_json_data_sorter task and a default test task. Disable auto_dash_names via invoke.yaml so task names match the Rake equivalents, and add invoke to the requirements. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 97d362c commit 4a45406

6 files changed

Lines changed: 51 additions & 33 deletions

File tree

python/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@ $ pip install -r requirements.txt
1111
## 3. Execution
1212

1313
```command
14-
$ python main.py
15-
Provide the directory name you put the JSON file in: ../json
16-
Provide the filename of which JSON data name you would like to sort: settings.json
17-
Provide asc(default) or desc you would like to sort key-value in: asc
14+
$ invoke run_json_data_sorter
15+
Provide the directory name you put the JSON file in
16+
../json
17+
Provide the filename of which JSON data name you would like to sort
18+
settings.json
19+
Provide asc(default) or desc you would like to sort key-value in
20+
asc
1821
Start exporting JSON data in ./json/settings.json
1922
Done export JSON data in ./json/settings.json 🎉
2023
```
2124

2225
## 4. Unit Test
2326

2427
```command
25-
$ pytest .
28+
$ invoke
2629
============================= test session starts ==============================
2730
platform linux -- Python 3.14.5, pytest-9.0.3, pluggy-1.6.0
2831
rootdir: json-data-sorters/python
@@ -38,8 +41,6 @@ test/test_application.py ..... [100%]
3841

3942
```command
4043
$ flake8 .
41-
./main.py:11:80: E501 line too long (84 > 79 characters)
42-
./main.py:13:80: E501 line too long (81 > 79 characters)
4344
./src/application.py:59:80: E501 line too long (80 > 79 characters)
4445
./src/application.py:76:80: E501 line too long (82 > 79 characters)
4546
./test/test_application.py:132:80: E501 line too long (85 > 79 characters)

python/invoke.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tasks:
2+
auto_dash_names: false

python/main.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

python/requirements.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ autoflake8==0.4.1
33
autopep8==2.3.2
44
flake8==7.3.0
55
iniconfig==2.3.0
6+
invoke==3.0.3
67
librt==0.11.0
78
mccabe==0.7.0
89
mypy==2.0.0

python/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
autoflake8==0.4.1
22
autopep8==2.3.2
33
flake8==7.3.0
4+
invoke==3.0.3
45
mypy==2.0.0
56
pytest==9.0.3

python/tasks.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
import sys
3+
4+
from invoke import Context, task
5+
6+
_ROOT = os.path.dirname(os.path.abspath(__file__))
7+
sys.path.insert(0, os.path.join(_ROOT, 'src'))
8+
9+
from application import Application # noqa: E402
10+
11+
12+
@task
13+
def run_json_data_sorter(c: Context) -> None:
14+
"""Run JSON Data Sorter"""
15+
print('Provide the directory name you put the JSON file in')
16+
dirname = input().strip()
17+
18+
print('Provide the filename of which JSON data name you would like '
19+
'to sort')
20+
filename = input().strip()
21+
22+
print('Provide asc(default) or desc you would like to sort '
23+
'key-value in')
24+
order = input().strip()
25+
26+
params: dict[str, str] = {}
27+
for key, value in {
28+
'dirname': dirname, 'filename': filename, 'order': order,
29+
}.items():
30+
if value:
31+
params[key] = value
32+
33+
Application(**params).run()
34+
35+
36+
@task(default=True)
37+
def test(c: Context) -> None:
38+
"""Run all tests"""
39+
c.run('pytest .')

0 commit comments

Comments
 (0)