Skip to content

Commit 252cbe4

Browse files
committed
More vendored versions, linting, summary, docs
1 parent f87210b commit 252cbe4

14 files changed

+480
-19
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ end_of_line = lf
77
charset = utf-8
88
trim_trailing_whitespace = true
99
insert_final_newline = true
10+
11+
[*.yml]
12+
indent_size = 2

.gitignore

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
.DS_Store
2+
3+
## Commonly used Python.gitignore
4+
## https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore
5+
6+
# Byte-compiled / optimized / DLL files
7+
__pycache__/
8+
*.py[cod]
9+
*$py.class
10+
11+
# C extensions
12+
*.so
13+
14+
# Distribution / packaging
15+
.Python
16+
build/
17+
develop-eggs/
18+
dist/
19+
downloads/
20+
eggs/
21+
.eggs/
22+
lib/
23+
lib64/
24+
parts/
25+
sdist/
26+
var/
27+
wheels/
28+
share/python-wheels/
29+
*.egg-info/
30+
.installed.cfg
31+
*.egg
32+
MANIFEST
33+
34+
# PyInstaller
35+
# Usually these files are written by a python script from a template
36+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
37+
*.manifest
38+
*.spec
39+
40+
# Installer logs
41+
pip-log.txt
42+
pip-delete-this-directory.txt
43+
44+
# Unit test / coverage reports
45+
htmlcov/
46+
.tox/
47+
.nox/
48+
.coverage
49+
.coverage.*
50+
.cache
51+
nosetests.xml
52+
coverage.xml
53+
*.cover
54+
*.py,cover
55+
.hypothesis/
56+
.pytest_cache/
57+
cover/
58+
59+
# Translations
60+
*.mo
61+
*.pot
62+
63+
# Django stuff:
64+
*.log
65+
local_settings.py
66+
db.sqlite3
67+
db.sqlite3-journal
68+
69+
# Flask stuff:
70+
instance/
71+
.webassets-cache
72+
73+
# Scrapy stuff:
74+
.scrapy
75+
76+
# Sphinx documentation
77+
docs/_build/
78+
79+
# PyBuilder
80+
.pybuilder/
81+
target/
82+
83+
# Jupyter Notebook
84+
.ipynb_checkpoints
85+
86+
# IPython
87+
profile_default/
88+
ipython_config.py
89+
90+
# pyenv
91+
# For a library or package, you might want to ignore these files since the code is
92+
# intended to run in multiple environments; otherwise, check them in:
93+
# .python-version
94+
95+
# pipenv
96+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
98+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
99+
# install all needed dependencies.
100+
#Pipfile.lock
101+
102+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
103+
__pypackages__/
104+
105+
# Celery stuff
106+
celerybeat-schedule
107+
celerybeat.pid
108+
109+
# SageMath parsed files
110+
*.sage.py
111+
112+
# Environments
113+
.env
114+
.venv
115+
env/
116+
venv/
117+
ENV/
118+
env.bak/
119+
venv.bak/
120+
121+
# Spyder project settings
122+
.spyderproject
123+
.spyproject
124+
125+
# Rope project settings
126+
.ropeproject
127+
128+
# mkdocs documentation
129+
/site
130+
131+
# mypy
132+
.mypy_cache/
133+
.dmypy.json
134+
dmypy.json
135+
136+
# Pyre type checker
137+
.pyre/
138+
139+
# pytype static type analyzer
140+
.pytype/
141+
142+
# Cython debug symbols
143+
cython_debug/

CHANGELOG.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Changelog
2+
3+
## v0.1.0 - 2021-05-29
4+
5+
- Add `poetry`
6+
- Add license
7+
- Add changelog
8+
- Reformat with `black`, `isort` and `autoflake`
9+
- Add more PyYAML versions for different architectures
10+
- Add task summary
11+
- Use [QuickPanelItem](https://www.sublimetext.com/docs/api_reference.html#sublime.QuickPanelItem) instead of plain text keys
12+
- Add usage gif
13+
14+
## v0.0.3 - 2021-05-27
15+
16+
- Fix indent
17+
18+
## v0.0.2 - 2021-05-27
19+
20+
- Move `Taskfile.yml` loading into `run`
21+
22+
## v0.0.1 - 2021-05-27
23+
24+
Initial version

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Ivan Elfimov <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# Sublime Taskfile
22

3-
A Sublime Text 4 plugin for running tasks from [Taskfile](https://taskfile.dev). It adds `Run Task` to command palette and you can select which task to run. The output of the task is than displayed in the quick panel on the bottom.
3+
A Sublime Text 4 plugin for running tasks from [Taskfile](https://taskfile.dev). It adds `Taskfile: Run Task` to your command palette and you can select which task to run. The output of the task is than displayed in the quick panel on the bottom.
4+
5+
![Usage](Usage.gif)
46

57
## Caveats
68

7-
- made for Sublime Text version 4
8-
- uses Sublime's python version 3.8
9-
- has a vendored package - PyYAML
10-
- only officially supports MaxOS X
9+
- made for Sublime Text 4
10+
- uses [Sublime's python version 3.8](https://www.sublimetext.com/docs/api_environments.html#selecting_python_version)
11+
- has a vendored package - PyYAML 5.4.1 (tested only with MacOS X)
12+
13+
## Contributing
14+
15+
You are welcome to submit pull requests with bug fixes and improvements.
16+
17+
Please lint your files with `task lint` before submition.

Taskfile.py

+43-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,57 @@
11
import os
22
import zipimport
3-
4-
from pathlib import Path
53
from functools import partial
4+
from pathlib import Path
65

6+
import sublime
77
import sublime_plugin
88

9-
109
cwd = Path(__file__).parent
11-
pack_path = cwd / 'vendor/PyYAML-5.4.1-cp38-cp38-macosx_10_9_x86_64.whl'
10+
11+
12+
PLATFORM_TO_ARCH_TO_WHL = {
13+
"osx": {
14+
"x64": "PyYAML-5.4.1-cp38-cp38-macosx_10_9_x86_64.whl",
15+
},
16+
"linux": {
17+
"x64": "PyYAML-5.4.1-cp38-cp38-manylinux1_x86_64.whl",
18+
"arm64": "PyYAML-5.4.1-cp38-cp38-manylinux2014_aarch64.whl",
19+
},
20+
"windows": {
21+
"x86": "PyYAML-5.4.1-cp38-cp38-win32.whl",
22+
"x64": "PyYAML-5.4.1-cp38-cp38-win_amd64.whl",
23+
},
24+
}
25+
platform = sublime.platform()
26+
arch = sublime.arch()
27+
whl = PLATFORM_TO_ARCH_TO_WHL.get(platform, {}).get(arch)
28+
if not whl:
29+
raise Exception("This platform or architecture is not supported")
30+
pack_path = cwd / "vendor" / whl
1231
importer = zipimport.zipimporter(pack_path.resolve())
13-
yaml = importer.load_module('yaml')
32+
yaml = importer.load_module("yaml")
1433

1534

1635
class RunTaskCommand(sublime_plugin.WindowCommand):
1736
def run(self):
18-
taskfile = open(cwd / 'Taskfile.yml')
37+
taskfile = open(cwd / "Taskfile.yml")
1938
res = yaml.load(taskfile, Loader=yaml.FullLoader)
20-
tasks_keys = list([t for t in res.get('tasks')])
21-
on_done = partial(run_task_by_index, self.window)
22-
self.window.show_quick_panel(tasks_keys, on_done)
39+
items = get_quick_panel_items(res)
40+
on_done = partial(run_task_by_index, self.window, items)
41+
self.window.show_quick_panel(items, on_done, sublime.MONOSPACE_FONT)
42+
43+
44+
def run_task_by_index(window, quick_panel_items, index):
45+
task_name = quick_panel_items[index].trigger
46+
window.run_command("exec", args={"shell_cmd": f"task {task_name}"})
47+
2348

24-
def run_task_by_index(window, task_index):
25-
window.run_command('exec', args={'shell_cmd': f'task {tasks_keys[task_index]}'})
49+
def get_quick_panel_items(taskfile):
50+
result = []
51+
for task_name, task in taskfile.get("tasks").items():
52+
summary = task.get("summary")
53+
if summary:
54+
summary = summary.split("\n")[0]
55+
item = sublime.QuickPanelItem(task_name, summary)
56+
result.append(item)
57+
return result

Taskfile.yml

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
version: '3'
22

33
tasks:
4-
hello:
4+
lint:
5+
summary: |
6+
Lint source code with black and isort.
57
cmds:
6-
- echo 'Hello World from Task!'
7-
silent: true
8+
- black .
9+
- isort .
10+
- autoflake .
11+
clean:
12+
summary: Remove temporary and cache files.
13+
cmds:
14+
- find . -name '*.pyc' | xargs rm -rf
15+
- find . -name '*__pycache__' | xargs rm -rf
16+
- find . -name '*.cache' | xargs rm -rf

Usage.gif

556 KB
Loading

0 commit comments

Comments
 (0)