VSCode Logging
Add additional logging for the VSCode Extension.
Changes
The logging information will be in JSON-Format and is sent to a port that is specified by the user, by setting an environment variable. If the environment variable is not set, no logging will happen. The communication happens in a new thread so that pytask is not blocked. Deamon Threads are not used, because we do not want the threads to be killed when the main pytask program ends, as this can result in them not being able to send the info if pytask finishes very quickly.
Info the extension needs
-
Collection: The ExitCode of the Collection and a list of the collected tasks with the name and path of the task. Example:
{exitcode: "OK", tasks: [ {name: "task1", path: "C:\Documents\task_task1.py"}, ...]} -
Execution: Every time a task finishes, the name, the outcome and if the task failed also the execution info eg. the error message. Example:
{name: "task1", outcome: "FAIL", exc_info: "Rendered String of Error message"}
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 97.47%. Comparing base (
ad3680e) to head (e5f1f99). Report is 69 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #506 +/- ##
==========================================
- Coverage 97.80% 97.47% -0.34%
==========================================
Files 106 113 +7
Lines 8710 9411 +701
==========================================
+ Hits 8519 9173 +654
- Misses 191 238 +47
| Flag | Coverage Δ | |
|---|---|---|
| end_to_end | 84.58% <86.79%> (+2.30%) |
:arrow_up: |
| integration | 40.73% <43.39%> (+0.24%) |
:arrow_up: |
| unit | 65.58% <64.15%> (-4.11%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
I added the logging code for the task execution to the hook in live.py, but this seems a bit odd considering the project structure. I could move it to a new implementation of the hook in logging.py that uses tryfirst or implement the hook a second time in execute.py, also with tryfirst. What do you think, @tobiasraabe ?
Hi @mj023, thanks for your effort!
- Let us refactor the code related to the vscode extension to its own module. Could you create a new module called
vscode.pyand implement the two hooks there? To register the module, go tocli.pyand see the hook implementationpytask_add_hooks. Play around with@hookimpl(tryfirst=True)if your hook specification is not called. As long as the function do not return anything, the following hook implementation will be executed. - Can we guard the execution in the two hooks somehow? I do not want the code executed when the plugin is not installed. What options do we have here?
- It would be great if we wouldn't need another dependency. how about using urllib from the standard library?
- Okay, I'll add a new module then.
- The first solution to the guarding problem I can think of, would be to add this as an option in the pytask config that I can activate with a cli argument. But I will see if I can check whether the process that calls the script is VS Code or if I can maybe set some environment variable before running pytask.
- I'll try to change it to the standard urllib, requests was just easier to use.
I think everything should be ready now, but I'm having a little trouble writing the tests. I have moved the code to a new vscode.py module, replaced the requests library with the standard urllib and added a guard so the code is only executed if a specific environment variable is set. I then added two new tests, so that almost everything I added is covered, but I'm not sure if I did that correctly. Furthermore the tests on ubuntu 3.12 now failed and I can not figure out why.