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 61 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
61 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
c17208d
Merge branch 'main' into vscode-integration
mj023 Jul 23, 2024
698519b
Add Test for Wrong EnvVar
mj023 Aug 1, 2024
9ef1305
Add Comments for new functions
mj023 Aug 1, 2024
e3ef562
Update vscode.py
timmens Aug 2, 2024
9afa75b
Add Unit Test
mj023 Aug 6, 2024
686cdbe
Unfinished changes from discussion
timmens Aug 7, 2024
bef8004
Refactor Port Validation; Docstrings
mj023 Aug 9, 2024
a79c101
Add Mocking to Tests
mj023 Aug 14, 2024
450ab7e
Fix mypy error
timmens Aug 14, 2024
da70cca
Merge pull request #1 from mj023/updates-tim
mj023 Aug 16, 2024
e5f1f99
Merge branch 'main' into vscode-integration
mj023 Aug 22, 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
Prev Previous commit
Next Next commit
Unfinished changes from discussion
timmens committed Aug 7, 2024
commit 686cdbe9691c3d9f15d61b3daaf571b7e5e3caab
32 changes: 23 additions & 9 deletions src/_pytask/vscode.py
Original file line number Diff line number Diff line change
@@ -32,12 +32,30 @@


def send_logging_info(url: str, data: dict[str, Any], timeout: float) -> None:
"""Send logging information to the provided port."""
"""Send logging information to the provided port.

TODO(@max): Explain why we need to suppress URLError and TimeoutError. Ideally, add
link to StackOverflow or similar.

"""
with contextlib.suppress(URLError, TimeoutError):
response = json.dumps(data).encode("utf-8")
req = Request(url, data=response) # noqa: S310
req.add_header("Content-Type", "application/json; charset=utf-8")
urlopen(req, timeout=timeout) # noqa: S310


def validate_and_return_port(port: str) -> int:
"""Validate the port number."""
try:
port = int(port)
except ValueError as e:
# TODO(@max):
# (1) Add comment to docstring, explaining why we do this
# (2) Raise ValueError with "good" error message
msg = f"Invalid port number: {port}, must be an integer."
raise ValueError(msg) from e
return port


@hookimpl(tryfirst=True)
@@ -49,10 +67,8 @@ def pytask_collect_log(
os.environ.get("PYTASK_VSCODE") is not None
and session.config["command"] == "collect"
):
try:
port = int(os.environ["PYTASK_VSCODE"])
except ValueError:
port = DEFAULT_VSCODE_PORT

port = validate_and_return_port(os.environ["PYTASK_VSCODE"])

exitcode = "OK"
for report in reports:
@@ -82,10 +98,8 @@ def pytask_execute_task_log_end(
) -> None:
"""Start threads to send logging information for executed tasks."""
if os.environ.get("PYTASK_VSCODE") is not None:
try:
port = int(os.environ["PYTASK_VSCODE"])
except ValueError:
port = DEFAULT_VSCODE_PORT

port = validate_and_return_port(os.environ["PYTASK_VSCODE"])

result = {
"name": report.task.name,
11 changes: 10 additions & 1 deletion tests/test_vscode.py
Original file line number Diff line number Diff line change
@@ -4,11 +4,20 @@
import textwrap

import pytest
from _pytask.vscode import send_logging_info
from _pytask.vscode import send_logging_info, validate_and_return_port
from pytask import ExitCode
from pytask import cli


def test_validate_and_return_port_valid_port():
assert validate_and_return_port("6000") == 6000


def test_validate_and_return_port_invalid_port():
with pytest.raises(ValueError):
validate_and_return_port("not_an_integer")


@pytest.mark.end_to_end()
def test_vscode_collect_failed(runner, tmp_path):
source = """