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 46 commits into
base: main
Choose a base branch
from
Open

VSCode Logging #506

wants to merge 46 commits into from

Conversation

mj023
Copy link

@mj023 mj023 commented Nov 29, 2023

Changes

Add additional logging for the VSCode Extension.

Copy link

codecov bot commented Dec 6, 2023

Codecov Report

Attention: Patch coverage is 98.36066% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 97.61%. Comparing base (ad3680e) to head (2e28de7).
Report is 28 commits behind head on main.

Files Patch % Lines
src/_pytask/vscode.py 97.56% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #506      +/-   ##
==========================================
- Coverage   97.80%   97.61%   -0.20%     
==========================================
  Files         106      110       +4     
  Lines        8710     9219     +509     
==========================================
+ Hits         8519     8999     +480     
- Misses        191      220      +29     
Flag Coverage Δ
end_to_end 84.75% <98.36%> (+2.48%) ⬆️
integration 40.70% <49.18%> (+0.21%) ⬆️
unit 65.14% <52.45%> (-4.55%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mj023
Copy link
Author

mj023 commented Dec 8, 2023

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 ?

@tobiasraabe
Copy link
Member

tobiasraabe commented Dec 8, 2023

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.py and implement the two hooks there? To register the module, go to cli.py and see the hook implementation pytask_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?

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.

@@ -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

@mj023
Copy link
Author

mj023 commented Dec 8, 2023

  • 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.

@mj023
Copy link
Author

mj023 commented Feb 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants