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

VSCode Logging #506

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d42d176
Added Logging for Vscode
mj023 Nov 29, 2023
ef10aab
Fixed mistake in json
mj023 Nov 29, 2023
ed38f14
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 29, 2023
a513fa5
Moved execution logging to live.py
mj023 Dec 6, 2023
b613a75
Merge branch 'vscode-integration' of https://github.com/mj023/pytask …
mj023 Dec 6, 2023
5f7b80a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 6, 2023
7846dee
added requests as dependency
mj023 Dec 6, 2023
d051db6
Merge branch 'vscode-integration' of https://github.com/mj023/pytask …
mj023 Dec 6, 2023
ceed57f
Add Func description
mj023 Dec 6, 2023
28a43e9
add requests to mypy
mj023 Dec 6, 2023
bb59416
Check for no exec info
mj023 Dec 6, 2023
bb1af38
suppress more exceptions
mj023 Dec 6, 2023
4ef51b0
Add new vscode module
mj023 Dec 13, 2023
945e933
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 13, 2023
24623fd
Suppress exceptions
mj023 Jan 17, 2024
8d5ca61
Remove old code
mj023 Jan 17, 2024
7db35cf
Remove Changes
mj023 Jan 17, 2024
1415d38
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 17, 2024
d0087a6
Merge branch 'pytask-dev:main' into vscode-integration
mj023 Jan 17, 2024
4ad1d36
Add vscode module
mj023 Jan 17, 2024
ec09e60
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 17, 2024
1722f1c
Fix URL error
mj023 Jan 17, 2024
3c188b5
Merge branch 'vscode-integration' of https://github.com/mj023/pytask …
mj023 Jan 17, 2024
224331f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 17, 2024
c856264
Check URL
mj023 Jan 17, 2024
c7de595
Merge branch 'vscode-integration' of https://github.com/mj023/pytask …
mj023 Jan 17, 2024
7d7bf21
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 17, 2024
e5d38f9
Disable qa
mj023 Jan 24, 2024
e6d1156
Merge branch 'vscode-integration' of https://github.com/mj023/pytask …
mj023 Jan 24, 2024
b9af139
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 24, 2024
b0aba34
Add noqa
mj023 Jan 24, 2024
208249b
Merge branch 'vscode-integration' of https://github.com/mj023/pytask …
mj023 Jan 24, 2024
5a28ed6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 24, 2024
2956580
change noqa
mj023 Jan 24, 2024
3166c8d
Merge branch 'vscode-integration' of https://github.com/mj023/pytask …
mj023 Jan 24, 2024
573d39a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 24, 2024
c1418c3
Merge branch 'main' into vscode-integration
mj023 Jan 24, 2024
f8945a7
Merge branch 'pytask-dev:main' into vscode-integration
mj023 Feb 7, 2024
2a856b2
Add tests for vscode module
mj023 Feb 7, 2024
ba12e7b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 7, 2024
a6c2dc9
Merge branch 'main' into vscode-integration
mj023 Feb 13, 2024
4d335d4
Send Logging to different urls
mj023 Mar 6, 2024
f2de23f
Merge branch 'vscode-integration' of https://github.com/mj023/pytask …
mj023 Mar 6, 2024
a3db9ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 6, 2024
4c68723
Merge branch 'pytask-dev:main' into vscode-integration
mj023 Apr 17, 2024
2e28de7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 17, 2024
1cd6281
Merge branch 'main' into vscode-integration
mj023 Jun 20, 2024
cde73fd
Make Port changeable
mj023 Jun 20, 2024
f4b1808
Fix typing mistake
mj023 Jul 3, 2024
57596b9
Merge branch 'main' into vscode-integration
mj023 Jul 3, 2024
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ repos:
click,
optree,
pluggy,
types-requests,
rich,
sqlalchemy,
types-setuptools,
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
- networkx >=2.4
- pluggy >=1.0.0
- optree >=0.9
- requests
- rich
- sqlalchemy >=1.4.36
- tomli >=1.0.0
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies = [
"packaging",
"pluggy>=1",
"rich",
"requests",
"sqlalchemy>=1.4.36",
'tomli>=1; python_version < "3.11"',
'typing-extensions; python_version < "3.9"',
Expand Down
31 changes: 31 additions & 0 deletions src/_pytask/collect.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
"""Implement functionality to collect tasks."""
from __future__ import annotations

import contextlib
import inspect
import itertools
import os
import sys
import time
from pathlib import Path
from threading import Thread
from typing import Any
from typing import Generator
from typing import Iterable
from typing import TYPE_CHECKING

import requests
from _pytask.collect_utils import create_name_of_python_node
from _pytask.collect_utils import parse_dependencies_from_task_function
from _pytask.collect_utils import parse_products_from_task_function
Expand All @@ -29,6 +32,7 @@
from _pytask.node_protocols import PPathNode
from _pytask.node_protocols import PTask
from _pytask.nodes import PathNode
from _pytask.nodes import PTaskWithPath
from _pytask.nodes import PythonNode
from _pytask.nodes import Task
from _pytask.nodes import TaskWithoutPath
Expand Down Expand Up @@ -469,13 +473,40 @@
return id_to_short_id


def send_logging_vscode(url: str, json: dict[str, Any], timeout: float) -> None:
"""Send logging information to VSCode."""
with contextlib.suppress(requests.exceptions.RequestException):
requests.post(url=url, json=json, timeout=timeout)


@hookimpl
def pytask_collect_log(
session: Session, reports: list[CollectionReport], tasks: list[PTask]
) -> None:
"""Log collection."""
session.collection_end = time.time()

if session.config["command"] == "collect":
exitcode = 0
for report in reports:
if report.outcome == CollectionOutcome.FAIL:
exitcode = 3
result = [
{"name": task.name.split("/")[-1], "path": str(task.path)}
if isinstance(task, PTaskWithPath)
else {"name": task.name, "path": ""}
for task in tasks
]
thread = Thread(
target=send_logging_vscode,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out the daemon keyword for threads and see whether it might be helpful in our situation.

args=(
"http://localhost:6000/pytask",
{"exitcode": exitcode, "tasks": result},
0.00001,
),
)
thread.start()

Check warning on line 509 in src/_pytask/collect.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/collect.py#L509

Added line #L509 was not covered by tests
console.print(f"Collected {len(tasks)} task{'' if len(tasks) == 1 else 's'}.")

failed_reports = [r for r in reports if r.outcome == CollectionOutcome.FAIL]
Expand Down
24 changes: 24 additions & 0 deletions src/_pytask/live.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
"""Contains code related to live objects."""
from __future__ import annotations

from threading import Thread
from typing import Any
from typing import Generator
from typing import NamedTuple
from typing import TYPE_CHECKING

import click
from _pytask.collect import send_logging_vscode
from _pytask.config import hookimpl
from _pytask.console import console
from _pytask.console import format_task_name
from _pytask.outcomes import CollectionOutcome
from _pytask.outcomes import TaskOutcome
from _pytask.traceback import Traceback
from attrs import define
from attrs import field
from rich.box import ROUNDED
Expand Down Expand Up @@ -168,6 +171,27 @@ def pytask_execute_task_log_start(self, task: PTask) -> bool:
@hookimpl
def pytask_execute_task_log_end(self, report: ExecutionReport) -> bool:
"""Mark a task as being finished and update outcome."""
if report.outcome == TaskOutcome.FAIL and report.exc_info is not None:
with console.capture() as capture:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out render_to_string from console.py

console.print(Traceback(report.exc_info))
s = capture.get()
result = {
"type": "task",
"name": report.task.name.split("/")[-1],
"outcome": str(report.outcome),
"exc_info": s,
}
else:
result = {
"type": "task",
"name": report.task.name.split("/")[-1],
"outcome": str(report.outcome),
}
thread = Thread(
target=send_logging_vscode,
args=("http://localhost:6000/pytask", result, 0.00001),
)
thread.start()
self.update_reports(report)
return True

Expand Down