| 1 |
"""Cross-Python compatibility helpers.""" |
| 2 |
|
| 3 |
import sys |
| 4 |
from typing import Iterable |
| 5 |
|
| 6 |
|
| 7 |
if sys.version_info >= (3, 8): |
| 8 |
from importlib.metadata import ( # noqa: WPS433 |
| 9 |
version as importlib_metadata_get_version, |
| 10 |
) |
| 11 |
from shlex import join as shlex_join # noqa: WPS433 |
| 12 |
else: |
| 13 |
# Python 3.7 and lower: |
| 14 |
from shlex import quote as _shlex_quote # noqa: WPS433 |
| 15 |
|
| 16 |
# pylint: disable-next=line-too-long |
| 17 |
from importlib_metadata import ( # type: ignore[no-redef, unused-ignore] # noqa: LN002, WPS433, WPS440 # `unused-ignore` is only needed under Python 3.6 |
| 18 |
version as importlib_metadata_get_version, |
| 19 |
) |
| 20 |
|
| 21 |
def shlex_join(split_command: Iterable[str]) -> str: # noqa: WPS440 |
| 22 |
"""Return a shell-escaped string from *split_command*.""" |
| 23 |
return ' '.join(_shlex_quote(arg) for arg in split_command) |
| 24 |
|
| 25 |
|
| 26 |
__all__ = ('importlib_metadata_get_version', 'shlex_join') # noqa: WPS410 |