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

chore: windows error before other imports for nicer error message #740

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@
from collections import deque
from collections.abc import Mapping

import platform
from importlib import metadata

try:
__version__ = metadata.version("sh")
except metadata.PackageNotFoundError: # pragma: no cover
__version__ = "unknown"

if "windows" in platform.system().lower(): # pragma: no cover
raise ImportError(
f"sh {__version__} is currently only supported on Linux and macOS."
)

import errno
import fcntl
import gc
Expand All @@ -35,7 +48,6 @@
import inspect
import logging
import os
import platform
import pty
import pwd
import re
Expand All @@ -55,7 +67,6 @@
from asyncio import Queue as AQueue
from contextlib import contextmanager
from functools import partial
from importlib import metadata
from io import BytesIO, StringIO, UnsupportedOperation
from io import open as fdopen
from locale import getpreferredencoding
Expand All @@ -64,17 +75,8 @@
from types import GeneratorType, ModuleType
from typing import Any, Dict, Type, Union

try:
__version__ = metadata.version("sh")
except metadata.PackageNotFoundError: # pragma: no cover
__version__ = "unknown"
__project_url__ = "https://github.com/amoffat/sh"

if "windows" in platform.system().lower(): # pragma: no cover
raise ImportError(
f"sh {__version__} is currently only supported on Linux and macOS."
)

TEE_STDOUT = {True, "out", 1}
TEE_STDERR = {"err", 2}

Expand Down