Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2.0.0 #19

Merged
merged 23 commits into from
May 12, 2024
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
4 changes: 3 additions & 1 deletion .sublime/Context.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"children":
[
{ "command": "py_rock", "args": {"action": "import_symbol"}, "caption": "Import Symbol" },
{ "command": "py_rock", "args": {"action": "copy_import_symbol"}, "caption": "Copy Import Symbol" },
{ "command": "py_rock", "args": {"action": "re_index_imports"}, "caption": "Re-Index Imports" },
{ "command": "py_rock", "args": {"action": "copy_test_path"}, "caption": "Copy test path" },
]
}
]
]
8 changes: 7 additions & 1 deletion .sublime/pyrock.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
"python_venv_path": "",
"python_interpreter_path": "",
"log_level": "info",
"import_scan_depth": 4
"import_scan_depth": 4,
"test_config": {
"enabled": false,
"test_framework": "",
"working_directory": "",
"test_runner_command": [],
}
}
67 changes: 60 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ Sublime plugin to generate import statement for python
Features
--------
- Generate's Import statement
- Copy Import statement
- Generate and copy `django` or `pytest` supported test path
- Run `django` or `pytest` tests
- Supports virtual enviroment

Upcoming Features
-----------------
- AI autocomplete
- Copy python import statement (module, class, method)
- Copy python path (module)
- Copy unittest path (module, class, method)
- Autocomplete
- Project level plugin settings

Installation
------------
Expand All @@ -36,24 +37,68 @@ Installation

Settings
--------
```
```json
{
"paths_to_scan": [], // Not used as of now
"python_venv_path": "",
"python_interpreter_path": "", // Not used as of now
"log_level": "info",
"import_scan_depth": 4
"import_scan_depth": 4,
"test_config": {
"enabled": false, // Enable or disable run test feature, default false
"test_framework": "", // django or pytest
"working_directory": "", // Working directory of your project
"test_runner_command": [], // Command to execute when clicking `Run as test`
}
}
```
- `paths_to_scan`: This is still in development, it will have no effect as of now.
- `python_interpreter_path`: This is still in development, it will have no effect as of now.
- `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:
```
"python_venv_path": "~/home/venv/bin/activate"
"python_venv_path": "/Users/abhishek/venv/bin/activate"
```
- `log_level`: By default set to `info`, accepted values `info`, `debug`, `error`, `warning`
- `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.

- `test_config.enabled`
- **Description**: Enable or disable run test feature
- **Type**: `str`
- **Allowed Values**: `true` or `false`
- **Default**: `false`
> ⚠️ If its `false` then it will ignore all other settings in `test_config`

- `test_config.test_framework`
- **Description**: Defines what library is used for running the test
- **Type**: `str`
- **Allowed Values**: `django` or `pytest`
- **Default**: NA
> ⚠️ This assumes that `django` or `pytest` is pre-installed in your python env

- `test_config.working_directory`
- **Description**: Working directory of your project, this will be used to define what is the root of project
- **Type**: `str`
- **Allowed Values**: Valid Path
- **Default**: NA
- **Example**:
```
"working_directory": "/Users/abhishek/django-app/"
```

- `test_config.test_runner_command`
- **Description**: Command to execute when clicking `Run as test`
- **Type**: `List[str]`
- **Allowed Values**: NA
- **Default**: NA
- **Example**
```json
// For Django
"test_runner_command": ["python", "manage.py", "test", "--keepdb"]

// For Pytest
"test_runner_command": ["pytest"]
```

Usage
-----
- Upon installation it automatically reads the settings and scans your python environment for packages and index them.
Expand All @@ -67,6 +112,14 @@ Usage
<img width="589" alt="Import symbol" src="https://github.com/abhishek72850/pyrock/assets/18554923/eb1421ff-4304-40f5-aca8-eaea84c96145">
<img width="584" alt="import suggestions" src="https://github.com/abhishek72850/pyrock/assets/18554923/a64fadef-9554-4840-929b-72a93f27c799">

- To Run Tests:
- Write your tests and save it as `test_*.py`, the file name has to be prefixed with `test_`
- 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
> 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.
<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">
![Run test demo](https://github.com/abhishek72850/pyrock/assets/18554923/512c05a2-be75-4b6b-b17e-e6af4f1026bd)


Key Bindings
------------
- 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:
Expand Down
Binary file added assets/beaker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/debug-start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions assets/run_test_annotation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<html>
<body id='pyrock-run-test'>
<style>

* {
margin: 0;
padding: 0;
}
body {
/* display: inline; */
}
.ref-link {
display: inline-block;
text-decoration: none;
position: relative;
/* margin: auto 0; */
}
.run-test-icon {
position: relative;
width: 1rem;
height: 1rem;
top: 10%;
}
.run-test-label {
display: inline-block;
}

</style>

<a href='$run_test_region_index' class='ref-link'>
<img src='file://$image_file' class='run-test-icon'>
<p class='run-test-label'>Run as test</p>
</a>
</body>
</html>
86 changes: 86 additions & 0 deletions assets/test_output.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
%YAML 1.2
---
name: PyRock Test Result
scope: text.test-result
hidden: true
contexts:
main:
- match: 'cd'
captures:
1: support.command.shell
scope: source.shell

# verbosity <= 1
- match: '(?=^[\\.sEF]+$)'
push:
- match: $
pop: true
- match: s
scope: markup.changed
- match: E|F
scope: markup.deleted

# verbosity >= 2
- match: .+(\.\.\.)
captures:
1: markup.ignored
push:
- match: $
pop: true
- match: ok
scope: markup.inserted
- match: ERROR|FAIL
scope: markup.deleted
- match: "skipped.*"
scope: markup.changed

- match: ^OK.*
scope: markup.inserted

- match: ^FAILED.*
scope: markup.deleted

- match: '======================================================================'
scope: markup.ignored
push:
- match: '----------------------------------------------------------------------'
scope: markup.ignored
pop: true
- match: ^ERROR|FAIL
scope: markup.deleted

- match: ^----------------------------------------------------------------------$
scope: markup.ignored

- include: scope:source.diff

- match: 'File "(.*)"(?:, line ([0-9]+)(?:, in (.*))?)?'
captures:
1: markup.underline.link
2: constant.numeric
3: entity.name

- match: 'Running Command:'
scope: markup.heading

# New patterns for datetime and logger level
- match: '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}'
scope: markup.changed

- match: 'INFO|DEBUG|WARN|WARNING|ERROR|CRITICAL'
scope: keyword.control.logger-level

# New patterns for Python errors
- match: 'Traceback \(most recent call last\):'
scope: keyword.control.python-error
push:
- match: 'File "(.*)"(?:, line ([0-9]+)(?:, in (.*))?)?'
captures:
1: markup.underline.link
2: constant.numeric
3: entity.name
- match: '^([^:]+): (.+)$'
captures:
1: variable.language.python
2: string.quoted.single.python
scope: keyword.control.python-error
58 changes: 58 additions & 0 deletions assets/test_output_color_scheme.tmTheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Custom Theme</string>
<key>settings</key>
<array>
<!-- Background color -->
<dict>
<key>settings</key>
<dict>
<key>background</key>
<string>#000000</string>
<key>foreground</key>
<string>#FFFFFF</string>
</dict>
</dict>

<!-- Datetime color -->
<dict>
<key>name</key>
<string>Constant - Datetime</string>
<key>scope</key>
<string>constant.other.datetime</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FF0000</string> <!-- Adjust the color here -->
</dict>
</dict>
<dict>
<key>name</key>
<string>Constant - Logger Level</string>
<key>scope</key>
<string>keyword.control.logger-level</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FF0000</string> <!-- Adjust the color here -->
</dict>
</dict>
<dict>
<key>name</key>
<string>Constant - Python Error</string>
<key>scope</key>
<string>keyword.control.python-error</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FF0000</string> <!-- Adjust the color here -->
<key>underline</key>
<true/>
</dict>
</dict>
</array>
</dict>
</plist>
76 changes: 76 additions & 0 deletions changelog/2-0-0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
2.0.0
-----

New Features
--------
- Copy Import statement
- Generate and copy `django` or `pytest` supported test path
- Run `django` or `pytest` tests


Upcoming Features
-----------------
- Autocomplete
- Project level plugin settings


Updated Settings
----------------
{
"paths_to_scan": [], // Not used as of now
"python_venv_path": "",
"python_interpreter_path": "", // Not used as of now
"log_level": "info",
"import_scan_depth": 4,
"test_config": {
"enabled": false, // Enable or disable run test feature, default false
"test_framework": "", // django or pytest
"working_directory": "", // Working directory of your project
"test_runner_command": [], // Command to execute when clicking `Run as test`
}
}

- `test_config.enabled`
- **Description**: Enable or disable run test feature
- **Type**: `str`
- **Allowed Values**: `true` or `false`
- **Default**: `false`
> ⚠️ If its `false` then it will ignore all other settings in `test_config`

- `test_config.test_framework`
- **Description**: Defines what library is used for running the test
- **Type**: `str`
- **Allowed Values**: `django` or `pytest`
- **Default**: NA
> ⚠️ This assumes that `django` or `pytest` is pre-installed in your python env

- `test_config.working_directory`
- **Description**: Working directory of your project, this will be used to define what is the root of project
- **Type**: `str`
- **Allowed Values**: Valid Path
- **Default**: NA
- **Example**:
```
"working_directory": "/Users/abhishek/django-app/"
```

- `test_config.test_runner_command`
- **Description**: Command to execute when clicking `Run as test`
- **Type**: `List[str]`
- **Allowed Values**: NA
- **Default**: NA
- **Example**
```json
// For Django
"test_runner_command": ["python", "manage.py", "test", "--keepdb"]

// For Pytest
"test_runner_command": ["pytest"]
```

Usage
-----
- To Run Tests:
- Write your tests and save it as `test_*.py`, the file name has to be prefixed with `test_`
- 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
> 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.
Loading
Loading