Skip to content

Commit 5b5c8c5

Browse files
Merge pull request #19 from abhishek72850/major-200-20240511
Version 2.0.0
2 parents bcb7b73 + a850b50 commit 5b5c8c5

30 files changed

+2883
-439
lines changed

.sublime/Context.sublime-menu

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"children":
66
[
77
{ "command": "py_rock", "args": {"action": "import_symbol"}, "caption": "Import Symbol" },
8+
{ "command": "py_rock", "args": {"action": "copy_import_symbol"}, "caption": "Copy Import Symbol" },
89
{ "command": "py_rock", "args": {"action": "re_index_imports"}, "caption": "Re-Index Imports" },
10+
{ "command": "py_rock", "args": {"action": "copy_test_path"}, "caption": "Copy test path" },
911
]
1012
}
11-
]
13+
]

.sublime/pyrock.sublime-settings

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33
"python_venv_path": "",
44
"python_interpreter_path": "",
55
"log_level": "info",
6-
"import_scan_depth": 4
6+
"import_scan_depth": 4,
7+
"test_config": {
8+
"enabled": false,
9+
"test_framework": "",
10+
"working_directory": "",
11+
"test_runner_command": [],
12+
}
713
}

README.md

+60-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ Sublime plugin to generate import statement for python
1919
Features
2020
--------
2121
- Generate's Import statement
22+
- Copy Import statement
23+
- Generate and copy `django` or `pytest` supported test path
24+
- Run `django` or `pytest` tests
2225
- Supports virtual enviroment
2326

2427
Upcoming Features
2528
-----------------
26-
- AI autocomplete
27-
- Copy python import statement (module, class, method)
28-
- Copy python path (module)
29-
- Copy unittest path (module, class, method)
29+
- Autocomplete
30+
- Project level plugin settings
3031

3132
Installation
3233
------------
@@ -36,24 +37,68 @@ Installation
3637

3738
Settings
3839
--------
39-
```
40+
```json
4041
{
4142
"paths_to_scan": [], // Not used as of now
4243
"python_venv_path": "",
4344
"python_interpreter_path": "", // Not used as of now
4445
"log_level": "info",
45-
"import_scan_depth": 4
46+
"import_scan_depth": 4,
47+
"test_config": {
48+
"enabled": false, // Enable or disable run test feature, default false
49+
"test_framework": "", // django or pytest
50+
"working_directory": "", // Working directory of your project
51+
"test_runner_command": [], // Command to execute when clicking `Run as test`
52+
}
4653
}
4754
```
4855
- `paths_to_scan`: This is still in development, it will have no effect as of now.
4956
- `python_interpreter_path`: This is still in development, it will have no effect as of now.
5057
- `python_venv_path` : Specifies which python env to use when indexing files, if not given it will choose the default python interpreter of your system (Make sure you have set any default python, otherwise it will not be able to index). It takes the full path to `activate` file of the virtual environment, for example:
5158
```
52-
"python_venv_path": "~/home/venv/bin/activate"
59+
"python_venv_path": "/Users/abhishek/venv/bin/activate"
5360
```
5461
- `log_level`: By default set to `info`, accepted values `info`, `debug`, `error`, `warning`
5562
- `import_scan_depth`: This defines how deep it will scan any python package, the higher the number the more deep it will go, `4` is an optimal depth, you can increase it but it will also increase the time to index all files, so change it carefully.
5663

64+
- `test_config.enabled`
65+
- **Description**: Enable or disable run test feature
66+
- **Type**: `str`
67+
- **Allowed Values**: `true` or `false`
68+
- **Default**: `false`
69+
> ⚠️ If its `false` then it will ignore all other settings in `test_config`
70+
71+
- `test_config.test_framework`
72+
- **Description**: Defines what library is used for running the test
73+
- **Type**: `str`
74+
- **Allowed Values**: `django` or `pytest`
75+
- **Default**: NA
76+
> ⚠️ This assumes that `django` or `pytest` is pre-installed in your python env
77+
78+
- `test_config.working_directory`
79+
- **Description**: Working directory of your project, this will be used to define what is the root of project
80+
- **Type**: `str`
81+
- **Allowed Values**: Valid Path
82+
- **Default**: NA
83+
- **Example**:
84+
```
85+
"working_directory": "/Users/abhishek/django-app/"
86+
```
87+
88+
- `test_config.test_runner_command`
89+
- **Description**: Command to execute when clicking `Run as test`
90+
- **Type**: `List[str]`
91+
- **Allowed Values**: NA
92+
- **Default**: NA
93+
- **Example**
94+
```json
95+
// For Django
96+
"test_runner_command": ["python", "manage.py", "test", "--keepdb"]
97+
98+
// For Pytest
99+
"test_runner_command": ["pytest"]
100+
```
101+
57102
Usage
58103
-----
59104
- Upon installation it automatically reads the settings and scans your python environment for packages and index them.
@@ -67,6 +112,14 @@ Usage
67112
<img width="589" alt="Import symbol" src="https://github.com/abhishek72850/pyrock/assets/18554923/eb1421ff-4304-40f5-aca8-eaea84c96145">
68113
<img width="584" alt="import suggestions" src="https://github.com/abhishek72850/pyrock/assets/18554923/a64fadef-9554-4840-929b-72a93f27c799">
69114
115+
- To Run Tests:
116+
- Write your tests and save it as `test_*.py`, the file name has to be prefixed with `test_`
117+
- Then as you save it will show `Run as test` annotation on individual test class and methods, if you click on any of them it will run that particular test
118+
> If in between you want to run another test you can simply click on the `Run as test` but this will terminate any running test and starts the new one.
119+
<img width="691" alt="Screenshot 2024-05-12 at 4 05 26 PM" src="https://github.com/abhishek72850/pyrock/assets/18554923/4d424ca9-eef0-448b-9d07-f5bf43dd60d5">
120+
![Run test demo](https://github.com/abhishek72850/pyrock/assets/18554923/512c05a2-be75-4b6b-b17e-e6af4f1026bd)
121+
122+
70123
Key Bindings
71124
------------
72125
- By default key bindings for this plugin are disabled, to enable it you simply goto `Preferences` -> `Package Settings` -> `PyRock` -> `Key Bindings` and then copy paste from left view to your right view and uncomment it or you can copy the below directly to your right view and save it:

assets/beaker.png

296 Bytes
Loading

assets/debug-start.png

505 Bytes
Loading

assets/run_test_annotation.html

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<html>
2+
<body id='pyrock-run-test'>
3+
<style>
4+
5+
* {
6+
margin: 0;
7+
padding: 0;
8+
}
9+
body {
10+
/* display: inline; */
11+
}
12+
.ref-link {
13+
display: inline-block;
14+
text-decoration: none;
15+
position: relative;
16+
/* margin: auto 0; */
17+
}
18+
.run-test-icon {
19+
position: relative;
20+
width: 1rem;
21+
height: 1rem;
22+
top: 10%;
23+
}
24+
.run-test-label {
25+
display: inline-block;
26+
}
27+
28+
</style>
29+
30+
<a href='$run_test_region_index' class='ref-link'>
31+
<img src='file://$image_file' class='run-test-icon'>
32+
<p class='run-test-label'>Run as test</p>
33+
</a>
34+
</body>
35+
</html>

assets/test_output.sublime-syntax

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
%YAML 1.2
2+
---
3+
name: PyRock Test Result
4+
scope: text.test-result
5+
hidden: true
6+
contexts:
7+
main:
8+
- match: 'cd'
9+
captures:
10+
1: support.command.shell
11+
scope: source.shell
12+
13+
# verbosity <= 1
14+
- match: '(?=^[\\.sEF]+$)'
15+
push:
16+
- match: $
17+
pop: true
18+
- match: s
19+
scope: markup.changed
20+
- match: E|F
21+
scope: markup.deleted
22+
23+
# verbosity >= 2
24+
- match: .+(\.\.\.)
25+
captures:
26+
1: markup.ignored
27+
push:
28+
- match: $
29+
pop: true
30+
- match: ok
31+
scope: markup.inserted
32+
- match: ERROR|FAIL
33+
scope: markup.deleted
34+
- match: "skipped.*"
35+
scope: markup.changed
36+
37+
- match: ^OK.*
38+
scope: markup.inserted
39+
40+
- match: ^FAILED.*
41+
scope: markup.deleted
42+
43+
- match: '======================================================================'
44+
scope: markup.ignored
45+
push:
46+
- match: '----------------------------------------------------------------------'
47+
scope: markup.ignored
48+
pop: true
49+
- match: ^ERROR|FAIL
50+
scope: markup.deleted
51+
52+
- match: ^----------------------------------------------------------------------$
53+
scope: markup.ignored
54+
55+
- include: scope:source.diff
56+
57+
- match: 'File "(.*)"(?:, line ([0-9]+)(?:, in (.*))?)?'
58+
captures:
59+
1: markup.underline.link
60+
2: constant.numeric
61+
3: entity.name
62+
63+
- match: 'Running Command:'
64+
scope: markup.heading
65+
66+
# New patterns for datetime and logger level
67+
- match: '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}'
68+
scope: markup.changed
69+
70+
- match: 'INFO|DEBUG|WARN|WARNING|ERROR|CRITICAL'
71+
scope: keyword.control.logger-level
72+
73+
# New patterns for Python errors
74+
- match: 'Traceback \(most recent call last\):'
75+
scope: keyword.control.python-error
76+
push:
77+
- match: 'File "(.*)"(?:, line ([0-9]+)(?:, in (.*))?)?'
78+
captures:
79+
1: markup.underline.link
80+
2: constant.numeric
81+
3: entity.name
82+
- match: '^([^:]+): (.+)$'
83+
captures:
84+
1: variable.language.python
85+
2: string.quoted.single.python
86+
scope: keyword.control.python-error
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Custom Theme</string>
7+
<key>settings</key>
8+
<array>
9+
<!-- Background color -->
10+
<dict>
11+
<key>settings</key>
12+
<dict>
13+
<key>background</key>
14+
<string>#000000</string>
15+
<key>foreground</key>
16+
<string>#FFFFFF</string>
17+
</dict>
18+
</dict>
19+
20+
<!-- Datetime color -->
21+
<dict>
22+
<key>name</key>
23+
<string>Constant - Datetime</string>
24+
<key>scope</key>
25+
<string>constant.other.datetime</string>
26+
<key>settings</key>
27+
<dict>
28+
<key>foreground</key>
29+
<string>#FF0000</string> <!-- Adjust the color here -->
30+
</dict>
31+
</dict>
32+
<dict>
33+
<key>name</key>
34+
<string>Constant - Logger Level</string>
35+
<key>scope</key>
36+
<string>keyword.control.logger-level</string>
37+
<key>settings</key>
38+
<dict>
39+
<key>foreground</key>
40+
<string>#FF0000</string> <!-- Adjust the color here -->
41+
</dict>
42+
</dict>
43+
<dict>
44+
<key>name</key>
45+
<string>Constant - Python Error</string>
46+
<key>scope</key>
47+
<string>keyword.control.python-error</string>
48+
<key>settings</key>
49+
<dict>
50+
<key>foreground</key>
51+
<string>#FF0000</string> <!-- Adjust the color here -->
52+
<key>underline</key>
53+
<true/>
54+
</dict>
55+
</dict>
56+
</array>
57+
</dict>
58+
</plist>

changelog/2-0-0.txt

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2.0.0
2+
-----
3+
4+
New Features
5+
--------
6+
- Copy Import statement
7+
- Generate and copy `django` or `pytest` supported test path
8+
- Run `django` or `pytest` tests
9+
10+
11+
Upcoming Features
12+
-----------------
13+
- Autocomplete
14+
- Project level plugin settings
15+
16+
17+
Updated Settings
18+
----------------
19+
{
20+
"paths_to_scan": [], // Not used as of now
21+
"python_venv_path": "",
22+
"python_interpreter_path": "", // Not used as of now
23+
"log_level": "info",
24+
"import_scan_depth": 4,
25+
"test_config": {
26+
"enabled": false, // Enable or disable run test feature, default false
27+
"test_framework": "", // django or pytest
28+
"working_directory": "", // Working directory of your project
29+
"test_runner_command": [], // Command to execute when clicking `Run as test`
30+
}
31+
}
32+
33+
- `test_config.enabled`
34+
- **Description**: Enable or disable run test feature
35+
- **Type**: `str`
36+
- **Allowed Values**: `true` or `false`
37+
- **Default**: `false`
38+
> ⚠️ If its `false` then it will ignore all other settings in `test_config`
39+
40+
- `test_config.test_framework`
41+
- **Description**: Defines what library is used for running the test
42+
- **Type**: `str`
43+
- **Allowed Values**: `django` or `pytest`
44+
- **Default**: NA
45+
> ⚠️ This assumes that `django` or `pytest` is pre-installed in your python env
46+
47+
- `test_config.working_directory`
48+
- **Description**: Working directory of your project, this will be used to define what is the root of project
49+
- **Type**: `str`
50+
- **Allowed Values**: Valid Path
51+
- **Default**: NA
52+
- **Example**:
53+
```
54+
"working_directory": "/Users/abhishek/django-app/"
55+
```
56+
57+
- `test_config.test_runner_command`
58+
- **Description**: Command to execute when clicking `Run as test`
59+
- **Type**: `List[str]`
60+
- **Allowed Values**: NA
61+
- **Default**: NA
62+
- **Example**
63+
```json
64+
// For Django
65+
"test_runner_command": ["python", "manage.py", "test", "--keepdb"]
66+
67+
// For Pytest
68+
"test_runner_command": ["pytest"]
69+
```
70+
71+
Usage
72+
-----
73+
- To Run Tests:
74+
- Write your tests and save it as `test_*.py`, the file name has to be prefixed with `test_`
75+
- Then as you save it will show `Run as test` annotation on individual test class and methods, if you click on any of them it will run that particular test
76+
> If in between you want to run another test you can simply click on the `Run as test` but this will terminate any running test and starts the new one.

0 commit comments

Comments
 (0)