diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0662405..ce988e8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v5.0.0 hooks: - id: check-added-large-files args: ['--maxkb=100'] @@ -16,7 +16,7 @@ repos: args: [--branch, main] - id: trailing-whitespace - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.9.0 + rev: v1.10.0 hooks: - id: python-check-blanket-noqa - id: python-check-mock-methods @@ -25,42 +25,42 @@ repos: - id: python-use-type-annotations - id: text-unicode-replacement-char -- repo: https://github.com/asottile/reorder_python_imports - rev: v3.9.0 +- repo: https://github.com/asottile/reorder-python-imports + rev: v3.15.0 hooks: - id: reorder-python-imports args: [--py37-plus, --add-import, 'from __future__ import annotations'] - repo: https://github.com/asottile/setup-cfg-fmt - rev: v2.2.0 + rev: v2.8.0 hooks: - id: setup-cfg-fmt - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 25.1.0 hooks: - id: black - repo: https://github.com/PyCQA/docformatter - rev: v1.5.1 + rev: v1.7.7 hooks: - id: docformatter args: [--in-place, --wrap-summaries, "88", --wrap-descriptions, "88", --blank] -- repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.241 +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.12.3 hooks: - id: ruff - repo: https://github.com/dosisod/refurb - rev: v1.9.1 + rev: v2.1.0 hooks: - id: refurb args: [--ignore, FURB126] - repo: https://github.com/econchick/interrogate - rev: 1.5.0 + rev: 1.7.0 hooks: - id: interrogate args: [-v, --fail-under=75] exclude: ^(tests/) - repo: https://github.com/executablebooks/mdformat - rev: 0.7.16 + rev: 0.7.22 hooks: - id: mdformat additional_dependencies: [ @@ -85,7 +85,7 @@ repos: # path/to/file.py # )$ - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v0.991' + rev: 'v1.16.1' hooks: - id: mypy args: [ @@ -94,11 +94,11 @@ repos: ] pass_filenames: false - repo: https://github.com/codespell-project/codespell - rev: v2.2.2 + rev: v2.4.1 hooks: - id: codespell - repo: https://github.com/mgedmin/check-manifest - rev: "0.49" + rev: "0.50" hooks: - id: check-manifest args: [--no-build-isolation] diff --git a/LICENSE b/LICENSE index 5f8563e..601ebd7 100644 --- a/LICENSE +++ b/LICENSE @@ -19,6 +19,3 @@ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - - diff --git a/README.md b/README.md index bd4558f..0fac741 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ This is a plugin for Pytask. It is needed to use the Pytask VS Code Extension. - ## Installation -pytask-vscode is available on [PyPI](https://pypi.org/project/pytask-vscode/). Install it with +pytask-vscode is available on [PyPI](https://pypi.org/project/pytask-vscode/). Install +it with ```console $ pip install pytask-vscode diff --git a/setup.cfg b/setup.cfg index 84d7627..319ef62 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [metadata] -name = pytask-vscode +name = pytask_vscode description = Additional Logging for VS Code integration long_description = file: README.md long_description_content_type = text/markdown @@ -7,18 +7,13 @@ url = https://github.com/pytask-dev/pytask-vscode author = Max Jahn author_email = max.jahn45@gmail.com license = MIT -license_file = LICENSE +license_files = LICENSE platforms = any classifiers = Development Status :: 3 - Alpha - License :: OSI Approved :: MIT License Operating System :: OS Independent Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 project_urls = Changelog = https://github.com/pytask-dev/pytask-vscode/blob/main/CHANGES.rst Documentation = https://github.com/pytask-dev/pytask-vscode @@ -31,7 +26,7 @@ install_requires = click pytask>=0.4.2 requests -python_requires = >=3.7 +python_requires = >=3.9 include_package_data = True package_dir = =src zip_safe = False diff --git a/src/pytask_vscode/__init__.py b/src/pytask_vscode/__init__.py index 5769aa6..483c821 100644 --- a/src/pytask_vscode/__init__.py +++ b/src/pytask_vscode/__init__.py @@ -1,4 +1,5 @@ """This module contains the main namespace of the package.""" + from __future__ import annotations try: diff --git a/src/pytask_vscode/execution.py b/src/pytask_vscode/execution.py index acfa9c5..a23808b 100644 --- a/src/pytask_vscode/execution.py +++ b/src/pytask_vscode/execution.py @@ -1,38 +1,67 @@ +from __future__ import annotations + + import pytask -import json import requests -from contextlib import redirect_stdout -import io + @pytask.hookimpl(tryfirst=True) -def pytask_collect_log(session: pytask.Session, reports: list[pytask.CollectionReport], tasks: list[pytask.PTask]) -> None: - try: - if session.config['command'] == 'collect': - exitcode = 0 - for report in reports: - if report.outcome == pytask.CollectionOutcome.FAIL: - exitcode = 3 - result = [{'name' : task.name.split('/')[-1], 'path' : str(task.path)} if isinstance(task,pytask.PTaskWithPath) else {'name' : task.name, 'path' : ''} for task in tasks] - res = requests.post('http://localhost:6000/pytask', json={"exitcode" : exitcode, "tasks": result}, timeout=0.0001) - except requests.exceptions.ReadTimeout: - pass - except Exception as e: - pass +def pytask_collect_log( + session: pytask.Session, + reports: list[pytask.CollectionReport], + tasks: list[pytask.PTask], +) -> None: + try: + if session.config["command"] == "collect": + exitcode = 0 + for report in reports: + if report.outcome == pytask.CollectionOutcome.FAIL: + exitcode = 3 + result = [ + ( + {"name": task.name.split("/")[-1], "path": str(task.path)} + if isinstance(task, pytask.PTaskWithPath) + else {"name": task.name, "path": ""} + ) + for task in tasks + ] + res = requests.post( + "http://localhost:6000/pytask", + json={"exitcode": exitcode, "tasks": result}, + timeout=0.0001, + ) + except requests.exceptions.ReadTimeout: + pass + except Exception: + pass @pytask.hookimpl(tryfirst=True) -def pytask_execute_task_log_end(session: pytask.Session, report: pytask.ExecutionReport) -> None: - +def pytask_execute_task_log_end( + session: pytask.Session, report: pytask.ExecutionReport +) -> None: + try: if report.outcome == pytask.TaskOutcome.FAIL: with pytask.console.capture() as capture: pytask.console.print(pytask.Traceback(report.exc_info)) s = capture.get() - result = {'type': 'task', 'name' : report.task.name.split('/')[-1], 'outcome' : str(report.outcome), 'exc_info' : s} + 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)} - res = requests.post('http://localhost:6000/pytask', json=result, timeout=0.00001) - except requests.exceptions.ReadTimeout: + result = { + "type": "task", + "name": report.task.name.split("/")[-1], + "outcome": str(report.outcome), + } + res = requests.post( + "http://localhost:6000/pytask", json=result, timeout=0.00001 + ) + except requests.exceptions.ReadTimeout: pass - except Exception as e:# + except Exception: pass diff --git a/src/pytask_vscode/plugin.py b/src/pytask_vscode/plugin.py index c3a6057..303d8a3 100644 --- a/src/pytask_vscode/plugin.py +++ b/src/pytask_vscode/plugin.py @@ -1,7 +1,10 @@ +from __future__ import annotations + import pytask -from pytask_vscode import execution from pluggy import PluginManager +from pytask_vscode import execution + @pytask.hookimpl -def pytask_add_hooks(pm : PluginManager) -> None: - pm.register(execution) \ No newline at end of file +def pytask_add_hooks(pm: PluginManager) -> None: + pm.register(execution) diff --git a/tests/conftest.py b/tests/conftest.py index 541f8d3..9ad3468 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,6 +4,6 @@ from click.testing import CliRunner -@pytest.fixture() +@pytest.fixture def runner(): return CliRunner()