Skip to content

Commit

Permalink
chore: Remove Python 3.6 compatibility workarounds (meltano#7341)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillDaSilva committed Feb 22, 2023
1 parent 41b9ab4 commit 6d8cd65
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 142 deletions.
5 changes: 1 addition & 4 deletions src/meltano/core/logging/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import logging
import os
import sys
from contextlib import suppress
from logging import config as logging_config

import structlog
Expand Down Expand Up @@ -204,9 +203,7 @@ async def _write_line_writer(writer, line):
writer.write(line)
await writer.drain()
except (BrokenPipeError, ConnectionResetError):
with suppress(AttributeError): # `wait_closed` is Python 3.7+
await writer.wait_closed()

await writer.wait_closed()
return False
else:
writer.writeline(line.decode())
Expand Down
49 changes: 20 additions & 29 deletions src/meltano/core/plugin_install_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import os
import sys
from dataclasses import dataclass
from enum import Enum
from multiprocessing import cpu_count
from typing import Any, Callable, Iterable, Mapping
Expand Down Expand Up @@ -53,52 +54,42 @@ class PluginInstallStatus(Enum):
WARNING = "warning"


@dataclass(frozen=True)
class PluginInstallState:
"""A message reporting the progress of installing a plugin."""
"""A message reporting the progress of installing a plugin.
def __init__(
self,
plugin: ProjectPlugin,
reason: PluginInstallReason,
status: PluginInstallStatus,
message: str | None = None,
details: str | None = None,
):
"""Initialize PluginInstallState instance.
plugin: Plugin related to this install state.
reason: Reason for plugin install.
status: Status of plugin install.
message: Formatted install state message.
details: Extra details relating to install (including error details if failed).
"""

Args:
plugin: Plugin related to this install state.
reason: Reason for plugin install.
status: Status of plugin install.
message: Formatted install state message.
details: Extra details relating to install (including error details if failed).
"""
# TODO: use dataclasses.dataclass for this when 3.6 support is dropped
self.plugin = plugin
self.reason = reason
self.status = status
self.message = message
self.details = details

@property
plugin: ProjectPlugin
reason: PluginInstallReason
status: PluginInstallStatus
message: str | None = None
details: str | None = None

@cached_property
def successful(self):
"""Plugin install success status.
Returns:
'True' if plugin install successful.
`True` if plugin install successful.
"""
return self.status in {PluginInstallStatus.SUCCESS, PluginInstallStatus.SKIPPED}

@property
@cached_property
def skipped(self):
"""Plugin install skipped status.
Returns:
'True' if the installation was skipped / not needed.
`True` if the installation was skipped / not needed.
"""
return self.status == PluginInstallStatus.SKIPPED

@property
@cached_property
def verb(self) -> str:
"""Verb form of status.
Expand Down
4 changes: 1 addition & 3 deletions src/meltano/core/runner/singer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging
import subprocess
import sys
from contextlib import suppress

from meltano.core.elt_context import ELTContext
from meltano.core.logging import capture_subprocess_output
Expand Down Expand Up @@ -175,8 +174,7 @@ async def invoke( # noqa: WPS210, WPS213, WPS217, WPS231, WPS238

# Close target stdin so process can complete naturally
p_target.stdin.close()
with suppress(AttributeError): # `wait_closed` is Python 3.7+
await p_target.stdin.wait_closed()
await p_target.stdin.wait_closed()

# Wait for all buffered target output to be processed
await asyncio.wait([target_stdout_future, target_stderr_future])
Expand Down

0 comments on commit 6d8cd65

Please sign in to comment.