Skip to content

Commit f1970c5

Browse files
committed
build(.cursor): add command to refactor Python file into module
1 parent cfb8a92 commit f1970c5

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Refactor the given file into a module of the same name.
2+
3+
## Example
4+
5+
Take the following `commands.py` file as an example.
6+
7+
```python
8+
CONSTANT_1 = "Constant 1"
9+
CONSTANT_2 = "Constant 2"
10+
11+
class MyCommand:
12+
pass
13+
14+
class MyOtherCommand:
15+
pass
16+
17+
class YetAnotherCommand:
18+
pass
19+
```
20+
21+
### Classes
22+
23+
1. Create a `commands` directory.
24+
2. For each class in the original `commands.py` file, create a file and place the corresponding class there.
25+
26+
### Constants
27+
28+
1. Create a `commands/config.py` file.
29+
2. Move all constants into the `config.py` file. Update each file to import the constants from the `config.py` file.
30+
31+
### **init**.py
32+
33+
1. Create a `commands/__init__.py` file.
34+
2. Export the items in this module using `__all__`.
35+
36+
The `__init__.py` file should look like this:
37+
38+
```python
39+
from .config import CONSTANT_1, CONSTANT_2
40+
from .my-command import MyCommand
41+
from .my-other-command import MyOtherCommand
42+
from .yet-another-command import YetAnotherCommand
43+
44+
__all__ = [
45+
"CONSTANT_1",
46+
"CONSTANT_2",
47+
"MyCommand",
48+
"MyOtherCommand",
49+
"YetAnotherCommand",
50+
]
51+
```
52+
53+
### Final file structure
54+
55+
The final file structure should look like this:
56+
57+
```
58+
commands/ # `commands` module directory, same name as given file
59+
- __init__.py # Init file to expose other items within this module
60+
- config.py # Config file for constants
61+
- my-command.py # For MyCommand
62+
- my-other-command.py # For MyOtherCommand
63+
- yet-another-command.py # For YetAnotherCommand
64+
```

0 commit comments

Comments
 (0)