Skip to content

Commit ba92ec8

Browse files
committed
2 parents b01c818 + bf68005 commit ba92ec8

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
# pytask-vscode
22

3-
4-
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/mj023/pytask-vscode/main.svg)](https://results.pre-commit.ci/latest/github/mj023/pytask-vscode/main)
5-
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
3+
This is a plugin for Pytask. It is needed to use the Pytask VS Code Extension.
64

75

86
## Installation
97

10-
pytask-vscode is available on [PyPI](https://pypi.org/project/pytask-vscode) and [Anaconda.org](https://anaconda.org/conda-forge/pytask-vscode). Install it with
8+
pytask-vscode is available on [PyPI](https://test.pypi.org/project/pytask-vscode/). Install it with
119

1210
```console
13-
$ pip install pytask-vscode
11+
$ pip install -i https://test.pypi.org/simple/ pytask-vscode
1412

15-
# or
16-
17-
$ conda install -c conda-forge pytask-vscode
1813
```
1914

2015
## Changes

environment.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ dependencies:
1111
- toml
1212

1313
# Package dependencies
14-
- pytask >=0.2
14+
- pytask >=0.4.1
1515
- pytask-parallel >=0.2
16+
- requests
1617

1718
# Misc
1819
- black

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]
33
build-backend = "setuptools.build_meta"
44

5-
65
[tool.setuptools_scm]
76
write_to = "src/pytask_vscode/_version.py"
87

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ project_urls =
2929
packages = find:
3030
install_requires =
3131
click
32-
pytask>=0.2
32+
pytask>=0.4.1
33+
requests
3334
python_requires = >=3.7
3435
include_package_data = True
3536
package_dir = =src

src/pytask_vscode/execution.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
import pytask
22
import json
33
import requests
4+
from contextlib import redirect_stdout
5+
import io
46

57
@pytask.hookimpl(tryfirst=True)
6-
def pytask_collect_log(session: pytask.Session, reports: list[pytask.CollectionReport], tasks: list[pytask.Task]) -> None:
8+
def pytask_collect_log(session: pytask.Session, reports: list[pytask.CollectionReport], tasks: list[pytask.PTask]) -> None:
79
try:
810
if session.config['command'] == 'collect':
9-
result = [{'name' : task.short_name, 'path' : str(task.path)} for task in tasks]
10-
res = requests.post('http://localhost:6000/pytask', json={"exitcode" : session.exit_code, "tasks": result}, timeout=0.1)
11+
result = [{'name' : task.name.split('/')[-1], 'path' : str(task.path)} if isinstance(task,pytask.PTaskWithPath) else {'name' : task.name, 'path' : ''} for task in tasks]
12+
res = requests.post('http://localhost:6000/pytask', json={"exitcode" : session.exit_code, "tasks": result}, timeout=0.0001)
13+
except requests.exceptions.ReadTimeout:
14+
pass
1115
except Exception as e:
1216
pass
1317

1418

1519
@pytask.hookimpl(tryfirst=True)
1620
def pytask_execute_task_log_end(session: pytask.Session, report: pytask.ExecutionReport) -> None:
1721

18-
try:
19-
result = {'type': 'task', 'name' : report.task.short_name, 'outcome' : str(report.outcome)}
20-
res = requests.post('http://localhost:6000/pytask', json=result)
22+
try:
23+
if report.outcome == pytask.TaskOutcome.FAIL:
24+
with pytask.console.capture() as capture:
25+
pytask.console.print(pytask.render_exc_info(report.exc_info[0], report.exc_info[1], report.exc_info[2]))
26+
s = capture.get()
27+
result = {'type': 'task', 'name' : report.task.name.split('/')[-1], 'outcome' : str(report.outcome), 'exc_info' : s}
28+
else:
29+
result = {'type': 'task', 'name' : report.task.name.split('/')[-1], 'outcome' : str(report.outcome)}
30+
res = requests.post('http://localhost:6000/pytask', json=result, timeout=0.00001)
31+
except requests.exceptions.ReadTimeout:
32+
pass
2133
except Exception as e:
2234
pass

0 commit comments

Comments
 (0)